Skip to content

[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
apache:masterfrom
gengliangwang:spark-in-nullcheck
Open

[SPARK-57202][SQL] Skip dead null checks in In expression codegen for non-null list elements#56258
gengliangwang wants to merge 1 commit into
apache:masterfrom
gengliangwang:spark-in-nullcheck

Conversation

@gengliangwang
Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

In's whole-stage codegen emits, for each list element x:

if (x.isNull) {
  inTmpResult = -1; // HAS_NULL
} else if (value == x) {
  inTmpResult = 1;  // MATCHED
  continue;
}

IN lists are usually constant literals, so x.isNull is the literal false and the HAS_NULL branch is dead (if (false) { inTmpResult = -1; } else if ...). This PR emits only the equality check when x.isNull == FalseLiteral. Symmetrically, when an element is statically null (x.isNull == TrueLiteral, e.g. IN (NULL, ...)), only the HAS_NULL assignment 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 from In over 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, including In with null list elements and a null left-hand value), all pass. Additionally verified by re-dumping the TPC-DS whole-stage codegen: the ~348 dead if (false) blocks in In are 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)

… 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)
@gengliangwang gengliangwang requested a review from LuciferYang June 2, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant