|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * IDENTIFICATION
|
18 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.209 2006/07/14 14:52:24 momjian Exp $ |
| 18 | + * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.210 2006/07/24 01:19:48 tgl Exp $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -4657,6 +4657,24 @@ genericcostestimate(PlannerInfo *root,
|
4657 | 4657 | *indexTotalCost = numIndexPages * random_page_cost;
|
4658 | 4658 | }
|
4659 | 4659 |
|
| 4660 | + /* |
| 4661 | + * A difficulty with the leaf-pages-only cost approach is that for |
| 4662 | + * small selectivities (eg, single index tuple fetched) all indexes |
| 4663 | + * will look equally attractive because we will estimate exactly 1 |
| 4664 | + * leaf page to be fetched. All else being equal, we should prefer |
| 4665 | + * physically smaller indexes over larger ones. (An index might be |
| 4666 | + * smaller because it is partial or because it contains fewer columns; |
| 4667 | + * presumably the other columns in the larger index aren't useful to |
| 4668 | + * the query, or the larger index would have better selectivity.) |
| 4669 | + * |
| 4670 | + * We can deal with this by adding a very small "fudge factor" that |
| 4671 | + * depends on the index size. The fudge factor used here is one |
| 4672 | + * random_page_cost per 100000 index pages, which should be small |
| 4673 | + * enough to not alter index-vs-seqscan decisions, but will prevent |
| 4674 | + * indexes of different sizes from looking exactly equally attractive. |
| 4675 | + */ |
| 4676 | + *indexTotalCost += index->pages * random_page_cost / 100000.0; |
| 4677 | + |
4660 | 4678 | /*
|
4661 | 4679 | * CPU cost: any complex expressions in the indexquals will need to be
|
4662 | 4680 | * evaluated once at the start of the scan to reduce them to runtime keys
|
|
0 commit comments