diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index b22b36ec0e..d15cffff6a 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -2052,6 +2052,14 @@ match_eclasses_to_foreign_key_col(PlannerInfo *root, continue; /* Note: it seems okay to match to "broken" eclasses here */ + /* + * If eclass visibly doesn't have members for both rels, there's no + * need to grovel through the members. + */ + if (!bms_is_member(var1varno, ec->ec_relids) || + !bms_is_member(var2varno, ec->ec_relids)) + continue; + foreach(lc2, ec->ec_members) { EquivalenceMember *em = (EquivalenceMember *) lfirst(lc2);