pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow subquery pullup to wrap a PlaceHolderVar in another one.
Date: Thu, 11 Jan 2024 20:28:52 +0000
Message-ID: <E1rO1fY-000xb1-7b@gemulon.postgresql.org> (raw)

Allow subquery pullup to wrap a PlaceHolderVar in another one.

The code for wrapping subquery output expressions in PlaceHolderVars
believed that if the expression already was a PlaceHolderVar, it was
never necessary to wrap that in another one.  That's wrong if the
expression is underneath an outer join and involves a lateral
reference to outside that scope: failing to add an additional PHV
risks evaluating the expression at the wrong place and hence not
forcing it to null when the outer join should do so.  This is an
oversight in commit 9e7e29c75, which added logic to forcibly wrap
lateral-reference Vars in PlaceHolderVars, but didn't see that the
adjacent case for PlaceHolderVars needed the same treatment.

The test case we have for this doesn't fail before 4be058fe9, but now
that I see the problem I wonder if it is possible to demonstrate
related errors before that.  That's moot though, since all such
branches are out of support.

Per bug #18284 from Holger Reise.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18284-47505a20c23647f8@postgresql.org

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/80bece312c4b957ea5a93db84be1d1776f0e5e67

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c |  9 +++++++--
src/test/regress/expected/join.out        | 27 +++++++++++++++++++++++++++
src/test/regress/sql/join.sql             | 12 ++++++++++++
3 files changed, 46 insertions(+), 2 deletions(-)



view thread (6+ messages)

Message-ID: <E1rO1fY-000xb1-7b@gemulon.postgresql.org>
Permalink:  ../E1rO1fY-000xb1-7b@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rO1fY-000xb1-7b@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Allow subquery pullup to wrap a PlaceHolderVar in another one.
  In-Reply-To: <E1rO1fY-000xb1-7b@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox