pgsql: Fix parser failure with whole-row join alias Vars

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix parser failure with whole-row join alias Vars
Date: 2026-10-07 05:40:25
Message-ID: E1xEKO9-00000000eEM-1CtE@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix parser failure with whole-row join alias Vars

When a query has aggregates or GROUP BY, parseCheckAggregates()
flattens join alias Vars in the grouping expressions, target list and
HAVING clause so that aliased and unaliased references compare equal.
The parser has no PlannerInfo, so this relies on every join alias
expression being able to carry varnullingrels without a PHV. That
doesn't hold for a whole-row Var of a join on the nullable side of an
outer join: it expands to a RowExpr, and pushing the nulling bits down
into its fields would turn a NULL row into ROW(NULL, ...). Such
queries therefore failed with "unsupported join alias expression".

To fix, leave a nulled whole-row join Var unexpanded when no root is
available. The planner expands it later and wraps it in a
PlaceHolderVar as before. Nothing is lost for GROUP BY matching: a
nulled whole-row Var can only be equal to the same Var, never to an
expression over the join's columns.

This has been broken since the introduction of varnullingrels in v16.

Author: Richard Guo <guofenglinux(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAMbWs49q_gvoeOoF0+KZ-DpQaDb=nGFfSgrz2V_n1_64L4ZNVQ@mail.gmail.com
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/372761e05a62856d32fb6a9811edf1c51a286b9c

Modified Files
--------------
src/backend/optimizer/util/var.c | 13 ++++++++++++-
src/test/regress/expected/join.out | 29 +++++++++++++++++++++++++++++
src/test/regress/sql/join.sql | 13 +++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-10-07 06:02:31 pgsql: pg_walsummary: Fix --quiet to suppress limit block output
Previous Message Michael Paquier 2026-10-07 01:40:28 pgsql: reindexdb: Forbid index-level REINDEX with CONCURRENTLY and mult