Skip to content

Commit b1f7ee9

Browse files
committed
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.
1 parent 9619fdc commit b1f7ee9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/optimizer/path/equivclass.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,21 @@ generate_base_implied_equalities_const(PlannerInfo *root,
611611
}
612612
}
613613

614-
/* Find the constant member to use */
614+
/*
615+
* Find the constant member to use. We prefer an actual constant to
616+
* pseudo-constants (such as Params), because the constraint exclusion
617+
* machinery might be able to exclude relations on the basis of generated
618+
* "var = const" equalities, but "var = param" won't work for that.
619+
*/
615620
foreach(lc, ec->ec_members)
616621
{
617622
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc);
618623

619624
if (cur_em->em_is_const)
620625
{
621626
const_em = cur_em;
622-
break;
627+
if (IsA(cur_em->em_expr, Const))
628+
break;
623629
}
624630
}
625631
Assert(const_em != NULL);

0 commit comments

Comments
 (0)