pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix bogus Assert in find_var_for_subquery_tle
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/11b56ee27315276bd09eff17fa503ba39f4231ce

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/707b3738df95541a9f1d93f2c9a3b96e3f8416d5

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_17_STABLE

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

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

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

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5978e4c6316287c43523b9fb119cf78c0b414329

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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

* pgsql: Fix bogus Assert in find_var_for_subquery_tle
@ 2026-10-16 07:49  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

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

Fix bogus Assert in find_var_for_subquery_tle

find_var_for_subquery_tle() searches a subquery rel's targetlist for a
Var referencing a given subquery output column, and asserted that any
Var it finds there belongs to that rel.  That does not hold for an
appendrel child.  set_append_rel_size() builds the child's targetlist
by translating the parent's, and as noted there the result can contain
arbitrary expressions.  In particular, when a member of a LATERAL UNION
ALL subquery is pulled up and its output is a lateral reference, the
translated expression is a Var of the laterally referenced rel.  If the
child is itself a subquery with sorted paths, convert_subquery_pathkeys()
would trip the Assert.

In non-assert builds, the function went on to compare such a Var's
varattno with the subquery column's resno, and so could match a Var of
an unrelated rel.

To fix, ignore Vars that do not belong to the subquery rel, the same
way set_rel_width() already does.  Also correct the adjacent comment,
which claimed that the only non-Var entries are placeholders.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 12 ++++++++++--
src/test/regress/expected/join.out    | 18 ++++++++++++++++++
src/test/regress/sql/join.sql         |  7 +++++++
3 files changed, 35 insertions(+), 2 deletions(-)



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


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

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle Richard Guo <rguo@postgresql.org>
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle Richard Guo <rguo@postgresql.org>
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle Richard Guo <rguo@postgresql.org>
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle Richard Guo <rguo@postgresql.org>
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle Richard Guo <rguo@postgresql.org>
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle Richard Guo <rguo@postgresql.org>
2026-10-16 07:49 pgsql: Fix bogus Assert in find_var_for_subquery_tle 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