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.
This commit is contained in:
Tom Lane 2003-12-29 22:22:45 +00:00
parent b53ca9bbcb
commit 5c5b911fcc

View File

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