aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-02-12 18:38:32 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-02-12 18:38:32 -0500
commit75c46149fc2215b046aa56caaf59f8125f0e6062 (patch)
treef5f4141e8c326a18662c58c2b5a1eda8a11ed20a /src/backend/utils/adt/selfuncs.c
parent8c67d29fd51c0381d8bce41d35d7726725924616 (diff)
downloadpostgresql-75c46149fc2215b046aa56caaf59f8125f0e6062.tar.gz
postgresql-75c46149fc2215b046aa56caaf59f8125f0e6062.zip
Clean up planner confusion between ncolumns and nkeycolumns.
We're only going to consider key columns when creating indexquals, so there is no point in having the outer loops in indxpath.c iterate further than nkeycolumns. Doing so in match_pathkeys_to_index() is actually wrong, and would have caused crashes by now, except that we have no index AMs supporting both amcanorderbyop and amcaninclude. It's also wrong in relation_has_unique_index_for(). The effect there is to fail to prove uniqueness even when the index does prove it, if there are extra columns. Also future-proof examine_variable() for the day when extra columns can be expressions, and fix what's either a thinko or just an oversight in btcostestimate(): we should consider the number of key columns, not the total, when deciding whether to derate correlation. None of these things seemed important enough to risk changing in a just-before-wrap patch, but since we're past the release wrap window, time to fix 'em. Discussion: https://postgr.es/m/25526.1549847928@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 1ef6faecd1e..b9f99fa050b 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4869,6 +4869,10 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
* it to expressional index columns, in hopes of finding some
* statistics.
*
+ * Note that we consider all index columns including INCLUDE columns,
+ * since there could be stats for such columns. But the test for
+ * uniqueness needs to be warier.
+ *
* XXX it's conceivable that there are multiple matches with different
* index opfamilies; if so, we need to pick one that matches the
* operator we are estimating for. FIXME later.
@@ -4904,6 +4908,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
*/
if (index->unique &&
index->nkeycolumns == 1 &&
+ pos == 0 &&
(index->indpred == NIL || index->predOK))
vardata->isunique = true;
@@ -7242,7 +7247,7 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
if (index->reverse_sort[0])
varCorrelation = -varCorrelation;
- if (index->ncolumns > 1)
+ if (index->nkeycolumns > 1)
costs.indexCorrelation = varCorrelation * 0.75;
else
costs.indexCorrelation = varCorrelation;