aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-10-06 11:43:54 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-10-06 11:43:54 -0400
commit3d69efc4f07d773329dfbd39d6ec67a025cf7339 (patch)
treee3ed8e584eacf43624566d3fcbe087ed7f8aa5d6
parent9b8e6857b8170f09861baa1bfd074fa0c8af9cfd (diff)
downloadpostgresql-3d69efc4f07d773329dfbd39d6ec67a025cf7339.tar.gz
postgresql-3d69efc4f07d773329dfbd39d6ec67a025cf7339.zip
Build EC members for child join rels in the right memory context.
This patch prevents crashes or wrong plans when partition-wise joins are considered during GEQO planning, as a consequence of the EquivalenceClass data structures becoming corrupt after a GEQO context reset. A remaining problem is that successive GEQO cycles will make multiple copies of the required EC members, since add_child_join_rel_equivalences has no idea that such members might exist already. For now we'll just live with that. The lack of field complaints of crashes suggests that this is a mighty little-used situation. Back-patch to v12 where this code was introduced. Discussion: https://postgr.es/m/1683100.1601860653@sss.pgh.pa.us
-rw-r--r--src/backend/optimizer/path/equivclass.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c
index e50a5d44afc..b62b954e880 100644
--- a/src/backend/optimizer/path/equivclass.c
+++ b/src/backend/optimizer/path/equivclass.c
@@ -2234,10 +2234,21 @@ add_child_join_rel_equivalences(PlannerInfo *root,
{
Relids top_parent_relids = child_joinrel->top_parent_relids;
Relids child_relids = child_joinrel->relids;
+ MemoryContext oldcontext;
ListCell *lc1;
Assert(IS_JOIN_REL(child_joinrel) && IS_JOIN_REL(parent_joinrel));
+ /*
+ * If we're being called during GEQO join planning, we still have to
+ * create any new EC members in the main planner context, to avoid having
+ * a corrupt EC data structure after the GEQO context is reset. This is
+ * problematic since we'll leak memory across repeated GEQO cycles. For
+ * now, though, bloat is better than crash. If it becomes a real issue
+ * we'll have to do something to avoid generating duplicate EC members.
+ */
+ oldcontext = MemoryContextSwitchTo(root->planner_cxt);
+
foreach(lc1, root->eq_classes)
{
EquivalenceClass *cur_ec = (EquivalenceClass *) lfirst(lc1);
@@ -2334,6 +2345,8 @@ add_child_join_rel_equivalences(PlannerInfo *root,
}
}
}
+
+ MemoryContextSwitchTo(oldcontext);
}