pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix parser failure with whole-row join alias Vars
5+ messages / 1 participants
[nested] [flat]

* pgsql: Fix parser failure with whole-row join alias Vars
@ 2026-10-07 05:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-10-07 05:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix parser failure with whole-row join alias Vars
@ 2026-10-07 05:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-10-07 05:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6181300283c57600f68e3c4ee7ef082cd12306f3

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix parser failure with whole-row join alias Vars
@ 2026-10-07 05:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-10-07 05:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix parser failure with whole-row join alias Vars
@ 2026-10-07 05:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-10-07 05:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0c42350131bdc173964e72f94d3096cc11e9bc2e

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix parser failure with whole-row join alias Vars
@ 2026-10-07 05:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-10-07 05:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f73794bc12acc126351326580577c56f023a479a

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-10-07 05:40 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 05:40 pgsql: Fix parser failure with whole-row join alias Vars Richard Guo <rguo@postgresql.org>
2026-10-07 05:40 pgsql: Fix parser failure with whole-row join alias Vars Richard Guo <rguo@postgresql.org>
2026-10-07 05:40 pgsql: Fix parser failure with whole-row join alias Vars Richard Guo <rguo@postgresql.org>
2026-10-07 05:40 pgsql: Fix parser failure with whole-row join alias Vars Richard Guo <rguo@postgresql.org>
2026-10-07 05:40 pgsql: Fix parser failure with whole-row join alias Vars Richard Guo <rguo@postgresql.org>

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