pgsql: Calculate agglevelsup correctly when Aggref contains a CTE. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Calculate agglevelsup correctly when Aggref contains a CTE.
Date
Msg-id E1uyypy-001Duh-0y@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Calculate agglevelsup correctly when Aggref contains a CTE.

If an aggregate function call contains a sub-select that has
an RTE referencing a CTE outside the aggregate, we must treat
that reference like a Var referencing the CTE's query level
for purposes of determining the aggregate's level.  Otherwise
we might reach the nonsensical conclusion that the aggregate
should be evaluated at some query level higher than the CTE,
ending in a planner error or a broken plan tree that causes
executor failures.

Bug: #19055
Reported-by: BugForge <dllggyx@outlook.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19055-6970cfa8556a394d@postgresql.org
Backpatch-through: 13

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7df74e635e65e880c308d52e11d3d603aa1ee9c6

Modified Files
--------------
src/backend/parser/parse_agg.c     | 28 +++++++++++++++++++++++++++-
src/test/regress/expected/with.out | 34 ++++++++++++++++++++++++++++++++++
src/test/regress/sql/with.sql      | 14 ++++++++++++++
3 files changed, 75 insertions(+), 1 deletion(-)


pgsql-committers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: pgsql: Move named LWLock tranche requests to shared memory.
Next
From: Michael Paquier
Date:
Subject: Re: pgsql: Move named LWLock tranche requests to shared memory.