Fix null-safe comparison exception with const Dynamic/Variant columns#98553
Merged
alexey-milovidov merged 4 commits intomasterfrom Mar 3, 2026
Merged
Fix null-safe comparison exception with const Dynamic/Variant columns#98553alexey-milovidov merged 4 commits intomasterfrom
alexey-milovidov merged 4 commits intomasterfrom
Conversation
The `executeForVariantOrDynamicAndNull` function tried to cast columns directly to `ColumnDynamic`/`ColumnVariant`, but the column could be wrapped in `ColumnConst` when only one argument is constant. Fixed by unwrapping via `convertToFullColumnIfConst` before the cast. Also fixed a pre-existing bug where `IS DISTINCT FROM` with Dynamic/Variant vs NULL always returned 0 due to `ele_is_null && false` always evaluating to `false`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=337832154ed77a0f80ca69c428a5932fb7212c77&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_msan%29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
alexey-milovidov
commented
Mar 2, 2026
src/Functions/FunctionsNullSafeCmp.h
Outdated
| { | ||
| bool ele_is_null = column_variant_or_dynamic.isNullAt(i); | ||
| data[i] = is_equal_mode ? ele_is_null && true : ele_is_null && false; | ||
| data[i] = is_equal_mode ? ele_is_null : !ele_is_null; |
Member
Author
There was a problem hiding this comment.
Who writes "element" as "ele"? 🤢
Member
Author
There was a problem hiding this comment.
No wonder this code has a bug.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The fix for `IS DISTINCT FROM` with `Dynamic`/`Variant` vs `NULL` changes the result from always 0 to correctly returning 1 for non-null values. Update the existing test reference to reflect the correct behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Bad cast from type ColumnConst to ColumnDynamicwhen using<=>/IS NOT DISTINCT FROMwith a constDynamicorVariantcolumn vsNULL. The column is now unwrapped viaconvertToFullColumnIfConstbefore casting.IS DISTINCT FROMwithDynamic/VariantvsNULLalways returned 0 due toele_is_null && falsealways evaluating tofalse.Found by AST fuzzer (MSan): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=337832154ed77a0f80ca69c428a5932fb7212c77&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_msan%29
Test plan
04010_null_safe_cmp_dynamic_constChangelog category:
Changelog entry:
Fixed exception
Bad cast from type ColumnConst to ColumnDynamicin null-safe comparison (<=>/IS NOT DISTINCT FROM) with constDynamicorVariantcolumns andNULL. Also fixedIS DISTINCT FROMwithDynamic/VariantvsNULLalways incorrectly returning 0.🤖 Generated with Claude Code