pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix constant propagation through FULL JOIN clauses 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix constant propagation through FULL JOIN clauses @ 2026-11-11 15:35 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 6+ messages in thread From: Tomas Vondra @ 2026-11-11 15:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix constant propagation through FULL JOIN clauses Given a FULL JOIN clause "LEFTVAR = RIGHTVAR" and an EquivalenceClass containing the expression COALESCE(LEFTVAR, RIGHTVAR) and a constant, reconsider_full_join_clause() derives "LEFTVAR = CONSTANT" and "RIGHTVAR = CONSTANT" and discards the join clause and the COALESCE condition. It however assumed LEFTVAR comes from the join's lefthand input and RIGHTVAR from its righthand input, which holds for FULL JOIN USING but not necessarily for a user-written ON clause. With the operands reversed, the derived equalities got the wrong JoinDomains. That could cause an assertion failure or, in non-assert builds, incorrect results, due to a derived qual being applied to the wrong side of the join. With both operands from the same input, or one referencing both inputs, nothing can be deduced, yet bogus equalities were derived anyway. Both could produce wrong results. Fix by determining which input each operand comes from, and giving up unless they come from different inputs. A FULL JOIN whose only condition is a clause of the latter kind now fails with "FULL JOIN is only supported with merge-joinable or hash-joinable join conditions", as it would without the COALESCE condition. The JoinDomain problem was introduced in v16. The other one (bogus equalities derived from a qual with both operands from the same input, or one referencing both inputs) exists in all supported branches, but before the introduction of outer-join-aware Vars (v16) only an operand referencing both inputs can trigger it. Backpatch to all supported versions. The 15 branch needs only the part addressing the second issue. Author: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/92808d26-1b4a-48fe-82f0-597da3ff471f@vondra.me Backpatch-through: 15 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e50d958f092bc33fcb51089c68c72779bae2a6a3 Modified Files -------------- src/backend/optimizer/path/equivclass.c | 36 ++++-- src/backend/optimizer/plan/initsplan.c | 7 +- src/test/regress/expected/join.out | 211 ++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 83 +++++++++++++ 4 files changed, 326 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix constant propagation through FULL JOIN clauses @ 2026-11-11 15:35 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 6+ messages in thread From: Tomas Vondra @ 2026-11-11 15:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix constant propagation through FULL JOIN clauses Given a FULL JOIN clause "LEFTVAR = RIGHTVAR" and an EquivalenceClass containing the expression COALESCE(LEFTVAR, RIGHTVAR) and a constant, reconsider_full_join_clause() derives "LEFTVAR = CONSTANT" and "RIGHTVAR = CONSTANT" and discards the join clause and the COALESCE condition. It however assumed LEFTVAR comes from the join's lefthand input and RIGHTVAR from its righthand input, which holds for FULL JOIN USING but not necessarily for a user-written ON clause. With the operands reversed, the derived equalities got the wrong JoinDomains. That could cause an assertion failure or, in non-assert builds, incorrect results, due to a derived qual being applied to the wrong side of the join. With both operands from the same input, or one referencing both inputs, nothing can be deduced, yet bogus equalities were derived anyway. Both could produce wrong results. Fix by determining which input each operand comes from, and giving up unless they come from different inputs. A FULL JOIN whose only condition is a clause of the latter kind now fails with "FULL JOIN is only supported with merge-joinable or hash-joinable join conditions", as it would without the COALESCE condition. The JoinDomain problem was introduced in v16. The other one (bogus equalities derived from a qual with both operands from the same input, or one referencing both inputs) exists in all supported branches, but before the introduction of outer-join-aware Vars (v16) only an operand referencing both inputs can trigger it. Backpatch to all supported versions. The 15 branch needs only the part addressing the second issue. Author: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/92808d26-1b4a-48fe-82f0-597da3ff471f@vondra.me Backpatch-through: 15 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/84b67a8310dfad1047f19e1eddec74906ed56d8a Modified Files -------------- src/backend/optimizer/path/equivclass.c | 36 ++++-- src/backend/optimizer/plan/initsplan.c | 7 +- src/test/regress/expected/join.out | 211 ++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 83 +++++++++++++ 4 files changed, 326 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix constant propagation through FULL JOIN clauses @ 2026-11-11 15:35 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 6+ messages in thread From: Tomas Vondra @ 2026-11-11 15:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix constant propagation through FULL JOIN clauses Given a FULL JOIN clause "LEFTVAR = RIGHTVAR" and an EquivalenceClass containing the expression COALESCE(LEFTVAR, RIGHTVAR) and a constant, reconsider_full_join_clause() derives "LEFTVAR = CONSTANT" and "RIGHTVAR = CONSTANT" and discards the join clause and the COALESCE condition. It however assumed LEFTVAR comes from the join's lefthand input and RIGHTVAR from its righthand input, which holds for FULL JOIN USING but not necessarily for a user-written ON clause. With the operands reversed, the derived equalities got the wrong JoinDomains. That could cause an assertion failure or, in non-assert builds, incorrect results, due to a derived qual being applied to the wrong side of the join. With both operands from the same input, or one referencing both inputs, nothing can be deduced, yet bogus equalities were derived anyway. Both could produce wrong results. Fix by determining which input each operand comes from, and giving up unless they come from different inputs. A FULL JOIN whose only condition is a clause of the latter kind now fails with "FULL JOIN is only supported with merge-joinable or hash-joinable join conditions", as it would without the COALESCE condition. The JoinDomain problem was introduced in v16. The other one (bogus equalities derived from a qual with both operands from the same input, or one referencing both inputs) exists in all supported branches, but before the introduction of outer-join-aware Vars (v16) only an operand referencing both inputs can trigger it. Backpatch to all supported versions. The 15 branch needs only the part addressing the second issue. Author: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/92808d26-1b4a-48fe-82f0-597da3ff471f@vondra.me Backpatch-through: 15 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/50cbffb7917a47c5f8f0df3b5994888a36c08ffb Modified Files -------------- src/backend/optimizer/path/equivclass.c | 36 ++++-- src/backend/optimizer/plan/initsplan.c | 7 +- src/test/regress/expected/join.out | 211 ++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 83 +++++++++++++ 4 files changed, 326 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix constant propagation through FULL JOIN clauses @ 2026-11-11 15:35 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 6+ messages in thread From: Tomas Vondra @ 2026-11-11 15:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix constant propagation through FULL JOIN clauses Given a FULL JOIN clause "LEFTVAR = RIGHTVAR" and an EquivalenceClass containing the expression COALESCE(LEFTVAR, RIGHTVAR) and a constant, reconsider_full_join_clause() derives "LEFTVAR = CONSTANT" and "RIGHTVAR = CONSTANT" and discards the join clause and the COALESCE condition. It however assumed LEFTVAR comes from the join's lefthand input and RIGHTVAR from its righthand input, which holds for FULL JOIN USING but not necessarily for a user-written ON clause. With the operands reversed, the derived equalities got the wrong JoinDomains. That could cause an assertion failure or, in non-assert builds, incorrect results, due to a derived qual being applied to the wrong side of the join. With both operands from the same input, or one referencing both inputs, nothing can be deduced, yet bogus equalities were derived anyway. Both could produce wrong results. Fix by determining which input each operand comes from, and giving up unless they come from different inputs. A FULL JOIN whose only condition is a clause of the latter kind now fails with "FULL JOIN is only supported with merge-joinable or hash-joinable join conditions", as it would without the COALESCE condition. The JoinDomain problem was introduced in v16. The other one (bogus equalities derived from a qual with both operands from the same input, or one referencing both inputs) exists in all supported branches, but before the introduction of outer-join-aware Vars (v16) only an operand referencing both inputs can trigger it. Backpatch to all supported versions. The 15 branch needs only the part addressing the second issue. Author: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/92808d26-1b4a-48fe-82f0-597da3ff471f@vondra.me Backpatch-through: 15 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d35a59f1b9bcb239bdd6f1378fb996dac251ef7f Modified Files -------------- src/backend/optimizer/path/equivclass.c | 36 ++++-- src/backend/optimizer/plan/initsplan.c | 7 +- src/test/regress/expected/join.out | 211 ++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 83 +++++++++++++ 4 files changed, 326 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix constant propagation through FULL JOIN clauses @ 2026-11-11 15:35 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 6+ messages in thread From: Tomas Vondra @ 2026-11-11 15:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix constant propagation through FULL JOIN clauses Given a FULL JOIN clause "LEFTVAR = RIGHTVAR" and an EquivalenceClass containing the expression COALESCE(LEFTVAR, RIGHTVAR) and a constant, reconsider_full_join_clause() derives "LEFTVAR = CONSTANT" and "RIGHTVAR = CONSTANT" and discards the join clause and the COALESCE condition. It however assumed LEFTVAR comes from the join's lefthand input and RIGHTVAR from its righthand input, which holds for FULL JOIN USING but not necessarily for a user-written ON clause. With the operands reversed, the derived equalities got the wrong JoinDomains. That could cause an assertion failure or, in non-assert builds, incorrect results, due to a derived qual being applied to the wrong side of the join. With both operands from the same input, or one referencing both inputs, nothing can be deduced, yet bogus equalities were derived anyway. Both could produce wrong results. Fix by determining which input each operand comes from, and giving up unless they come from different inputs. A FULL JOIN whose only condition is a clause of the latter kind now fails with "FULL JOIN is only supported with merge-joinable or hash-joinable join conditions", as it would without the COALESCE condition. The JoinDomain problem was introduced in v16. The other one (bogus equalities derived from a qual with both operands from the same input, or one referencing both inputs) exists in all supported branches, but before the introduction of outer-join-aware Vars (v16) only an operand referencing both inputs can trigger it. Backpatch to all supported versions. The 15 branch needs only the part addressing the second issue. Author: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/92808d26-1b4a-48fe-82f0-597da3ff471f@vondra.me Backpatch-through: 15 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7594f33ab81c00ea8e5b09ce25e7ae67274b452d Modified Files -------------- src/backend/optimizer/path/equivclass.c | 36 ++++-- src/backend/optimizer/plan/initsplan.c | 7 +- src/test/regress/expected/join.out | 211 ++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 83 +++++++++++++ 4 files changed, 326 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix constant propagation through FULL JOIN clauses @ 2026-11-11 15:36 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 6+ messages in thread From: Tomas Vondra @ 2026-11-11 15:36 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix constant propagation through FULL JOIN clauses Given a FULL JOIN clause "LEFTVAR = RIGHTVAR" and an EquivalenceClass containing the expression COALESCE(LEFTVAR, RIGHTVAR) and a constant, reconsider_full_join_clause() derives "LEFTVAR = CONSTANT" and "RIGHTVAR = CONSTANT" and discards the join clause and the COALESCE condition. It however assumed LEFTVAR comes from the join's lefthand input and RIGHTVAR from its righthand input, which holds for FULL JOIN USING but not necessarily for a user-written ON clause. With the operands reversed, the derived equalities got the wrong JoinDomains. That could cause an assertion failure or, in non-assert builds, incorrect results, due to a derived qual being applied to the wrong side of the join. With both operands from the same input, or one referencing both inputs, nothing can be deduced, yet bogus equalities were derived anyway. Both could produce wrong results. Fix by determining which input each operand comes from, and giving up unless they come from different inputs. A FULL JOIN whose only condition is a clause of the latter kind now fails with "FULL JOIN is only supported with merge-joinable or hash-joinable join conditions", as it would without the COALESCE condition. The JoinDomain problem was introduced in v16. The other one (bogus equalities derived from a qual with both operands from the same input, or one referencing both inputs) exists in all supported branches, but before the introduction of outer-join-aware Vars (v16) only an operand referencing both inputs can trigger it. Backpatch to all supported versions. The 15 branch needs only the part addressing the second issue. Author: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/92808d26-1b4a-48fe-82f0-597da3ff471f@vondra.me Backpatch-through: 15 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e3dfb42efd776119b5bbceb0ad39887000fe0d0d Modified Files -------------- src/backend/optimizer/path/equivclass.c | 38 ++++++++++++++++++ src/backend/optimizer/plan/initsplan.c | 6 +-- src/test/regress/expected/join.out | 69 +++++++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 33 ++++++++++++++++ 4 files changed, 143 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-11-11 15:36 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-11 15:35 pgsql: Fix constant propagation through FULL JOIN clauses Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 15:35 pgsql: Fix constant propagation through FULL JOIN clauses Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 15:35 pgsql: Fix constant propagation through FULL JOIN clauses Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 15:35 pgsql: Fix constant propagation through FULL JOIN clauses Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 15:35 pgsql: Fix constant propagation through FULL JOIN clauses Tomas Vondra <tomas.vondra@postgresql.org> 2026-11-11 15:36 pgsql: Fix constant propagation through FULL JOIN clauses 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