pgsql: Disallow aggregates, window functions, and SRFs in GRAPH_TABLE C

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Disallow aggregates, window functions, and SRFs in GRAPH_TABLE C
Date: 2026-08-05 08:57:43
Message-ID: E1wrXRX-00000000HN2-1s2J@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Disallow aggregates, window functions, and SRFs in GRAPH_TABLE COLUMNS

The COLUMNS list of a GRAPH_TABLE query is parsed as an ordinary select
target list, which permits aggregate functions, window functions, and
set-returning functions. GRAPH_TABLE has no machinery to evaluate them,
though: the rewriter copies the COLUMNS target list verbatim into a
freshly built subquery whose hasAggs/hasWindowFuncs/hasTargetSRFs flags
are never set, so the planner builds no Agg/WindowAgg node (and no SRF
expansion) and the Aggref/WindowFunc/SRF reaches the executor. This
triggers an assertion failure ("ecxt_aggvalues != NULL"), or "Aggref
found in non-Agg plan node" on a non-assert build, for otherwise
parser-accepted SQL such as

SELECT max(c) FROM GRAPH_TABLE
(g MATCH (x IS v) COLUMNS (count(*) AS c));

Reject these constructs in transformRangeGraphTable() the same way
subqueries are already handled: save and clear pstate->p_hasAggs,
p_hasWindowFuncs, and p_hasTargetSRFs around the transformation of the
COLUMNS list, and raise a "not supported" error if any of them got set.

This is deliberately a blanket prohibition for now. Once quantified
element patterns such as (a)->{1,5} are supported, aggregates over
property references of higher degree (e.g. count(a) or sum(a.val)) can
be allowed; at that point the check will need to inspect the aggregate
arguments rather than reject all aggregates outright.

Author: Ewan Young <kdbase(dot)hack(at)gmail(dot)com>
Reviewed-by: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/CAON2xHOYAmYLkB2jGi6g77d6Fqv8YgOrfV-riQVf0K_7AdxD3w(at)mail(dot)gmail(dot)com

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8ce749f8f65c8991d6d2f5010116530e0d7fb2ad

Modified Files
--------------
src/backend/parser/parse_clause.c | 30 ++++++++++++++++++++++++++++++
src/test/regress/expected/graph_table.out | 7 +++++++
src/test/regress/sql/graph_table.sql | 4 ++++
3 files changed, 41 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-08-05 13:58:52 pgsql: Fix calculating length of match to localized month/weekday names
Previous Message Michael Paquier 2026-08-05 07:57:17 pgsql: Initialize read stream before fetching metapage in hash bulk-del