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

From Richard Guo
Subject pgsql: Fix parser failure with whole-row join alias Vars
Date
Msg-id E1xEKO9-00000000eEU-1ZqI@gemulon.postgresql.org
Whole thread
List 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@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49q_gvoeOoF0+KZ-DpQaDb=nGFfSgrz2V_n1_64L4ZNVQ@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/53b058d3b7f41a258035d9f3f590deef300a0df1

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


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: reindexdb: Forbid index-level REINDEX with CONCURRENTLY and mult
Next
From: Fujii Masao
Date:
Subject: pgsql: pg_walsummary: Fix --quiet to suppress limit block output