pgsql: Avoid dangling-pointer problem with partitionwise joins under GE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid dangling-pointer problem with partitionwise joins under GE
Date: 2024-02-23 20:22:08
Message-ID: E1rdc3c-000NXJ-HA@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid dangling-pointer problem with partitionwise joins under GEQO.

build_child_join_sjinfo creates a derived SpecialJoinInfo in
the short-lived GEQO context, but afterwards the semi_rhs_exprs
from that may be used in a UniquePath for a child base relation.
This breaks the expectation that all base-relation-level structures
are in the planning-lifespan context, leading to use of a dangling
pointer with probable ensuing crash later on in create_unique_plan.
To fix, copy the expression trees when making a UniquePath.

Per bug #18360 from Alexander Lakhin. This has been broken since
partitionwise joins were added, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/18360-a23caf3157f34e62@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/cbeb455275138e6525912dd480c421864994c9c1

Modified Files
--------------
src/backend/optimizer/util/pathnode.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2024-02-23 22:35:31 pgsql: Replace lateral references to removed rels in subqueries
Previous Message Heikki Linnakangas 2024-02-23 15:43:54 pgsql: Fix compiler warning on typedef redeclaration