summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2012-10-26 18:20:10 +0000
committerTom Lane2012-10-26 18:20:10 +0000
commit7e765cb0688a9280a89f5054d3cb57fe892d73f5 (patch)
tree0bd86cae05764d0d037884d79f0a8f2cb9367000
parent67efc03a81a4a34d31545c15533dd78927b8bdb5 (diff)
Prefer actual constants to pseudo-constants in equivalence class machinery.
generate_base_implied_equalities_const() should prefer plain Consts over other em_is_const eclass members when choosing the "pivot" value that all the other members will be equated to. This makes it more likely that the generated equalities will be useful in constraint-exclusion proofs. Per report from Rushabh Lathia.
-rw-r--r--src/backend/optimizer/path/equivclass.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c
index c911bcda242..f40a46b0d7b 100644
--- a/src/backend/optimizer/path/equivclass.c
+++ b/src/backend/optimizer/path/equivclass.c
@@ -612,7 +612,12 @@ generate_base_implied_equalities_const(PlannerInfo *root,
}
}
- /* Find the constant member to use */
+ /*
+ * Find the constant member to use. We prefer an actual constant to
+ * pseudo-constants (such as Params), because the constraint exclusion
+ * machinery might be able to exclude relations on the basis of generated
+ * "var = const" equalities, but "var = param" won't work for that.
+ */
foreach(lc, ec->ec_members)
{
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc);
@@ -620,7 +625,8 @@ generate_base_implied_equalities_const(PlannerInfo *root,
if (cur_em->em_is_const)
{
const_em = cur_em;
- break;
+ if (IsA(cur_em->em_expr, Const))
+ break;
}
}
Assert(const_em != NULL);