Build EC members for child join rels in the right memory context.
authorTom Lane
Tue, 6 Oct 2020 15:43:54 +0000 (11:43 -0400)
committerTom Lane
Tue, 6 Oct 2020 15:43:54 +0000 (11:43 -0400)
commit3d69efc4f07d773329dfbd39d6ec67a025cf7339
treee3ed8e584eacf43624566d3fcbe087ed7f8aa5d6
parent9b8e6857b8170f09861baa1bfd074fa0c8af9cfd
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
src/backend/optimizer/path/equivclass.c