HIVE-29598: Fix vectorized outer join wrong results due to stale scratch column values#6486
Open
ryukobayashi wants to merge 1 commit into
Open
HIVE-29598: Fix vectorized outer join wrong results due to stale scratch column values#6486ryukobayashi wants to merge 1 commit into
ryukobayashi wants to merge 1 commit into
Conversation
…tch column values
|
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 vectorized outer join,
generateOuterNulls()andgenerateOuterNullsRepeatedAll()setisNull[i] = trueon scratch columns but leavevector[i]untouched. Whenhive.vectorized.reuse.scratch.columns=true(the default), a scratch column slotfreed after an expression evaluation (e.g.
CastStringToLong) can be reused for the outer join's null-marking column. Afterreset()clearsisNull[], the expression overwritesvector[i]with a fresh value (e.g. 2025). Later,generateOuterNulls()sets
isNull[i] = truewithout clearingvector[i], leaving a stale non-zero value.Downstream operators such as
ColOrColreadvector[i]directly to distinguish "false" (== 0) from "null" (!= 0). The stale value causes null rows to be misinterpreted as "true", producing wrong OR/AND/CASE WHEN results.The fix adds
clearVectorValue(), called wheneverisNull[i]is set totruein the outer join null-marking paths, zeroingvector[i]for all supported column vector types (LongColumnVector,DoubleColumnVector,BytesColumnVector,TimestampColumnVector,IntervalDayTimeColumnVector).Why are the changes needed?
Without the fix, vectorized outer joins silently return wrong results when scratch column reuse is enabled (the default). The bug is non-obvious because it only triggers when a specific combination of conditions is met: a type-casting expression allocates a scratch column that is later reused for the outer join's null-marking column, and the join result is consumed by a boolean operator that reads the raw vector value for null discrimination. Users have no indication that results are wrong; workarounds require disabling vectorization entirely (
hive.vectorization.enabled=false) or disabling scratch column reuse (hive.vectorized.reuse.scratch.columns=false), both of which carry a significant performance cost.Does this PR introduce any user-facing change?
No
How was this patch tested?
The existing TestMapJoinOperator suite (17 tests) passes without regression. The bug can also be verified manually with the minimal SQL reproducer below; with the fix applied, the result matches the expected output (C 2026 new, D 2026 new) that was previously only obtainable by disabling vectorization.