Skip to content

Commit 29d539b

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 2383d6d commit 29d539b

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
@@ -601,15 +601,21 @@ generate_base_implied_equalities_const(PlannerInfo *root,
601601
}
602602
}
603603

604-
/* Find the constant member to use */
604+
/*
605+
* Find the constant member to use. We prefer an actual constant to
606+
* pseudo-constants (such as Params), because the constraint exclusion
607+
* machinery might be able to exclude relations on the basis of generated
608+
* "var = const" equalities, but "var = param" won't work for that.
609+
*/
605610
foreach(lc, ec->ec_members)
606611
{
607612
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc);
608613

609614
if (cur_em->em_is_const)
610615
{
611616
const_em = cur_em;
612-
break;
617+
if (IsA(cur_em->em_expr, Const))
618+
break;
613619
}
614620
}
615621
Assert(const_em != NULL);

0 commit comments

Comments
 (0)