pgsql: Fix incorrect Result node flattening logic

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix incorrect Result node flattening logic
Date: 2026-07-31 01:16:19
Message-ID: E1wpbrH-000000011RA-0RK5@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix incorrect Result node flattening logic

This fixes some incorrect flattening of nested Result nodes during
create_plan that was introduced by f2bae51df. That commit failed to
maintain the logic that checks for subplans and gating quals from the
nested Result node before flattening, and that could result in the nested
gating qual and subplan being lost, which could produce incorrect results.

Bug: #19579
Reported-by: Viktor Leis <leis(at)in(dot)tum(dot)de>
Author: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Discussion: https://postgr.es/m/19579-e6296b6c9fc0591c@postgresql.org
Backpatch-through: 19

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/plan/createplan.c | 21 +++++++++++----------
src/test/regress/expected/join.out | 11 +++++++++++
src/test/regress/sql/join.sql | 8 ++++++++
3 files changed, 30 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2026-07-31 01:16:50 pgsql: Fix incorrect Result node flattening logic
Previous Message Masahiko Sawada 2026-07-30 23:17:37 pgsql: Fix background psql session cleanup in 051_effective_wal_level.p