pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Set hasSubLinks when expanding a whole-row join alias reference
7+ messages / 1 participants
[nested] [flat]

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3ad05dea1330e3d6607adda934169fdda387fadc

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7a776fc9d2874a396512a92c45311f53ef4c0235

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6c0698339e3d792f679fc39866fb7d3ebeb3fe09

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6bd71489d8155def741af656acb0eaee47d25f49

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5a73125874c9ae929cc8a3640c79c974800f2a60

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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

* pgsql: Set hasSubLinks when expanding a whole-row join alias reference
@ 2026-10-04 03:11 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Richard Guo @ 2026-10-04 03:11 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set hasSubLinks when expanding a whole-row join alias reference

If a subquery has been flattened into its parent, the joinaliasvars
entries of a join above it can be arbitrary expressions rather than
plain Vars, so expanding a reference to such a join alias may insert a
SubLink into a lower-level subquery.  flatten_join_alias_vars_mutator
detects that and sets the subquery's hasSubLinks flag, but only in the
single-column code path; the whole-row path just asserted in a comment
that its recursive call would handle this, which is true only when the
alias entry is itself a Var referencing another join.

Hence a whole-row reference to such a join appearing in a sub-select
left that sub-select's hasSubLinks false, so preprocess_expression
skipped SS_process_sublinks for it, and the unprocessed SubLink
reached code that is not prepared for one: this produced "cannot
handle unplanned sub-select" from cost_qual_eval, an assertion failure
in preprocess_aggrefs, or "unrecognized node type" at execution,
depending on where in the sub-select the SubLink ended up.

To fix, make the same check in the whole-row expansion path.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49PgeNFhQTZ2gSzwatF0_LXyegMPGt++jSfxUN7NZuQ5Q@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/10717fe150a06791b50a357912d90249c0bf40a6

Modified Files
--------------
src/backend/optimizer/util/var.c        |  6 +++++-
src/test/regress/expected/subselect.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 12 ++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)



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


end of thread, other threads:[~2026-10-04 03:11 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference Richard Guo <rguo@postgresql.org>
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference Richard Guo <rguo@postgresql.org>
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference Richard Guo <rguo@postgresql.org>
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference Richard Guo <rguo@postgresql.org>
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference Richard Guo <rguo@postgresql.org>
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference Richard Guo <rguo@postgresql.org>
2026-10-04 03:11 pgsql: Set hasSubLinks when expanding a whole-row join alias reference 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