From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix assert failure when planning setop subqueries with CTEs
Date: Mon, 01 Apr 2024 23:16:18 +0000
Message-ID: <E1rrQsz-0002uC-IM@gemulon.postgresql.org> (raw)
Fix assert failure when planning setop subqueries with CTEs
66c0185a3 adjusted the UNION planner to request that union child queries
produce Paths correctly ordered to implement the UNION by way of
MergeAppend followed by Unique. The code there made a bad assumption
that if the root->parent_root->parse had setOperations set that the
query must be the child subquery of a set operation. That's not true
when it comes to planning a non-inlined CTE which is parented by a set
operation. This causes issues as the CTE's targetlist has no
requirement to match up to the SetOperationStmt's groupClauses
Fix this by adding a new parameter to both subquery_planner() and
grouping_planner() to explicitly pass the SetOperationStmt only when
planning set operation child subqueries.
Thank you to Tom Lane for helping to rationalize the decision on the
best function signature for subquery_planner().
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/242fc7c6-a8aa-2daf-ac4c-0a231e2619c1@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d5d2205c8ddc6670fa87474e172fdfab162b7a73
Modified Files
--------------
src/backend/optimizer/path/allpaths.c | 5 ++---
src/backend/optimizer/plan/planner.c | 39 ++++++++++++++++++----------------
src/backend/optimizer/plan/subselect.c | 15 ++++++-------
src/backend/optimizer/prep/prepunion.c | 14 ++++++++----
src/include/optimizer/planner.h | 3 ++-
src/test/regress/expected/union.out | 14 ++++++++++++
src/test/regress/sql/union.sql | 11 ++++++++++
7 files changed, 66 insertions(+), 35 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 using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix assert failure when planning setop subqueries with CTEs
In-Reply-To: <E1rrQsz-0002uC-IM@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