[SPARK-57202][SQL] Skip dead null checks in In expression codegen for non-null list elements#56258
Open
gengliangwang wants to merge 1 commit into
Open
[SPARK-57202][SQL] Skip dead null checks in In expression codegen for non-null list elements#56258gengliangwang wants to merge 1 commit into
gengliangwang wants to merge 1 commit into
Conversation
… non-null list elements
In's codegen emits `if (x.isNull) { HAS_NULL } else if (value == x) {...}`
per list element. IN lists are usually constant literals, so x.isNull is the
literal `false` and the HAS_NULL branch is dead. Emit only the equality check
when `x.isNull == FalseLiteral`; emit only HAS_NULL when the element is
statically null (`x.isNull == TrueLiteral`).
Across the TPC-DS queries this removes ~348 dead `if (false)` blocks. IN
semantics (including with nulls) are unchanged.
Generated-by: Claude Code (Opus 4.8)
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.
What changes were proposed in this pull request?
In's whole-stage codegen emits, for each list elementx:IN lists are usually constant literals, so
x.isNullis the literalfalseand theHAS_NULLbranch is dead (if (false) { inTmpResult = -1; } else if ...). This PR emits only the equality check whenx.isNull == FalseLiteral. Symmetrically, when an element is statically null (x.isNull == TrueLiteral, e.g.IN (NULL, ...)), only theHAS_NULLassignment is emitted and the dead equality check is dropped.Why are the changes needed?
Sub-task of SPARK-56908 (reduce generated Java size in whole-stage codegen). Dumping the TPC-DS whole-stage codegen shows ~348 dead
if (false) { inTmpResult = -1; } else if (...)blocks fromInover literal lists. Emitting only the live branch removes the dead conditional from the generated code.Does this PR introduce any user-facing change?
No. The generated code is smaller but evaluates IN with identical (including null) semantics: a statically non-null element can never set
HAS_NULL, and a statically null element can never match, so dropping those dead branches is equivalent.How was this patch tested?
Behavior-preserving change covered by
PredicateSuite(70 tests, includingInwith null list elements and a null left-hand value), all pass. Additionally verified by re-dumping the TPC-DS whole-stage codegen: the ~348 deadif (false)blocks inInare gone and every generated subtree still compiles.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)