Repository navigation
Fix logical error reading a whole Tuple subcolumn of Dynamic or Variant from a part - #116739
Conversation
…nt from a part `IDataType::createColumn(const ISerialization &)` builds the read column from the type and then hands it to the serialization. With `allow_nullable_tuple_in_extracted_subcolumns = 1` an extracted whole-`Tuple` subcolumn of a `Dynamic` or `Variant` column is typed `Nullable(Tuple(...))`, so that column is a `ColumnNullable`. `SerializationWrapper::wrapColumnForDeserialization` forwards it unchanged to the nested serialization, so `SerializationTuple::wrapColumnForDeserialization` receives a `ColumnNullable` and its `assert_cast<const ColumnTuple &>` fires: `Bad cast from type DB::ColumnNullable to DB::ColumnTuple`. That forward is wrong for these two wrappers because they own that `Nullable` level themselves. `SerializationVariantElement::deserializeBinaryBulkWithMultipleStreams` peels exactly that level off the result column, fills its null map from the discriminators, and only then recurses into `nested_serialization`. The wrap now mirrors that unwrap. `SerializationDynamicElement` also needs an early return for a null map subcolumn: there the result column is a `ColumnUInt8` read through `SerializationVariantElementNullMap`, `nested_serialization` is not used at all, and the blanket forward produced a second signature, `Bad cast from type DB::ColumnVector<char8_t> to DB::ColumnTuple`. `LowCardinality(Nullable(T))` results stay on the forwarding path on purpose: `isColumnNullable` is false for them and the unwrap side keeps them whole for the same reason. `LowCardinality` cannot hold a `Tuple`, so no non-identity nested serialization can appear under one. Introduced by ClickHouse#111427, commit 8fa5b9b "Deserialize const subcolumns via ISerialization::wrapColumnForDeserialization", which replaced type-driven column construction with serialization-driven construction. Before it the tuple rebuild lived in `DataTypeTuple::createColumn(const ISerialization &)`, a virtual reached only when the type itself was a `Tuple`, so a `Nullable(Tuple(...))` never entered it. Measured: master snapshot 82cfa6a returns the correct values, 19a501b aborts. Rejected alternatives: relaxing the `assert_cast` in `SerializationTuple`, since that class did not add the `Nullable` and tolerating it there would mask every genuine type-against- serialization mismatch for every caller; making `SerializationWrapper`'s default non-forwarding, since forwarding is required by `SerializationNamed`, which is what `SerializationTuple` calls for each element; restoring a type-side `DataTypeNullable::createColumn(const ISerialization &)` virtual, which reintroduces the type-side dispatch ClickHouse#111427 removed. Reachable only with `allow_nullable_tuple_in_extracted_subcolumns = 1`, which is read from the global context and can only be set in a startup profile. The AST fuzzer jobs set it for every run, which is where this surfaced. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review: my own cold pass over the resulting code (3 findings), then one
Severity: ❌ blocker / Also noticed and deliberately not raised: Session id: cron:clickhouse-review-slot-8:20260827-163300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260827-152600 |
|
Workflow [PR], commit [8f3f7df] Summary: ✅
AI ReviewSummaryThis PR fixes a real deserialization mismatch when a whole Final Verdict
LLVM Coverage ReportMeasured on commit 8f3f7df.
Changed lines: Changed C/C++ lines covered: 17/17 (100.00%) · Uncovered code |
|
cc @Avogar @CurtizJ, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units16 translation units recompiled, 40 s compile time in total, 16 of them have a recent master baseline. |
2ea17c3
…column of Dynamic or Variant from a part
Backport #116739 to 26.8: Fix logical error reading a whole Tuple subcolumn of Dynamic or Variant from a part
Both conflicts came from master renaming the dynamic-subcolumn result structure (`res->serialization`/`res->type` -> `res->data.*`, `dynamic_subcolumn_data` -> `dynamic_subcolumn_info->data`). Resolved by keeping this branch's semantics in master's spelling: the ordering in `DataTypeDynamic::getDynamicSubcolumnData` that computes `nullable_added_by_extraction` across the type wrap, and the serialization-before-type creator order in `IDataType::getSubcolumnData`. Master's own `ISerialization::createFromPath` already applies the creator in that same order. ClickHouse#116739 (`8f3f7df0d3150`) landed on master after this branch was last updated, adding `wrapColumnForDeserialization` overrides to `SerializationVariantElement` and `SerializationDynamicElement` that peel the result column's `Nullable` level whenever `isColumnNullable`. This branch makes the matching unwrap in `deserializeBinaryBulkWithMultipleStreams` conditional on `nullable_added_by_extraction`, so the wrap was checked against that flag too. Gating it changes no observable behavior: for an intrinsic `Nullable` the peel hands the nested column to a `SerializationNullable`, which does not override `wrapColumnForDeserialization`, so rebuilding the `ColumnNullable` around it reproduces the input layout. Measured on this tree, 04652, 04653 and 05045 all pass both with the gate and without it. The overrides are therefore left byte-identical to master, and only the comment that described the unwrap as unconditional is corrected. Validation on the merged tree (debug, build id a395d5b3272a6dd9d33e1a4bf2ee5a9ab4766540): 04652, 04653 and master's own 05045 all pass. With the six `src/` files reverted to master (build id ed053ed21015c958), 05045 still passes while 04652 and 04653 fail with `Bad cast from type DB::DataTypeNumber<unsigned int> to DB::DataTypeNullable`, so the fix this branch carries is still load-bearing and is not superseded by anything on master. Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not user-visible; the defect exists only on master.
Description
Related: #111427 (introduced this), #112338.
With
allow_nullable_tuple_in_extracted_subcolumns = 1, reading a wholeTuplesubcolumn of aDynamicorVariantcolumn out of a MergeTree part throwsLOGICAL_ERROR: Bad cast from type DB::ColumnNullable to DB::ColumnTuple:IDataType::createColumn(const ISerialization &)builds the read column from the type, so with thatsetting it is a
ColumnNullable, andSerializationWrapper::wrapColumnForDeserializationforwards it toSerializationTuple, whoseassert_cast<const ColumnTuple &>fires. The forward is wrong forSerializationVariantElementandSerializationDynamicElement, which own that level: theirdeserializeBinaryBulkWithMultipleStreamspeels it off and fills its null map from the discriminators.Both now override the wrap to mirror that unwrap, and
SerializationDynamicElementreturns a null mapsubcolumn untouched, since that one is a
ColumnUInt8read throughSerializationVariantElementNullMapwhere the forward produced a second signature.Introduced on master by #111427; no release branch is affected. In a release build
assert_castis astatic_cast, so the pre-fix behaviour there is undefined (unmeasured). Only a startup profile can setthe setting; the AST fuzzer jobs set it for every run, which is where this surfaced:
report.
The new test covers both types, both part formats, typed and shared variants, a
Nullableelement andthe
.nullsubcolumn; its output matches the pre-regression snapshot byte for byte.Ordering with #112338: it narrows the matching unwrap to
nullable_added_by_extraction && isColumnNullable, so once it lands that bit should gate these two wraps as well. Benign in eitherorder today: the nested wrap is the identity in the intrinsically-nullable case.
#111427 carries
v26.8-must-backportand its backport #116547 is open, so 26.8 would get the regressiontoo. Could a maintainer apply
v26.8-must-backporthere?Workflow [PR]
Sync PR [sync-upstream/pr/116739]
Version info
26.8.3.9