Repository navigation
Conversation
A non-nullable LowCardinality(T) element of Nullable(Tuple(..., LowCardinality(T), ...)) used as a sort key aborted the server with "Sort order of blocks violated" during a horizontal merge (OPTIMIZE FINAL). Such an element reaches NullableSubcolumnCreator::create as a ColumnLowCardinality whose dictionary is not nullable, so both canExtractedSubcolumnsBeInsideNullable and canContainNull are false. Neither create overload applied the outer tuple null map, so the in-memory sort key re-extracted during the merge exposed the inner dictionary value for rows whose outer tuple was NULL. That contradicted the on-disk sort key (which combined both masks), and the next merge tripped CheckSortedTransform. The type creator now promotes such an element to LowCardinality(Nullable(T)) (reusing makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe), and the column creator promotes the ColumnLowCardinality with cloneNullable() before folding in the outer mask via applyParentNullMapToExtractedSubcolumn, so the extracted (type, column) pair stays consistent and can represent the outer NULLs. Other carriers (ColumnNullable, LowCardinality(Nullable), Dynamic, Variant) are unchanged. Extends 04339_105356_nullable_tuple_subcolumn_sort_order with the non-nullable LC carrier. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Known separate gap (flagged in the PR description, not addressed here): the on-disk Session id: cron:clickhouse-worker-slot-2:20260627-045100 |
|
cc @Avogar @CurtizJ -- could you review this? It is the residual carrier-3 of #105356 that #102942 did not cover: a non-nullable |
|
Workflow [PR], commit [a0df6fb] Summary: ❌
AI ReviewSummaryThis PR fixes the remaining Final Verdict
|
…ad path too The non-nullable LowCardinality(T) element of Nullable(Tuple(..., LowCardinality(T), ...)) has its extracted subcolumn type promoted to LowCardinality(Nullable(T)) so it can carry the outer tuple's NULLs (fixing the OPTIMIZE FINAL "Sort order of blocks violated" abort). The in-memory column creator promoted the column to match, but the serialization (read) path did not: reading the subcolumn directly from a MergeTree part produced a ColumnLowCardinality with a non-nullable dictionary while its declared type was LowCardinality(Nullable(T)). That (type, column) mismatch made isNull() on the subcolumn abort with "ColumnUnique can't contain null values", and outer-NULL rows leaked the inner dictionary value. Wrap the original (non-nullable) LowCardinality serialization in SerializationNullableWithParentNullMap so the on-disk stream layout is unchanged, and promote the read column to LowCardinality(Nullable(T)) in applyParentNullMapToExtractedSubcolumn before folding in the outer null map. The promotion happens before the no-NULL-rows early-out so the column type stays consistent across all read ranges. Extend the 04338 / 04339 tests to cover reading the subcolumn directly (value + isNull) from both wide and compact parts. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260627-170900 |
|
Pushed The previous revision promoted the subcolumn type to |
CI finish ledger - 7850d59CI is fully finished (Finish Workflow green). Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260627-220000 |
|
Update on the Investigated at full effort. The failure is a transient
The failure precedes any randomized-setting-dependent logic (connection establishment under TSan scheduling pressure), so there is no setting to pin and no test-logic or decimal-conversion defect, and it is not reproducible. No per-test code change is warranted; a fresh run of this job clears it. Closing this line as not actionable. |
Avogar
left a comment
There was a problem hiding this comment.
I would do it differently, let's change canExtractedSubcolumnsBeInsideNullable so it returns true if type is LC and can be transformed to LC(Nullable). And call makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe instead of makeNullableSafe when needed
| if (canExtractedSubcolumnsBeInsideNullable(prev)) | ||
| return makeNullableSafe(prev); | ||
|
|
||
| /// A non-nullable `LowCardinality(T)` cannot be wrapped in `Nullable`, but it must still be able to | ||
| /// represent the outer column's NULLs, so promote it to `LowCardinality(Nullable(T))`. For every other | ||
| /// type this returns `prev` unchanged, matching the previous behaviour. | ||
| return makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe(prev); |
There was a problem hiding this comment.
Why not to use just return makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe(prev), won't it be the same?
There was a problem hiding this comment.
Yes, exactly the same. Done in fc15065.
Address review feedback: create(DataTypePtr) now calls makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe directly. This is exactly equivalent to the previous two-branch form (a promotable non-LC type takes the makeNullableSafe path inside the helper; a non-nullable LowCardinality(T) is promoted to LowCardinality(Nullable(T)); anything else is returned unchanged), just less code. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Simplified On the other part of the suggestion, changing |
…ty elements tupleElement inherited the default LowCardinality implementation, which strips a nested LowCardinality(...) tuple element via recursiveRemoveLowCardinality before extraction. As a result tupleElement(t, 'a') returned String / Nullable(String) while the subcolumn path t.a returned LowCardinality(String) / LowCardinality(Nullable(String)) for the same element, and a LowCardinality(Nullable(String)) element was silently downgraded to Nullable(String). Disable useDefaultImplementationForLowCardinalityColumns for tupleElement so the element type is preserved, and route the Nullable(Tuple(...)) null-map folding through the same helpers as the subcolumn path: makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe for the return type and NullableSubcolumnCreator for the column. This guarantees the (type, column) pair produced by the function matches the subcolumn reader for every element type, including the non-optimized path (materialize(t)). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Done in 236b1ab. Root cause: Fix: disable both New test |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260707-184200 |
The tupleElement consistency refactor routed the Nullable(Tuple(...)) null-map folding through NullableSubcolumnCreator::create for every element type. For an element that can neither be wrapped in Nullable nor carry NULL itself (Map, Array), that helper returns the column unchanged, so outer-NULL rows leaked whatever payload happened to sit under the null map in the hidden nested column instead of reading the element default. Restore explicit default-filling for the non-null-capable / non-LC-promotable case, matching NestedUtils::unwrapNullableTuple and the stored subcolumn, and keep the NullableSubcolumnCreator path (LowCardinality(Nullable) promotion and null-map OR-ing) for element types that can represent NULL. Extend 04344_tuple_element_lowcardinality_consistency with materialize()-forced Map and Array regressions whose hidden payload under outer NULL is non-default. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 46/46 (100.00%) · Uncovered code |
CI finish ledger — a0df6fbCI fully finished (Finish Workflow SUCCESS). Every failure below has an owner (a fixing PR). None PR-caused.
Session id: cron:our-pr-ci-monitor:20260708-023000 |
CI finish ledger — a0df6fb1ea562036089071688bd050e823402aEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260708-030000 |
10a8947
…entation An extracted subcolumn of a Nullable(Tuple(...)) column whose element is a non-nullable LowCardinality(T) has its type promoted to LowCardinality(Nullable(T)) so that it can carry the parent's NULLs. On a Compact part MergeTreeReaderCompact therefore creates the result column already promoted, and SerializationNullableWithParentNullMap built its per-range deserialization buffer from it. The nested SerializationLowCardinality deserializes into that nullable-dictionary buffer and publishes it to the shared substreams cache, so the published substream is not the on-disk LowCardinality(T) representation. A sibling reader of the same streams, that is the parent subcolumn or assumeNotNull() over it, adopts the cached column directly and ends up holding a nullable dictionary under a declared type that is not nullable. Depending on the build that surfaces as wrong values, Code: 49, or an abort on a bad cast. Nothing mutated the published column; it was never the right representation. Build the buffer from the pre-promotion type instead, which NullableSubcolumnCreator still knows and now passes to the wrapper, and let the existing promotion in applyParentNullMapToExtractedSubcolumn promote the private per-range column afterwards. That keeps a single promotion owner and leaves the published substreams in the representation a reader of the parent expects. The new constructor parameter enters getHash() so the two flavours of the wrapper cannot share a pooled instance. Promoting on a private copy at the in-place promotion instead was evaluated and measured to be a no-op: while the buffer is pre-promoted, that code is unreachable, because its guard is !nestedIsNullable(). Wide parts were unaffected, since MergeTreeReaderWide reads each column separately, and so was the getSubcolumn branch taken when write_marks_for_substreams_in_compact_parts is disabled, which already copies. Regression from ClickHouse#108679, which introduced this read path. Affects master and 26.7. Related: ClickHouse#100394
…6-carrier3-nonnullable-lc Fix server abort for non-nullable LowCardinality tuple-element sort key
Related: #105356
Related: #102942
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server abort (
Sort order of blocks violated) during a merge, and incorrect reads, when a non-nullableLowCardinalityelement of aNullable(Tuple(...))column is used as a subcolumn (for example as a sort key).Description
Residual carrier of #105356 that #102942 (merged) does not cover. Carriers 1 (
Nullable(Decimal)) and 2 (LowCardinality(Nullable(String))) are fixed there; a non-nullableLowCardinality(String)element was still mishandled.Repro on current master (debug), git hash
07643905aae, report shape from issue #105356:Such an element reaches
NullableSubcolumnCreator::createas aColumnLowCardinalitywhose dictionary is not nullable, so bothcanExtractedSubcolumnsBeInsideNullableandcanContainNullare false. None of the threecreateoverloads applied the outer tuple null map, so the extracted subcolumn dropped the outer NULLs entirely.The extracted subcolumn type is promoted to
LowCardinality(Nullable(T))so it can represent the outer NULLs. All three creator overloads are now made consistent with that type:create(DataTypePtr)): promote the non-nullableLowCardinality(T)toLowCardinality(Nullable(T))via the existingmakeExtractedSubcolumnsNullableOrLowCardinalityNullableSafe.create(ColumnPtr)): promote the column withcloneNullable()and fold in the outer null map. This fixes the merge abort, where the in-memory sort key was re-extracted and exposed the inner dictionary value for outer-NULLrows, contradicting the on-disk sort key and trippingCheckSortedTransform.create(SerializationPtr)): wrap the original (non-nullable)LowCardinalityserialization inSerializationNullableWithParentNullMap, keeping the on-disk stream layout unchanged.applyParentNullMapToExtractedSubcolumnpromotes the readLowCardinality(T)column toLowCardinality(Nullable(T))(rebuilding the dictionary with a NULL placeholder and remapping indexes) before folding in the outer null map. The promotion runs before the no-NULL-rows early-out so the column type is consistent across all read ranges.Without the read-path part, reading the subcolumn directly from a part (
SELECT c0.2) produced aColumnLowCardinalitywith a non-nullable dictionary while its declared type wasLowCardinality(Nullable(T)):isNull(c0.2)then aborted withColumnUnique can't contain null values, and outer-NULLrows leaked the inner dictionary value instead of readingNULL. With the fix, the subcolumn readsNULLfor outer-NULLrows on both wide and compact parts.Other carriers (
ColumnNullable,LowCardinality(Nullable),Dynamic,Variant) are unchanged. The04338/04339tests are extended to cover reading the subcolumn directly (value andisNull) from both wide and compact parts; both tests fail on master and pass with this change.Follow-up:
tupleElementconsistency (@Avogar review)The same inconsistency existed on the
tupleElementfunction path. It inherited the defaultLowCardinalityimplementation, whoseconvertLowCardinalityColumnsToFull->recursiveRemoveLowCardinalityrecurses into the tuple and strips a nestedLowCardinality(...)element beforegetReturnTypeImpl/executeImplrun. Sot.a(subcolumn) keptLowCardinality(...)whiletupleElement(t, 'a')returnedString/Nullable(String), and aLowCardinality(Nullable(String))element was downgraded toNullable(String):useDefaultImplementationForLowCardinalityColumns()is now disabled fortupleElement, and both its return type and itsNullable(Tuple(...))null-map folding are routed through the same helpers the subcolumn path uses (makeExtractedSubcolumnsNullableOrLowCardinalityNullableSafeandNullableSubcolumnCreator). The function now produces a(type, column)pair identical to the subcolumn reader for every element type. New test04344_tuple_element_lowcardinality_consistencyforces the non-optimized path viamaterialize(t)and asserts type+value equality across the subcolumn path, the optimized function path, and the materialized path (plainLowCardinality,LowCardinality(Nullable),String,Mapelements); it fails on HEAD before this change and passes after.Version info
26.7.1.941(included in26.7and later)