Repository navigation
fix: Decide NOT IN null-aware joins from expression nullability, not just column nullability - #25641
Closed
namanjain24-sudo wants to merge 4 commits into
Closed
namanjain24-sudo wants to merge 4 commits into
namanjain24-sudo wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25641 +/- ##
==========================================
- Coverage 82.49% 82.48% -0.01%
==========================================
Files 1140 1140
Lines 438854 438965 +111
Branches 438854 438965 +111
==========================================
+ Hits 362032 362094 +62
- Misses 54952 54968 +16
- Partials 21870 21903 +33 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…just column nullability closes: apache#25473 closes: apache#25474 `join_keys_may_be_null` only checked the schema nullability of the columns a join filter references. A NULL constant or an expression that is nullable even though every column it reads is NOT NULL (CASE without ELSE, NULLIF, arithmetic with a NULL operand) was therefore never treated as needing null-aware semantics, so a NOT IN predicate that should be UNKNOWN silently kept the outer row instead. Replace the column walk with a per-equality-conjunct nullability check that evaluates each operand as an expression against whichever schema it resolves to, falling back to nullable when that can't be determined.
The double-negation query was labeled as demonstrating a flip from false to true. NOT UNKNOWN is UNKNOWN, not TRUE; the query was always empty and is a control from the issue's own table, not evidence of the fix.
- A correlated NOT IN whose value equality is NOT NULL but whose correlation equality is nullable, checked second, exercises the loop continuing past the first conjunct. - An operand referencing columns from both schemas exercises the conservative fallback in operand_may_be_null directly. Verified each fails when the corresponding code path is broken.
namanjain24-sudo
force-pushed
the
fix-not-in-null-aware-nullability
branch
from
September 24, 2026 21:22
5fc19ab to
5509608
Compare
apache#25560, merged after this branch, changed build_join to project a constant IN/NOT IN value as a real column so it takes the on[0] key position instead of the correlation predicate. That now also fires for this test's correlated + null-aware case, which is exactly the scenario apache#25560's own comment on build_join describes. The plan is still null-aware with both equi-join conditions; only the constant's representation changed.
Contributor
Author
|
Bumping this — still open for review whenever someone has bandwidth. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
NOT IN (subquery)returns every row when the subquery column isNOT NULL#25473.NOT IN (subquery)ignores NULLs from a nullable outer expression overNOT NULLcolumns #25474.Rationale for this change
NOT IN (subquery)decides whether it needs null-aware join semantics bychecking if any column in the join filter is nullable. That misses a NULL
constant (
NULL NOT IN (...)) or an expression that is nullable on its own(
CASEwithoutELSE,NULLIF) even when every column it reads isNOT NULL. In both cases a row that should beUNKNOWN(and dropped from theresult) is silently kept.
What changes are included in this PR?
join_keys_may_be_nullindecorrelate_predicate_subquery.rsnow checks thenullability of each equality operand as an expression (via
ExprSchemable),not just the columns it references, falling back to "may be null" when that
can't be resolved to one side.
What is the testing strategy for this PR?
NOT NULLsubquerycolumn, and a
CASEexpression overNOT NULLcolumns, both asserting theresulting join is null-aware.
null_aware_anti_join.sltcovering both issues' tables,including the
ORmark-join form andEXPLAINassertions. Confirmed eachnew query fails on
mainand passes with this change.cargo test -p datafusion-optimizerand the full defaultsqllogictestsuite (521 files) pass. Checked the TPC-H Q16 plan (the only TPC-H query
using this path) is unchanged.
Are there any user-facing changes?
NOT INsubqueries now return correct (fewer) rows for these two cases.No public API changes.