summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-02-15 20:16:21 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-02-15 20:16:21 +0000
commitce6e31de9c99430256468d059eb226ea7a267376 (patch)
tree9aaa52d121cf80e3426405f981c0f46dfd14b68f /src/backend/optimizer/util
parent57b5984d241c00bb8362881a14cc566fbb4869e3 (diff)
Teach the planner to treat a partial unique index as proving a variable is
unique for a particular query, if the index predicate is satisfied. This requires a bit of reordering of operations so that we check the predicates before doing any selectivity estimates, but shouldn't really cause any noticeable slowdown. Per a comment from Michal Politowski.
Diffstat (limited to 'src/backend/optimizer/util')
-rw-r--r--src/backend/optimizer/util/plancat.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index f4f8ac8a763..e880e668cba 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.154 2009/01/07 22:40:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.155 2009/02/15 20:16:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -939,15 +939,16 @@ has_unique_index(RelOptInfo *rel, AttrNumber attno)
/*
* Note: ignore partial indexes, since they don't allow us to conclude
- * that all attr values are distinct. We don't take any interest in
- * expressional indexes either. Also, a multicolumn unique index
- * doesn't allow us to conclude that just the specified attr is
- * unique.
+ * that all attr values are distinct, *unless* they are marked predOK
+ * which means we know the index's predicate is satisfied by the query.
+ * We don't take any interest in expressional indexes either. Also, a
+ * multicolumn unique index doesn't allow us to conclude that just the
+ * specified attr is unique.
*/
if (index->unique &&
index->ncolumns == 1 &&
index->indexkeys[0] == attno &&
- index->indpred == NIL)
+ (index->indpred == NIL || index->predOK))
return true;
}
return false;