diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-26 14:19:47 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-26 14:19:47 -0400 |
commit | ff8f7103b559d8f19731157aca38650a938fedef (patch) | |
tree | 09ef839796fef47253968ba7bb52cec76e2cf012 /src | |
parent | 5110a96992e508b220a7a6ab303b0501c4237b4a (diff) | |
download | postgresql-ff8f7103b559d8f19731157aca38650a938fedef.tar.gz postgresql-ff8f7103b559d8f19731157aca38650a938fedef.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/path/equivclass.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index 00493d82e77..f84dcdfd1be 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -768,7 +768,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); @@ -776,7 +781,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); |