Skip to content

Commit affee8b

Browse files
committed
Speed up match_eclasses_to_foreign_key_col() when there are many ECs.
Check ec_relids before bothering to iterate through the EC members. On a perhaps extreme, but still real-world, query in which match_eclasses_to_foreign_key_col() accounts for the bulk of the planner's runtime, this saves nearly 40% of the runtime. It's a bit of a stopgap fix, but it's simple enough to be back-patched to 9.6 where this code came in; so let's do that. David Rowley Discussion: https://postgr.es/m/6970.1545327857@sss.pgh.pa.us
1 parent ddad002 commit affee8b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/backend/optimizer/path/equivclass.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,14 @@ match_eclasses_to_foreign_key_col(PlannerInfo *root,
20132013
continue;
20142014
/* Note: it seems okay to match to "broken" eclasses here */
20152015

2016+
/*
2017+
* If eclass visibly doesn't have members for both rels, there's no
2018+
* need to grovel through the members.
2019+
*/
2020+
if (!bms_is_member(var1varno, ec->ec_relids) ||
2021+
!bms_is_member(var2varno, ec->ec_relids))
2022+
continue;
2023+
20162024
foreach(lc2, ec->ec_members)
20172025
{
20182026
EquivalenceMember *em = (EquivalenceMember *) lfirst(lc2);

0 commit comments

Comments
 (0)