agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Fix nullability check for a sub-select's upper-level Vars 2+ messages / 1 participants [nested] [flat]
* pgsql: Fix nullability check for a sub-select's upper-level Vars @ 2026-08-03 06:53 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Richard Guo @ 2026-08-03 06:53 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix nullability check for a sub-select's upper-level Vars When checking whether a sub-select's output columns can produce NULL, so as to decide whether a NOT IN can be converted to an anti-join, query_outputs_are_not_nullable() falls back on find_nonnullable_vars() for targetlist entries that are plain Vars: if the sub-select's own quals prove the Var non-null, the output is non-nullable. But that test compared only varno and varattno, without checking varlevelsup. An outer reference in the targetlist could thus be matched against a Var of the sub-select's own range table that happens to share the same varno and varattno, wrongly proving the output non-nullable and allowing an invalid conversion to an anti-join, which yields wrong answers when the outer reference is NULL. To fix, restrict the fallback to Vars of the current query level. Author: Rui Zhao <zhaorui126@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAHWVJhGuaFFRpmq4j+mcMcm_HC5QOT7LZsC9bf9b7BCBmvbfMA@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0d99579320d075eba5733517463d81a2231e373b Modified Files -------------- src/backend/optimizer/util/clauses.c | 3 ++- src/test/regress/expected/subselect.out | 24 ++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Fix nullability check for a sub-select's upper-level Vars @ 2026-08-03 06:53 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Richard Guo @ 2026-08-03 06:53 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix nullability check for a sub-select's upper-level Vars When checking whether a sub-select's output columns can produce NULL, so as to decide whether a NOT IN can be converted to an anti-join, query_outputs_are_not_nullable() falls back on find_nonnullable_vars() for targetlist entries that are plain Vars: if the sub-select's own quals prove the Var non-null, the output is non-nullable. But that test compared only varno and varattno, without checking varlevelsup. An outer reference in the targetlist could thus be matched against a Var of the sub-select's own range table that happens to share the same varno and varattno, wrongly proving the output non-nullable and allowing an invalid conversion to an anti-join, which yields wrong answers when the outer reference is NULL. To fix, restrict the fallback to Vars of the current query level. Author: Rui Zhao <zhaorui126@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAHWVJhGuaFFRpmq4j+mcMcm_HC5QOT7LZsC9bf9b7BCBmvbfMA@mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3fb599b26411a1322dec89759349ce4920e1055a Modified Files -------------- src/backend/optimizer/util/clauses.c | 3 ++- src/test/regress/expected/subselect.out | 24 ++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-08-03 06:53 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-08-03 06:53 pgsql: Fix nullability check for a sub-select's upper-level Vars Richard Guo <rguo@postgresql.org> 2026-08-03 06:53 pgsql: Fix nullability check for a sub-select's upper-level Vars Richard Guo <rguo@postgresql.org>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox