pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix parser failure with whole-row join alias Vars
Date: Wed, 07 Oct 2026 05:40:25 +0000
Message-ID: <E1xEKO9-00000000eEM-1CtE@gemulon.postgresql.org> (raw)

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@gmail.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(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1xEKO9-00000000eEM-1CtE@gemulon.postgresql.org>
Permalink:  ../E1xEKO9-00000000eEM-1CtE@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xEKO9-00000000eEM-1CtE@gemulon.postgresql.org

 · 

reply

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: rguo@postgresql.org
  Subject: Re: pgsql: Fix parser failure with whole-row join alias Vars
  In-Reply-To: <E1xEKO9-00000000eEM-1CtE@gemulon.postgresql.org>
  References: <E1xEKO9-00000000eEM-1CtE@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