pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Reject join input paths parameterized by pushed-down outer joins 5+ messages / 1 participants [nested] [flat]
* pgsql: Reject join input paths parameterized by pushed-down outer joins @ 2026-11-11 17:48 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Tomas Vondra @ 2026-11-11 17:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject join input paths parameterized by pushed-down outer joins. Commit a798660ebe3 taught try_nestloop_path(), try_mergejoin_path() and try_hashjoin_path() to reject an input path with a nonsensical parameterization. But that check has a gap, making it possible to hit the assertion in get_joinrel_parampathinfo() added by 5b7b5518d0ea. We need to reject all paths whose parameterization includes the outer join being formed at the current join, since a value that is supposed to be nulled by that outer join can't be available before the join is done. That check considered only sjinfo->ojrelid, but that's insufficient because of joins pushed down into the RHS per outer-join identity 3. That relid is added only at the join that completes it, with the relid of the outer join performed there (see add_outer_joins_to_relids). This omission allowed building paths parameterized by a pushed-down outer join, which is still nonsensical. In non-assert builds this is mostly harmless - we add the patch to the joinrel pathlist, but as the parameterization contains relids within the joinrel itself, no upper join can supply that. And thus it will be unused. To fix, determine the full set of outer joins computed at the current join. That includes sjinfo's own OJ plus any pushed-down OJs completed there. We do this once in add_paths_to_joinrel(), and save it in a new JoinPathExtraData field, and check the input paths' parameterization against that whole set. The partial-path variants need no change, since they never accept input paths whose parameterization isn't satisfied by the outer rel. Backpatch to 16, where 2489d76c490 made Vars outer-join-aware and 9df8f903eb6 introduced the delayed addition of pushed-down outer join relids. The checks added by a798660ebe3 did not cover this case. The new JoinPathExtraData field needs to go at the end of the struct, to avoid an ABI break. It's allocated only in add_paths_to_joinrel (on stack), and only passed through a pointer, so this should be safe. Author: Tomas Vondra <tomas@vondra.me> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Backpatch-through: 16 Discussion: https://postgr.es/m/72d81c95-60fc-48bb-b5e2-e3346c17dd11@vondra.me Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/f14a16c28bcf1ffaa4e8d6bf9bd4b519bb4517d5 Modified Files -------------- src/backend/optimizer/path/joinpath.c | 53 +++++++++++++++++++++++++++-------- src/include/nodes/pathnodes.h | 4 +++ src/test/regress/expected/join.out | 35 +++++++++++++++++++++++ src/test/regress/sql/join.sql | 15 ++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Reject join input paths parameterized by pushed-down outer joins @ 2026-11-11 17:48 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Tomas Vondra @ 2026-11-11 17:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject join input paths parameterized by pushed-down outer joins. Commit a798660ebe3 taught try_nestloop_path(), try_mergejoin_path() and try_hashjoin_path() to reject an input path with a nonsensical parameterization. But that check has a gap, making it possible to hit the assertion in get_joinrel_parampathinfo() added by 5b7b5518d0ea. We need to reject all paths whose parameterization includes the outer join being formed at the current join, since a value that is supposed to be nulled by that outer join can't be available before the join is done. That check considered only sjinfo->ojrelid, but that's insufficient because of joins pushed down into the RHS per outer-join identity 3. That relid is added only at the join that completes it, with the relid of the outer join performed there (see add_outer_joins_to_relids). This omission allowed building paths parameterized by a pushed-down outer join, which is still nonsensical. In non-assert builds this is mostly harmless - we add the patch to the joinrel pathlist, but as the parameterization contains relids within the joinrel itself, no upper join can supply that. And thus it will be unused. To fix, determine the full set of outer joins computed at the current join. That includes sjinfo's own OJ plus any pushed-down OJs completed there. We do this once in add_paths_to_joinrel(), and save it in a new JoinPathExtraData field, and check the input paths' parameterization against that whole set. The partial-path variants need no change, since they never accept input paths whose parameterization isn't satisfied by the outer rel. Backpatch to 16, where 2489d76c490 made Vars outer-join-aware and 9df8f903eb6 introduced the delayed addition of pushed-down outer join relids. The checks added by a798660ebe3 did not cover this case. The new JoinPathExtraData field needs to go at the end of the struct, to avoid an ABI break. It's allocated only in add_paths_to_joinrel (on stack), and only passed through a pointer, so this should be safe. Author: Tomas Vondra <tomas@vondra.me> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Backpatch-through: 16 Discussion: https://postgr.es/m/72d81c95-60fc-48bb-b5e2-e3346c17dd11@vondra.me Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c0a8bb1262925d1573ccec8794a60a83f1ac4622 Modified Files -------------- src/backend/optimizer/path/joinpath.c | 53 +++++++++++++++++++++++++++-------- src/include/nodes/pathnodes.h | 4 +++ src/test/regress/expected/join.out | 35 +++++++++++++++++++++++ src/test/regress/sql/join.sql | 15 ++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Reject join input paths parameterized by pushed-down outer joins @ 2026-11-11 17:48 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Tomas Vondra @ 2026-11-11 17:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject join input paths parameterized by pushed-down outer joins. Commit a798660ebe3 taught try_nestloop_path(), try_mergejoin_path() and try_hashjoin_path() to reject an input path with a nonsensical parameterization. But that check has a gap, making it possible to hit the assertion in get_joinrel_parampathinfo() added by 5b7b5518d0ea. We need to reject all paths whose parameterization includes the outer join being formed at the current join, since a value that is supposed to be nulled by that outer join can't be available before the join is done. That check considered only sjinfo->ojrelid, but that's insufficient because of joins pushed down into the RHS per outer-join identity 3. That relid is added only at the join that completes it, with the relid of the outer join performed there (see add_outer_joins_to_relids). This omission allowed building paths parameterized by a pushed-down outer join, which is still nonsensical. In non-assert builds this is mostly harmless - we add the patch to the joinrel pathlist, but as the parameterization contains relids within the joinrel itself, no upper join can supply that. And thus it will be unused. To fix, determine the full set of outer joins computed at the current join. That includes sjinfo's own OJ plus any pushed-down OJs completed there. We do this once in add_paths_to_joinrel(), and save it in a new JoinPathExtraData field, and check the input paths' parameterization against that whole set. The partial-path variants need no change, since they never accept input paths whose parameterization isn't satisfied by the outer rel. Backpatch to 16, where 2489d76c490 made Vars outer-join-aware and 9df8f903eb6 introduced the delayed addition of pushed-down outer join relids. The checks added by a798660ebe3 did not cover this case. The new JoinPathExtraData field needs to go at the end of the struct, to avoid an ABI break. It's allocated only in add_paths_to_joinrel (on stack), and only passed through a pointer, so this should be safe. Author: Tomas Vondra <tomas@vondra.me> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Backpatch-through: 16 Discussion: https://postgr.es/m/72d81c95-60fc-48bb-b5e2-e3346c17dd11@vondra.me Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/52cb12240cd02c2a435d6aee4f778e155b1ed77a Modified Files -------------- src/backend/optimizer/path/joinpath.c | 53 +++++++++++++++++++++++++++-------- src/include/nodes/pathnodes.h | 4 +++ src/test/regress/expected/join.out | 35 +++++++++++++++++++++++ src/test/regress/sql/join.sql | 15 ++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Reject join input paths parameterized by pushed-down outer joins @ 2026-11-11 17:49 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Tomas Vondra @ 2026-11-11 17:49 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject join input paths parameterized by pushed-down outer joins. Commit a798660ebe3 taught try_nestloop_path(), try_mergejoin_path() and try_hashjoin_path() to reject an input path with a nonsensical parameterization. But that check has a gap, making it possible to hit the assertion in get_joinrel_parampathinfo() added by 5b7b5518d0ea. We need to reject all paths whose parameterization includes the outer join being formed at the current join, since a value that is supposed to be nulled by that outer join can't be available before the join is done. That check considered only sjinfo->ojrelid, but that's insufficient because of joins pushed down into the RHS per outer-join identity 3. That relid is added only at the join that completes it, with the relid of the outer join performed there (see add_outer_joins_to_relids). This omission allowed building paths parameterized by a pushed-down outer join, which is still nonsensical. In non-assert builds this is mostly harmless - we add the patch to the joinrel pathlist, but as the parameterization contains relids within the joinrel itself, no upper join can supply that. And thus it will be unused. To fix, determine the full set of outer joins computed at the current join. That includes sjinfo's own OJ plus any pushed-down OJs completed there. We do this once in add_paths_to_joinrel(), and save it in a new JoinPathExtraData field, and check the input paths' parameterization against that whole set. The partial-path variants need no change, since they never accept input paths whose parameterization isn't satisfied by the outer rel. Backpatch to 16, where 2489d76c490 made Vars outer-join-aware and 9df8f903eb6 introduced the delayed addition of pushed-down outer join relids. The checks added by a798660ebe3 did not cover this case. The new JoinPathExtraData field needs to go at the end of the struct, to avoid an ABI break. It's allocated only in add_paths_to_joinrel (on stack), and only passed through a pointer, so this should be safe. Author: Tomas Vondra <tomas@vondra.me> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Backpatch-through: 16 Discussion: https://postgr.es/m/72d81c95-60fc-48bb-b5e2-e3346c17dd11@vondra.me Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1603fe94fa05f66056aa29e7ad0d58f8f3b8231e Modified Files -------------- src/backend/optimizer/path/joinpath.c | 53 +++++++++++++++++++++++++++-------- src/include/nodes/pathnodes.h | 4 +++ src/test/regress/expected/join.out | 35 +++++++++++++++++++++++ src/test/regress/sql/join.sql | 15 ++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Reject join input paths parameterized by pushed-down outer joins @ 2026-11-11 17:49 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 5+ messages in thread From: Tomas Vondra @ 2026-11-11 17:49 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject join input paths parameterized by pushed-down outer joins. Commit a798660ebe3 taught try_nestloop_path(), try_mergejoin_path() and try_hashjoin_path() to reject an input path with a nonsensical parameterization. But that check has a gap, making it possible to hit the assertion in get_joinrel_parampathinfo() added by 5b7b5518d0ea. We need to reject all paths whose parameterization includes the outer join being formed at the current join, since a value that is supposed to be nulled by that outer join can't be available before the join is done. That check considered only sjinfo->ojrelid, but that's insufficient because of joins pushed down into the RHS per outer-join identity 3. That relid is added only at the join that completes it, with the relid of the outer join performed there (see add_outer_joins_to_relids). This omission allowed building paths parameterized by a pushed-down outer join, which is still nonsensical. In non-assert builds this is mostly harmless - we add the patch to the joinrel pathlist, but as the parameterization contains relids within the joinrel itself, no upper join can supply that. And thus it will be unused. To fix, determine the full set of outer joins computed at the current join. That includes sjinfo's own OJ plus any pushed-down OJs completed there. We do this once in add_paths_to_joinrel(), and save it in a new JoinPathExtraData field, and check the input paths' parameterization against that whole set. The partial-path variants need no change, since they never accept input paths whose parameterization isn't satisfied by the outer rel. Backpatch to 16, where 2489d76c490 made Vars outer-join-aware and 9df8f903eb6 introduced the delayed addition of pushed-down outer join relids. The checks added by a798660ebe3 did not cover this case. The new JoinPathExtraData field needs to go at the end of the struct, to avoid an ABI break. It's allocated only in add_paths_to_joinrel (on stack), and only passed through a pointer, so this should be safe. Author: Tomas Vondra <tomas@vondra.me> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Backpatch-through: 16 Discussion: https://postgr.es/m/72d81c95-60fc-48bb-b5e2-e3346c17dd11@vondra.me Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/be913fabe79d73a37af55eafc3d3352db4c3d1ca Modified Files -------------- src/backend/optimizer/path/joinpath.c | 53 +++++++++++++++++++++++++++-------- src/include/nodes/pathnodes.h | 4 +++ src/test/regress/expected/join.out | 35 +++++++++++++++++++++++ src/test/regress/sql/join.sql | 15 ++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2026-11-11 17:49 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-11 17:48 pgsql: Reject join input paths parameterized by pushed-down outer joins Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 17:48 pgsql: Reject join input paths parameterized by pushed-down outer joins Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 17:48 pgsql: Reject join input paths parameterized by pushed-down outer joins Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 17:49 pgsql: Reject join input paths parameterized by pushed-down outer joins Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 17:49 pgsql: Reject join input paths parameterized by pushed-down outer joins Tomas Vondra <tomas.vondra@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