[BugFix] Fix shared NullColumn in map_apply, array_length, and normalize_column_type#71258
Draft
GavinMar wants to merge 1 commit intoStarRocks:branch-4.1.0from
Draft
[BugFix] Fix shared NullColumn in map_apply, array_length, and normalize_column_type#71258GavinMar wants to merge 1 commit intoStarRocks:branch-4.1.0from
GavinMar wants to merge 1 commit intoStarRocks:branch-4.1.0from
Conversation
…ize_column_type When COW optimization is enabled, `std::move(*nullable->null_column()).mutate()` returns the same NullColumn object without cloning (use_count==1), causing two NullableColumns to share the same NullColumn. Use `Column::mutate(nullable->null_column())` instead, which implicitly copies the ColumnPtr parameter, bumping use_count>=2 and forcing a proper clone.
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 problem does this PR solve?
Fix a crash (
Check failed: _data_column->size() == _null_column->size()) caused by two NullableColumns in the same Chunk sharing the same NullColumn object.Root Cause
The bug is triggered by an unsafe pattern for obtaining a mutable NullColumn:
Crash Trigger Path
For the query:
SelectOperator::push_chunkevaluates_common_exprs(e.g.,map_apply(s.map2)) and appends the result as a new column (slot20) to the chunkmap_apply_expr.cpp:85usesstd::move(*nullable->null_column()).mutate()to extract the input's NullColumn — with COW optimization anduse_count==1, this returns the same NullColumn objecteval_conjuncts_and_in_filters→eager_prune_eval_conjuncts→Chunk::filter()Chunk::filter()iterates columns: filtering slot4 shrinks the shared NullColumn (3→2)_data_column->size()==3but_null_column->size()==2→ CHECK FAIL / CRASHFix
Replace all instances of the unsafe
std::move(*nullable->null_column()).mutate()pattern withColumn::mutate(nullable->null_column())in:map_apply_expr.cpp:85— the primary trigger for this crasharray_functions.cpp:62(array_length) — same unsafe patternWhat tests does this PR have?
Existing test:
test/sql/test_join/R/test_join_mapThe crash was reproducible with the
map_applyjoin queries in this test file. After the fix, the test passes without theCheck failedassertion.Related PRs
Follow-up to #71207 which fixed the same class of bug in
array_functions.cpp,binary_function.h,map_functions.cpp, andngram.cpp— but missed the locations fixed in this PR.