[SPARK-42360][SQL] Rule to convert Left Outer Join with suitable filter to Left Anti Join #51762
+1,646
−991
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.
What changes were proposed in this pull request?
Add an Optimizer rule looks for Left Outer Join followed by IsNull(rhs column) and rewrites it as Anti Join if possible
In the simplest case it expects select L.* from L LOJ R on l1 = r1 where r1 is null
or select L.* from L LOJ (select s1 as r1, s2 as r2 from S) R on l1 = r1 where r2 is null.
Why are the changes needed?
This rewrite may provide a performance improvement.
The implementation is not comprehensive but is meant to address the common cases seen in
legacy systems submitting queries with "synthetic anti join" expressed as Left Outer
followed by IsNull filter.
Does this PR introduce any user-facing change?
It may change the query plan to use Left Anti join instead of the original Left Outer join
How was this patch tested?
Existing and newly added Unit tests
Was this patch authored or co-authored using generative AI tooling?
No