pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb 5+ messages / 1 participants [nested] [flat]
* pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb @ 2026-10-05 06:05 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-05 06:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix relids of EC-derived join clauses for lateral UNION ALL members When a LATERAL UNION ALL subquery is flattened into an appendrel, a child EquivalenceMember's expression can contain lateral references to other relations. create_join_clause() builds a clause from such a member with make_restrictinfo(), which computes clause_relids from the expression, and so includes the relids of the lateral references along with those of any outer joins that null them. Commit 03107b4ed made sure that clause_relids include the child's relids, but it only ever added relids. This is a problem when a lateral reference is nullable. The child is parameterized by its lateral_relids, which do not include the outer joins that null the lateral references, so the clause fails the join_clause_is_movable_into() assertion that get_baserel_parampathinfo() applies to EC-derived clauses. To fix, set a child clause's clause_relids from its members' em_relids rather than from their expressions. This matches how adjust_appendrel_attrs() computes clause_relids for a child's other join clauses. The lateral references need not be included, since every path for the child is parameterized by at least its lateral_relids. Also update num_base_rels to match, which commit 03107b4ed neglected to do. Back-patch to v16, where outer-join relids were added to clause_relids. Before that, the relids of a lateral reference are always part of the child's parameterization, so the problem does not arise. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com Backpatch-through: 16 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/a464d31ff6213fe47505c750972b404e4517ebd9 Modified Files -------------- src/backend/optimizer/path/equivclass.c | 32 +++++++----- src/test/regress/expected/join.out | 92 +++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 26 ++++++++++ 3 files changed, 138 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb @ 2026-10-05 06:05 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-05 06:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix relids of EC-derived join clauses for lateral UNION ALL members When a LATERAL UNION ALL subquery is flattened into an appendrel, a child EquivalenceMember's expression can contain lateral references to other relations. create_join_clause() builds a clause from such a member with make_restrictinfo(), which computes clause_relids from the expression, and so includes the relids of the lateral references along with those of any outer joins that null them. Commit 03107b4ed made sure that clause_relids include the child's relids, but it only ever added relids. This is a problem when a lateral reference is nullable. The child is parameterized by its lateral_relids, which do not include the outer joins that null the lateral references, so the clause fails the join_clause_is_movable_into() assertion that get_baserel_parampathinfo() applies to EC-derived clauses. To fix, set a child clause's clause_relids from its members' em_relids rather than from their expressions. This matches how adjust_appendrel_attrs() computes clause_relids for a child's other join clauses. The lateral references need not be included, since every path for the child is parameterized by at least its lateral_relids. Also update num_base_rels to match, which commit 03107b4ed neglected to do. Back-patch to v16, where outer-join relids were added to clause_relids. Before that, the relids of a lateral reference are always part of the child's parameterization, so the problem does not arise. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com Backpatch-through: 16 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/46875a4c7464be5513bf8891b7971f5534241870 Modified Files -------------- src/backend/optimizer/path/equivclass.c | 32 +++++++----- src/test/regress/expected/join.out | 92 +++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 26 ++++++++++ 3 files changed, 138 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb @ 2026-10-05 06:05 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-05 06:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix relids of EC-derived join clauses for lateral UNION ALL members When a LATERAL UNION ALL subquery is flattened into an appendrel, a child EquivalenceMember's expression can contain lateral references to other relations. create_join_clause() builds a clause from such a member with make_restrictinfo(), which computes clause_relids from the expression, and so includes the relids of the lateral references along with those of any outer joins that null them. Commit 03107b4ed made sure that clause_relids include the child's relids, but it only ever added relids. This is a problem when a lateral reference is nullable. The child is parameterized by its lateral_relids, which do not include the outer joins that null the lateral references, so the clause fails the join_clause_is_movable_into() assertion that get_baserel_parampathinfo() applies to EC-derived clauses. To fix, set a child clause's clause_relids from its members' em_relids rather than from their expressions. This matches how adjust_appendrel_attrs() computes clause_relids for a child's other join clauses. The lateral references need not be included, since every path for the child is parameterized by at least its lateral_relids. Also update num_base_rels to match, which commit 03107b4ed neglected to do. Back-patch to v16, where outer-join relids were added to clause_relids. Before that, the relids of a lateral reference are always part of the child's parameterization, so the problem does not arise. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com Backpatch-through: 16 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b7866c934d6242ea07edfc8f137618dde721465f Modified Files -------------- src/backend/optimizer/path/equivclass.c | 32 +++++++----- src/test/regress/expected/join.out | 92 +++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 26 ++++++++++ 3 files changed, 138 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb @ 2026-10-05 06:05 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-05 06:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix relids of EC-derived join clauses for lateral UNION ALL members When a LATERAL UNION ALL subquery is flattened into an appendrel, a child EquivalenceMember's expression can contain lateral references to other relations. create_join_clause() builds a clause from such a member with make_restrictinfo(), which computes clause_relids from the expression, and so includes the relids of the lateral references along with those of any outer joins that null them. Commit 03107b4ed made sure that clause_relids include the child's relids, but it only ever added relids. This is a problem when a lateral reference is nullable. The child is parameterized by its lateral_relids, which do not include the outer joins that null the lateral references, so the clause fails the join_clause_is_movable_into() assertion that get_baserel_parampathinfo() applies to EC-derived clauses. To fix, set a child clause's clause_relids from its members' em_relids rather than from their expressions. This matches how adjust_appendrel_attrs() computes clause_relids for a child's other join clauses. The lateral references need not be included, since every path for the child is parameterized by at least its lateral_relids. Also update num_base_rels to match, which commit 03107b4ed neglected to do. Back-patch to v16, where outer-join relids were added to clause_relids. Before that, the relids of a lateral reference are always part of the child's parameterization, so the problem does not arise. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com Backpatch-through: 16 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b83b7ddf7a64dce41624b5c0dabefd74dfe10ec0 Modified Files -------------- src/backend/optimizer/path/equivclass.c | 32 +++++++----- src/test/regress/expected/join.out | 92 +++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 26 ++++++++++ 3 files changed, 138 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb @ 2026-10-05 06:05 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-05 06:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix relids of EC-derived join clauses for lateral UNION ALL members When a LATERAL UNION ALL subquery is flattened into an appendrel, a child EquivalenceMember's expression can contain lateral references to other relations. create_join_clause() builds a clause from such a member with make_restrictinfo(), which computes clause_relids from the expression, and so includes the relids of the lateral references along with those of any outer joins that null them. Commit 03107b4ed made sure that clause_relids include the child's relids, but it only ever added relids. This is a problem when a lateral reference is nullable. The child is parameterized by its lateral_relids, which do not include the outer joins that null the lateral references, so the clause fails the join_clause_is_movable_into() assertion that get_baserel_parampathinfo() applies to EC-derived clauses. To fix, set a child clause's clause_relids from its members' em_relids rather than from their expressions. This matches how adjust_appendrel_attrs() computes clause_relids for a child's other join clauses. The lateral references need not be included, since every path for the child is parameterized by at least its lateral_relids. Also update num_base_rels to match, which commit 03107b4ed neglected to do. Back-patch to v16, where outer-join relids were added to clause_relids. Before that, the relids of a lateral reference are always part of the child's parameterization, so the problem does not arise. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com Backpatch-through: 16 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/aad7571d0e132a0d176b98b0e741059b057f5373 Modified Files -------------- src/backend/optimizer/path/equivclass.c | 32 +++++++----- src/test/regress/expected/join.out | 92 +++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 26 ++++++++++ 3 files changed, 138 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2026-10-05 06:05 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-05 06:05 pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb Richard Guo <rguo@postgresql.org> 2026-10-05 06:05 pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb Richard Guo <rguo@postgresql.org> 2026-10-05 06:05 pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb Richard Guo <rguo@postgresql.org> 2026-10-05 06:05 pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb Richard Guo <rguo@postgresql.org> 2026-10-05 06:05 pgsql: Fix relids of EC-derived join clauses for lateral UNION ALL memb 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