From 5c5b911fcc9dd2c3f3397800a8a625ef644962e1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Dec 2003 22:22:45 +0000 Subject: [PATCH] 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. --- src/backend/utils/adt/selfuncs.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 0a37df1d9a..1c3bba0ca2 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * 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 * explicitly given indexquals to produce a more accurate idea of the - * index restriction. This may produce redundant clauses, which we - * hope that canonicalize_qual and clauselist_selectivity will deal with - * intelligently. + * index selectivity. This may produce redundant clauses. We can get + * rid of exact duplicates by using set_union(). We expect that most + * 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 - * to start with, which we have to make explicit to hand to - * canonicalize_qual, and then we convert back to implicit-AND form. + * Note that index->indpred and indexQuals are both in implicit-AND form, + * so ANDing them together just takes merging the lists. */ if (index->indpred != NIL) - { - Expr *andedQuals; - - andedQuals = make_ands_explicit(nconc(listCopy(index->indpred), - indexQuals)); - andedQuals = canonicalize_qual(andedQuals); - selectivityQuals = make_ands_implicit(andedQuals); - } + selectivityQuals = set_union(index->indpred, indexQuals); /* Estimate the fraction of main-table tuples that will be visited */ *indexSelectivity = clauselist_selectivity(root, selectivityQuals,