fix: Decide NOT IN null-aware joins from expression nullability, not just column nullability - #25641
Open
namanjain24-sudo wants to merge 2 commits into
Open
namanjain24-sudo wants to merge 2 commits into
namanjain24-sudo wants to merge 2 commits into
Conversation
…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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25641 +/- ##
==========================================
- Coverage 82.45% 82.44% -0.01%
==========================================
Files 1140 1140
Lines 436434 436486 +52
Branches 436434 436486 +52
==========================================
+ Hits 359840 359859 +19
- Misses 54840 54855 +15
- Partials 21754 21772 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
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.