Repository navigation
Fix logical error in arrayUnion and arraySymmetricDifference with a Nullable and a Dynamic argument - #118966
Conversation
… cast one prepareArrays builds an overflow mask for integer-like element types by re-comparing the cast element column against the original with notEquals, so values truncated by the narrowing cast cannot match. It unwrapped ColumnNullable from the initial element column only inside the `if` that tests the cast column, so the two operands could disagree about nullability. With a Dynamic common element type they do. Dynamic cannot sit inside Nullable (DataTypeDynamic::canBeInsideNullable) and getLeastSupertype's Dynamic rule precedes its Nullable rule, so castColumns produces a ColumnDynamic for the cast side while the initial side keeps its ColumnNullable wrapper. Since the element types handed to the comparison are stripped of Nullable, callFunctionNotEquals is given UInt8 for a column that is still a ColumnNullable. The Dynamic adaptor substitutes its own operand's per-variant column and forwards the other untouched, the declared types become equal, and notEquals takes the types_equal branch into executeGenericIdenticalTypes, whose paranoid isNullable() check fires: SELECT arrayUnion([1, NULL], ['a'::Dynamic]) raises a logical error and aborts builds that treat it as fatal. Move the initial-column unwrap out of the cast-column `if` so both operands are unwrapped whenever either is. initial_column is read nowhere after the guard block, so the move is observable only in the shape that fails today: when the cast column is a ColumnNullable the behaviour is byte-identical, and when neither column is nullable it is a no-op. The pointer comparison that gates the mask is unaffected, because without a cast both sides unwrap to the same object and with a cast they differ either way. The same class was fixed at these three lines before, in f8ebd75. arrayUnion and arraySymmetricDifference share prepareArrays and both failed; arrayIntersect resolves its cast target through getMostSubtype, which has no Dynamic handling, so it rejects the mixed spelling with NO_COMMON_TYPE earlier. The defect is not confined to analyzer constant folding either: the same call over table columns failed identically. Master only. Previously the element type stayed Nullable(T) and isInteger(Nullable(T)) is false, so this branch was unreachable for a Nullable element type in every release. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: no findings in the code; two notes disclosedAn independent model re-reviewed this diff cold and returned no findings. My own cold pass raised five, 💡 The moved guard tests 💡 Whenever the cast target is |
|
Workflow [PR], commit [be32a70] Summary: ✅
AI ReviewSummaryThis PR fixes the Missing context / blind spots
Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit be32a70.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
|
cc @Avogar @Ergus, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
Requested in review. The overflow-mask guard has four separate element type
predicates (isInteger, isDate, isDateTime, isDateTime64), so each one now has a
case, and the cases are spread over both functions that can reach the guard with
a Dynamic cast target. Every added statement aborts on master and passes here:
- Date, DateTime and DateTime64 element types, one guard predicate each
- a LowCardinality(Nullable(UInt8)) element type
- non-constant arguments, which run executeImpl rather than the analyzer's
constant folding
- a value present in both arguments, so the result also pins that the overflow
mask stays aligned with the element column it was built from
- an empty array, paired with a non-empty row in the same column: on its own
the cast side is a zero-row ColumnDynamic with no variants, the comparison is
never dispatched, and the case would pass with or without the fix
Results are sorted because the element order of an Array(Dynamic) result is
variant dependent and the order is not the property under test.
arrayIntersect cannot reach this shape: it resolves its cast target through
getMostSubtype, which rejects a number next to Dynamic with NO_COMMON_TYPE.
Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger - a22f0d5Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260910-030114 |
…mic-nullable-column-unwrap
|
@alexey-milovidov the PR is on the queue, why you merged master into it? |
Co-Authored-By: Claude Opus 5 <[email protected]>
…mic-nullable-column-unwrap
|
@PedroTadim, it had a failed check. |
e3d6e2b
|
Fixing PR for the |
Closes: #118961
Related: #118485
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: the defect exists only on master, introduced by the unreleased #118485, so no released version is affected.
Description
SELECT arrayUnion([1, NULL], ['a'::Dynamic])fails withColumns are assumed to be of identical types, but they are different in Nullable, and aborts debug and sanitizer builds.arraySymmetricDifferencebehaves the same, and table columns fail identically, not only constants.prepareArraysbuilds an overflow mask by re-comparing the cast element column against the original withnotEquals, and it unwrapsColumnNullablefrom the initial column only inside theifthat tests the cast one. With aDynamiccommon element type the cast column is aColumnDynamic:Dynamiccannot sit insideNullable, andgetLeastSupertype'sDynamicrule precedes itsNullablerule. So that inner unwrap never runs and the initial column keeps its wrapper, while #118485 stripsNullablefrom both declared types, leavingcallFunctionNotEqualswithUInt8for a still-ColumnNullablecolumn. TheDynamicadaptor substitutes its own operand's per-variant column, so the declared types match andnotEqualsentersexecuteGenericIdenticalTypes, whose paranoidisNullable()check this argument list violates.The fix moves that unwrap out of the cast-column
if, so both operands are unwrapped whenever either is.initial_columnis read nowhere after the guard block, so the move is observable only where it fails today: with no cast both sides unwrap to the same pointer and the guard is skipped as before. Before #118485 the element type stayedNullable(T)andisInteger(Nullable(T))is false, so the branch was unreachable in every release: master only.Validated both directions: four query shapes and the test fail before and pass after, returning the pre-#118485 output
[NULL,1,'a']; 50 randomized runs and five neighbour tests pass.arrayIntersectand theVariantspelling stop at an earlierNO_COMMON_TYPE, so they are not carriers. Residual left alone: the mask is all-zero whenever the cast target isDynamic, which predates this defect.CI provenance: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117973&sha=fea6f43a91efed27ff56e9425b728dfda0498c74&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29
Workflow [PR]
Sync PR [sync-upstream/pr/118966]
Version info
26.9.1.1272(included in26.9and later)