From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: In back branches, fix conditions for pullup of FROM-less subquer
Date: Thu, 15 Sep 2022 19:22:01 +0000
Message-ID: <E1oYuQy-000UnJ-Rj@gemulon.postgresql.org> (raw)
In back branches, fix conditions for pullup of FROM-less subqueries.
In branches before commit 4be058fe9, we have to prevent flattening
of subqueries with empty jointrees if the subqueries' output
columns might need to be wrapped in PlaceHolderVars. That's
because the empty jointree would result in empty phrels for the
PlaceHolderVars, meaning we'd be unable to figure out where to
evaluate them. However, we've failed to keep is_simple_subquery's
check for this hazard in sync with what pull_up_simple_subquery
actually does. The former is checking "lowest_outer_join != NULL",
whereas the conditions pull_up_simple_subquery actually uses are
if (lowest_nulling_outer_join != NULL)
if (containing_appendrel != NULL)
if (parse->groupingSets)
So the outer-join test is overly conservative, while we missed out
checking for appendrels and groupingSets. The appendrel omission
is harmless, because in that case we also check is_safe_append_member
which will also reject such subqueries. The groupingSets omission
is a bug though, leading to assertion failures or planner errors
such as "variable not found in subplan target lists".
is_simple_subquery has access to none of the three variables used
in the correct tests, but its callers do, so I chose to have them
pass down a bool corresponding to the OR of these conditions.
(The need for duplicative conditions would be a maintenance
hazard in actively-developed code, but I'm not too concerned
about it in branches that have only ~ 1 year to live.)
Per bug #17614 from Wei Wei. Patch v10 and v11 only, since we have a
better answer to this in v12 and later (indeed, the faulty check in
is_simple_subquery is gone entirely).
Discussion: https://postgr.es/m/17614-8ec20c85bdecaa2a@postgresql.org
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/19bb5e46b95fa8543a9e685788ff6c514eda07fc
Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 36 +++++++++++++++----
src/test/regress/expected/groupingsets.out | 57 +++++++++++++++++++++++-------
src/test/regress/sql/groupingsets.sql | 7 ++++
3 files changed, 80 insertions(+), 20 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: In back branches, fix conditions for pullup of FROM-less subquer
In-Reply-To: <E1oYuQy-000UnJ-Rj@gemulon.postgresql.org>
References: <E1oYuQy-000UnJ-Rj@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