pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Look through wrapper paths when collecting enforced clause seria 5+ messages / 1 participants [nested] [flat]
* pgsql: Look through wrapper paths when collecting enforced clause seria @ 2026-10-26 01:07 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-26 01:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Look through wrapper paths when collecting enforced clause serials. get_param_path_clause_serials() handles join paths and Append paths explicitly, and for anything else returns the ppi_serials of the path's ParamPathInfo on the assumption that it is a baserel scan. But Material, Memoize, Projection, Sort, IncrementalSort, Unique, Agg and GroupingSets paths all inherit their subpath's ParamPathInfo, and that assumption fails when the subpath is a join or Append. This could drop a join clause for good. If a LATERAL UNION ALL subquery references an outer relation in an expression that becomes an EquivalenceClass member, the members get no child version of it, so their parameterized scans cannot enforce the derived clause. The appendrel's ParamPathInfo claims it nonetheless, and once a Materialize sat on the Append, create_nestloop_path() dropped the clause from the join above as already enforced, returning rows that fail it. To fix, make get_param_path_clause_serials() recurse through such wrapper paths, since they enforce no clauses of their own. Also use it in get_memoize_path(), which unsafely read ppi_serials directly for its inner-unique check. To try to clarify what's going on here, introduce a new function get_wrapper_parampathinfo() that pathnode.c should use instead of directly assuming that copying a wrapper path's subpath's param_info is what to do. This is just cosmetic at present but might become less so in future. Back-patch to v16, where the serial-based detection of enforced clauses was introduced. Author: Richard Guo <guofenglinux@gmail.com> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: shihao zhong <zhong950419@gmail.com> Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CAMbWs49jVFRZ7oOgMK9zYt7d=SLxpiz=dN=QMu5iV8TS+9T0AA@mail.gmail.com Backpatch-through: 16 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/f9bc96514afc9c71d533568f62dc613be8356c4d Modified Files -------------- src/backend/optimizer/path/joinpath.c | 6 +- src/backend/optimizer/util/pathnode.c | 20 ++-- src/backend/optimizer/util/relnode.c | 187 +++++++++++++++++++++++----------- src/include/nodes/pathnodes.h | 29 +++++- src/include/optimizer/pathnode.h | 1 + src/test/regress/expected/join.out | 37 +++++++ src/test/regress/sql/join.sql | 23 +++++ 7 files changed, 225 insertions(+), 78 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Look through wrapper paths when collecting enforced clause seria @ 2026-10-26 01:07 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-26 01:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Look through wrapper paths when collecting enforced clause serials. get_param_path_clause_serials() handles join paths and Append paths explicitly, and for anything else returns the ppi_serials of the path's ParamPathInfo on the assumption that it is a baserel scan. But Material, Memoize, Projection, Sort, IncrementalSort, Unique, Agg and GroupingSets paths all inherit their subpath's ParamPathInfo, and that assumption fails when the subpath is a join or Append. This could drop a join clause for good. If a LATERAL UNION ALL subquery references an outer relation in an expression that becomes an EquivalenceClass member, the members get no child version of it, so their parameterized scans cannot enforce the derived clause. The appendrel's ParamPathInfo claims it nonetheless, and once a Materialize sat on the Append, create_nestloop_path() dropped the clause from the join above as already enforced, returning rows that fail it. To fix, make get_param_path_clause_serials() recurse through such wrapper paths, since they enforce no clauses of their own. Also use it in get_memoize_path(), which unsafely read ppi_serials directly for its inner-unique check. To try to clarify what's going on here, introduce a new function get_wrapper_parampathinfo() that pathnode.c should use instead of directly assuming that copying a wrapper path's subpath's param_info is what to do. This is just cosmetic at present but might become less so in future. Back-patch to v16, where the serial-based detection of enforced clauses was introduced. Author: Richard Guo <guofenglinux@gmail.com> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: shihao zhong <zhong950419@gmail.com> Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CAMbWs49jVFRZ7oOgMK9zYt7d=SLxpiz=dN=QMu5iV8TS+9T0AA@mail.gmail.com Backpatch-through: 16 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c47a86f73d02ee45fe2a99b4aa8e221c907b57fe Modified Files -------------- src/backend/optimizer/path/joinpath.c | 6 +- src/backend/optimizer/util/pathnode.c | 20 ++-- src/backend/optimizer/util/relnode.c | 187 +++++++++++++++++++++++----------- src/include/nodes/pathnodes.h | 29 +++++- src/include/optimizer/pathnode.h | 1 + src/test/regress/expected/join.out | 37 +++++++ src/test/regress/sql/join.sql | 23 +++++ 7 files changed, 225 insertions(+), 78 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Look through wrapper paths when collecting enforced clause seria @ 2026-10-26 01:07 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-26 01:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Look through wrapper paths when collecting enforced clause serials. get_param_path_clause_serials() handles join paths and Append paths explicitly, and for anything else returns the ppi_serials of the path's ParamPathInfo on the assumption that it is a baserel scan. But Material, Memoize, Projection, Sort, IncrementalSort, Unique, Agg and GroupingSets paths all inherit their subpath's ParamPathInfo, and that assumption fails when the subpath is a join or Append. This could drop a join clause for good. If a LATERAL UNION ALL subquery references an outer relation in an expression that becomes an EquivalenceClass member, the members get no child version of it, so their parameterized scans cannot enforce the derived clause. The appendrel's ParamPathInfo claims it nonetheless, and once a Materialize sat on the Append, create_nestloop_path() dropped the clause from the join above as already enforced, returning rows that fail it. To fix, make get_param_path_clause_serials() recurse through such wrapper paths, since they enforce no clauses of their own. Also use it in get_memoize_path(), which unsafely read ppi_serials directly for its inner-unique check. To try to clarify what's going on here, introduce a new function get_wrapper_parampathinfo() that pathnode.c should use instead of directly assuming that copying a wrapper path's subpath's param_info is what to do. This is just cosmetic at present but might become less so in future. Back-patch to v16, where the serial-based detection of enforced clauses was introduced. Author: Richard Guo <guofenglinux@gmail.com> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: shihao zhong <zhong950419@gmail.com> Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CAMbWs49jVFRZ7oOgMK9zYt7d=SLxpiz=dN=QMu5iV8TS+9T0AA@mail.gmail.com Backpatch-through: 16 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/77c4a9037b8ab79b0c3cb85365d12935ba6dfdb8 Modified Files -------------- src/backend/optimizer/path/joinpath.c | 6 +- src/backend/optimizer/util/pathnode.c | 12 ++- src/backend/optimizer/util/relnode.c | 187 +++++++++++++++++++++++----------- src/include/nodes/pathnodes.h | 29 +++++- src/include/optimizer/pathnode.h | 1 + src/test/regress/expected/join.out | 37 +++++++ src/test/regress/sql/join.sql | 23 +++++ 7 files changed, 221 insertions(+), 74 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Look through wrapper paths when collecting enforced clause seria @ 2026-10-26 01:07 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-26 01:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Look through wrapper paths when collecting enforced clause serials. get_param_path_clause_serials() handles join paths and Append paths explicitly, and for anything else returns the ppi_serials of the path's ParamPathInfo on the assumption that it is a baserel scan. But Material, Memoize, Projection, Sort, IncrementalSort, Unique, Agg and GroupingSets paths all inherit their subpath's ParamPathInfo, and that assumption fails when the subpath is a join or Append. This could drop a join clause for good. If a LATERAL UNION ALL subquery references an outer relation in an expression that becomes an EquivalenceClass member, the members get no child version of it, so their parameterized scans cannot enforce the derived clause. The appendrel's ParamPathInfo claims it nonetheless, and once a Materialize sat on the Append, create_nestloop_path() dropped the clause from the join above as already enforced, returning rows that fail it. To fix, make get_param_path_clause_serials() recurse through such wrapper paths, since they enforce no clauses of their own. Also use it in get_memoize_path(), which unsafely read ppi_serials directly for its inner-unique check. To try to clarify what's going on here, introduce a new function get_wrapper_parampathinfo() that pathnode.c should use instead of directly assuming that copying a wrapper path's subpath's param_info is what to do. This is just cosmetic at present but might become less so in future. Back-patch to v16, where the serial-based detection of enforced clauses was introduced. Author: Richard Guo <guofenglinux@gmail.com> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: shihao zhong <zhong950419@gmail.com> Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CAMbWs49jVFRZ7oOgMK9zYt7d=SLxpiz=dN=QMu5iV8TS+9T0AA@mail.gmail.com Backpatch-through: 16 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3e914438a3ac4abfde004b8a850cb198f64613f3 Modified Files -------------- src/backend/optimizer/path/joinpath.c | 2 +- src/backend/optimizer/util/pathnode.c | 12 +- src/backend/optimizer/util/relnode.c | 212 ++++++++++++++++++++++------------ src/include/nodes/pathnodes.h | 29 ++++- src/include/optimizer/pathnode.h | 1 + src/test/regress/expected/join.out | 37 ++++++ src/test/regress/sql/join.sql | 23 ++++ 7 files changed, 231 insertions(+), 85 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Look through wrapper paths when collecting enforced clause seria @ 2026-10-26 01:07 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Richard Guo @ 2026-10-26 01:07 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Look through wrapper paths when collecting enforced clause serials. get_param_path_clause_serials() handles join paths and Append paths explicitly, and for anything else returns the ppi_serials of the path's ParamPathInfo on the assumption that it is a baserel scan. But Material, Memoize, Projection, Sort, IncrementalSort, Unique, Agg and GroupingSets paths all inherit their subpath's ParamPathInfo, and that assumption fails when the subpath is a join or Append. This could drop a join clause for good. If a LATERAL UNION ALL subquery references an outer relation in an expression that becomes an EquivalenceClass member, the members get no child version of it, so their parameterized scans cannot enforce the derived clause. The appendrel's ParamPathInfo claims it nonetheless, and once a Materialize sat on the Append, create_nestloop_path() dropped the clause from the join above as already enforced, returning rows that fail it. To fix, make get_param_path_clause_serials() recurse through such wrapper paths, since they enforce no clauses of their own. Also use it in get_memoize_path(), which unsafely read ppi_serials directly for its inner-unique check. To try to clarify what's going on here, introduce a new function get_wrapper_parampathinfo() that pathnode.c should use instead of directly assuming that copying a wrapper path's subpath's param_info is what to do. This is just cosmetic at present but might become less so in future. Back-patch to v16, where the serial-based detection of enforced clauses was introduced. Author: Richard Guo <guofenglinux@gmail.com> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: shihao zhong <zhong950419@gmail.com> Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CAMbWs49jVFRZ7oOgMK9zYt7d=SLxpiz=dN=QMu5iV8TS+9T0AA@mail.gmail.com Backpatch-through: 16 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a8b9a7fe42a56fd29e29ea50d54841919e7caeb9 Modified Files -------------- src/backend/optimizer/path/joinpath.c | 2 +- src/backend/optimizer/util/pathnode.c | 12 +- src/backend/optimizer/util/relnode.c | 212 ++++++++++++++++++++++------------ src/include/nodes/pathnodes.h | 29 ++++- src/include/optimizer/pathnode.h | 1 + src/test/regress/expected/join.out | 37 ++++++ src/test/regress/sql/join.sql | 23 ++++ 7 files changed, 231 insertions(+), 85 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2026-10-26 01:07 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-26 01:07 pgsql: Look through wrapper paths when collecting enforced clause seria Richard Guo <rguo@postgresql.org> 2026-10-26 01:07 pgsql: Look through wrapper paths when collecting enforced clause seria Richard Guo <rguo@postgresql.org> 2026-10-26 01:07 pgsql: Look through wrapper paths when collecting enforced clause seria Richard Guo <rguo@postgresql.org> 2026-10-26 01:07 pgsql: Look through wrapper paths when collecting enforced clause seria Richard Guo <rguo@postgresql.org> 2026-10-26 01:07 pgsql: Look through wrapper paths when collecting enforced clause seria 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