|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * IDENTIFICATION
|
18 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.151 2003/12/28 21:57:37 tgl Exp $ |
| 18 | + * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.152 2003/12/29 22:22:45 tgl Exp $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -3901,23 +3901,22 @@ genericcostestimate(Query *root, RelOptInfo *rel,
|
3901 | 3901 | /*
|
3902 | 3902 | * If the index is partial, AND the index predicate with the
|
3903 | 3903 | * explicitly given indexquals to produce a more accurate idea of the
|
3904 |
| - * index restriction. This may produce redundant clauses, which we |
3905 |
| - * hope that canonicalize_qual and clauselist_selectivity will deal with |
3906 |
| - * intelligently. |
| 3904 | + * index selectivity. This may produce redundant clauses. We can get |
| 3905 | + * rid of exact duplicates by using set_union(). We expect that most |
| 3906 | + * cases of partial redundancy (such as "x < 4" from the qual and |
| 3907 | + * "x < 5" from the predicate) will be recognized and handled correctly |
| 3908 | + * by clauselist_selectivity(). This assumption is somewhat fragile, |
| 3909 | + * since it depends on pred_test() and clauselist_selectivity() having |
| 3910 | + * similar capabilities, and there are certainly many cases where we will |
| 3911 | + * end up with a too-low selectivity estimate. This will bias the system |
| 3912 | + * in favor of using partial indexes where possible, which is not |
| 3913 | + * necessarily a bad thing. But it'd be nice to do better someday. |
3907 | 3914 | *
|
3908 |
| - * Note that index->indpred and indexQuals are both in implicit-AND form |
3909 |
| - * to start with, which we have to make explicit to hand to |
3910 |
| - * canonicalize_qual, and then we convert back to implicit-AND form. |
| 3915 | + * Note that index->indpred and indexQuals are both in implicit-AND form, |
| 3916 | + * so ANDing them together just takes merging the lists. |
3911 | 3917 | */
|
3912 | 3918 | if (index->indpred != NIL)
|
3913 |
| - { |
3914 |
| - Expr *andedQuals; |
3915 |
| - |
3916 |
| - andedQuals = make_ands_explicit(nconc(listCopy(index->indpred), |
3917 |
| - indexQuals)); |
3918 |
| - andedQuals = canonicalize_qual(andedQuals); |
3919 |
| - selectivityQuals = make_ands_implicit(andedQuals); |
3920 |
| - } |
| 3919 | + selectivityQuals = set_union(index->indpred, indexQuals); |
3921 | 3920 |
|
3922 | 3921 | /* Estimate the fraction of main-table tuples that will be visited */
|
3923 | 3922 | *indexSelectivity = clauselist_selectivity(root, selectivityQuals,
|
|
0 commit comments