pgsql: Fix possible usage of incorrect UPPERREL_SETOP RelOptInfo

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix possible usage of incorrect UPPERREL_SETOP RelOptInfo
Date: 2025-11-04 22:48:31
Message-ID: E1vGPpH-0053iF-0S@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix possible usage of incorrect UPPERREL_SETOP RelOptInfo

03d40e4b5 allowed dummy UNION [ALL] children to be removed from the plan
by checking for is_dummy_rel(). That commit neglected to still account
for the relids from the dummy rel so that the correct UPPERREL_SETOP
RelOptInfo could be found and used for adding the Paths to.

Not doing this could result in processing of subsequent UNIONs using the
same RelOptInfo as a previously processed UNION, which could result in
add_path() freeing old Paths that are needed by the previous UNION.

The same fix was independently submitted (2 mins later) by Richard Guo.

Reported-by: Alexander Lakhin <exclusion(at)gmail(dot)com>
Author: David Rowley <dgrowleyml(at)gmail(dot)com>
Discussion: https://postgr.es/m/bee34aec-659c-46f1-9ab7-7bbae0b7616c@gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/prep/prepunion.c | 8 ++++++--
src/test/regress/expected/union.out | 6 +++---
2 files changed, 9 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2025-11-04 23:48:47 pgsql: Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers.
Previous Message Álvaro Herrera 2025-11-04 19:35:30 pgsql: Fix snapshot handling bug in recent BRIN fix