Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5c5b911

Browse files
committed
Using canonicalize_qual() to get rid of duplicate index predicate
conditions is overkill; set_union() does the job about as well, and much more efficiently. Furthermore this avoids assuming that canonicalize_qual() will check for duplicate clauses at all, which it may not always do.
1 parent b53ca9b commit 5c5b911

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/backend/utils/adt/selfuncs.c

+14-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* 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 $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -3901,23 +3901,22 @@ genericcostestimate(Query *root, RelOptInfo *rel,
39013901
/*
39023902
* If the index is partial, AND the index predicate with the
39033903
* 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.
39073914
*
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.
39113917
*/
39123918
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);
39213920

39223921
/* Estimate the fraction of main-table tuples that will be visited */
39233922
*indexSelectivity = clauselist_selectivity(root, selectivityQuals,

0 commit comments

Comments
 (0)