aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-02-20 20:53:08 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-02-20 20:53:08 -0500
commite22bfe94e4dfc9abedf17026c3081bca9877163d (patch)
tree9964b3a14f797ff4ad49b5ed8866ead531de7538 /src
parent93ec0c90cde7e0188c96bca9a8ba815b58c00d24 (diff)
downloadpostgresql-e22bfe94e4dfc9abedf17026c3081bca9877163d.tar.gz
postgresql-e22bfe94e4dfc9abedf17026c3081bca9877163d.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/path/equivclass.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c
index b22b36ec0ef..d15cffff6a9 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);