Repository navigation
Check column structure against the declared type in collectOffsetsColumns - #114087
Conversation
…umns The type-directed enumerateStreams walk in collectOffsetsColumns pairs each available column's declared type with its data. When an entry's type was resolved from the table's metadata while the column was read from a data part with an older type (the mixed type provenance behind #113925), the walk casts the column to the wrong class at the first diverging wrapper: in debug and sanitizer builds that aborted with a bare 'Bad cast from type A to B' naming no column, and in release builds assert_cast does not check at all, so the walk silently misbehaved on memory-unsafe reinterpretation. The new check descends exactly the wrapper levels whose serializations assert_cast the column (Array, Nullable, Tuple, Map, and class-only Dynamic, Variant, Object), accepts every leaf it does not know (leaf divergence such as a part storing UInt32 for a column widened to UInt64 is legitimate), and reports a LOGICAL_ERROR naming the column, the declared type and the column structure. Debug builds get a one-frame diagnosis instead of a cross-file hunt; release builds now fail close instead of walking mismatched memory. Related: #113925 Related: #113225 Related: #113891 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [09aa43f] Summary: ✅
AI ReviewSummaryThis PR adds a structural preflight check in Final Verdict✅ No new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 47/58 (81.03%) · Uncovered code |
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 units8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline. |
… too `SerializationVariant::enumerateStreams` walks every alternative declared by the type and pairs it with the column's variant of the same global discriminator, and `SerializationObject::enumerateStreams` does the same for every typed path declared by the type. Treating both as class-only therefore left the hole open one frame deeper: a part carrying an older alternative set or an older typed-path shape passed the guard and still reached an unchecked nested `assert_cast`, or failed in the raw typed-path lookup with no indication of the column. `columnMatchesTypeStructure` now validates both recursively, mirroring what `ColumnVariant::structureEquals` and `ColumnObject::structureEquals` check statically: the alternative list has to match in length and element-wise by global discriminator, and the typed paths have to match by name and structure. `Dynamic` stays class-only, because its `enumerateStreams` takes both the type and the column of its variant from the column itself, so the two cannot diverge. False-positive sweep: all 826 stateless `.sql` tests matching `variant`/`dynamic`/`json`/`nested`/`subcolumn`/`object` run against a local `RelWithDebInfo` build with this change - the guard's message and `Bad cast` both appear zero times - plus a targeted check that reads old parts through newly added `Variant`, `JSON`, `Dynamic`, `Tuple`, `Map` and `Nested` columns and through unfinished `ALTER TABLE ... MODIFY COLUMN` mutations of `Variant` and `JSON`.
|
🕵 CI triage for commit 8c6330c — all four failures are unrelated to this change, which touches only
@groeneai, if #113926 is not the right fix for STID 2169-17fd, please take a look at that leak: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114087&sha=8c6330c031f79ee3d8d5bad616369e842f1fd8b6&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 |
|
Yes, #113926 is the right fix for STID 2169-17fd. I reproduced this arm on a master ASAN build and the stack matches the CI report frame for frame: The fix destroys every Nothing extra is needed for this one. |
`SerializationQBit::enumerateStreams` does an unchecked `assert_cast` of both the type to `DataTypeQBit` and the column to `ColumnQBit` before descending into the nested tuple, so `columnMatchesTypeStructure` must not let `QBit` fall through to the unconditional leaf case. Recurse into `ColumnQBit::getTuple` vs `DataTypeQBit::getNestedType`, mirroring the pairing done by the serialization. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 CI triage for commit 173112c — all four failures are unrelated to this change (the PR touches only
The branch has been updated with the latest |
…arse is legitimate The stress test (arm_tsan) on this PR caught a false positive of the new check (STID: 2459-4106): a column of type `Tuple(Nullable(Int32))` whose element is stored sparse was rejected, because the check paired the `Nullable` type with a `ColumnSparse`. The serialization used for the walk is built from the column's own serialization info, so `SerializationSparse::enumerateStreams` pairs the same type with the sparse column's values column - a sparse column at any nesting level is a legitimate pairing and must be unwrapped, like `ColumnReplicated`. Reproduced locally with `nullable_serialization_version = 'allow_sparse'` and a mostly-NULL `Tuple(Nullable(Int32))` element read together with a column missing from the part; added as a stateless test. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114087&sha=e38ab7e6ac7cf673f8e2102a49c7ac58e74c9cd0&name_0=PR&name_1=Stress%20test%20(arm_tsan) PR: #114087 Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 CI triage for commit e38ab7e — one failure was a real false positive of the new check (now fixed), two are unrelated with open trackers:
Also merged |
|
🕵 CI triage for commit 3783f80 — all three failures are unrelated to this change (the PR touches only
@groeneai, investigate the BuzzHouse hang: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114087&sha=3783f809a92ab46f114f112759fecef3788780c7&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29 (job log: https://s3.amazonaws.com/clickhouse-test-reports/PRs/114087/3783f809a92ab46f114f112759fecef3788780c7/buzzhouse_amd_tsan/job.log — hung I merged the current |
|
Two corrections to the BuzzHouse (amd_tsan) reading, then the defect I found. The fuzz phase did not hang. The 18000 s job timeout was spent in teardown, not in fuzzing. The last log line is 17:08:58, which is the first statement of The The plain scan is the older of the two, by 0.08 s. The common factor is The defect: a
The whole catalog walk is therefore uninterruptible: neither a killed client nor an expired time limit can stop it mid-walk. Four sibling system tables already call This is log plus source analysis. I have not reproduced it yet, so I am not opening a PR on a mechanism I cannot demonstrate. I am building the repro (many tables in one database, then cancel a The |
|
First, a correction to my earlier comment here: the Your change is exonerated at code level: the same signature occurs on #107292 Where the 18000 s went: the fuzz pass ended exactly on its 3600 s budget, so exit 143 is a completed budget, not a hang. The remaining 14262 s is Controls: in all five affected runs the rows print and It is recurring and author-independent. Of 223 The fix is already in progress and it is yours: #113248 adds Not explained: why five mutated |
|
🕵 CI triage for commit c6a7348 — both failures are unrelated to this change (the PR touches only
The AI Review on c6a7348 reported ✅ no new findings, and there are no unresolved review threads. I merged the current |
The test did not preserve an old part through ALTER, so it expected a `LOGICAL_ERROR` from a query that correctly succeeds. Remove it while retaining the `LowCardinality` structure validation in `columnMatchesTypeStructure`. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114087&sha=aaf7d9010609fc7572f09e38391d84554e0e0787&name_0=PR&name_1=Fast%20test
Match the tab emitted by 04904_low_cardinality_missing_column_read. #114087
| if (res_columns[i]->isSparse()) | ||
| continue; | ||
|
|
||
| if (!columnMatchesTypeStructure(*res_columns[i], *available_column->type)) |
There was a problem hiding this comment.
Ok. So this is just a diagnostic improvement.
There was a problem hiding this comment.
In debug and sanitizer builds, yes. assert_cast already aborted there, and the new check raises LOGICAL_ERROR, which also aborts (Common/Exception.cpp:112-115), so the only thing that changes is that the message names the column and both structures.
In release builds it is more than diagnostics. assert_cast compiles to a bare static_cast (Common/assert_cast.h:45), so nothing was checked and the walk went on to read ColumnArray::getOffsetsPtr() off a column that is not a ColumnArray (SerializationArray.cpp:280-281). The check throws before the walk starts, so that reinterpretation is now a normal exception.
Related: #113925
Related: #113225
Related: #113891
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
When a column's declared type and its data diverge during a
MergeTreeread (mixed type provenance, e.g. after anALTER TABLE ... MODIFY COLUMNwhose mutation has not finished), the server now reports a clear exception naming the column and both structures, instead of an unchecked cast: debug and sanitizer builds previously aborted with a bareBad cast from type A to Bnaming no column, and release builds walked mismatched memory silently.Description
The type-directed
enumerateStreamswalk incollectOffsetsColumns(src/Interpreters/inplaceBlockConversions.cpp) pairs each available column's declared type with its data. When an entry's type was resolved from the table's metadata while the column was read from a data part with an older type - the mixed type provenance behind #113925 - the walkassert_casts the column to the wrong class at the first diverging wrapper. In debug/sanitizer builds that is an abort whose message names two column classes and no column (the crash-classifier issue #113891, STID 4256-3fc1, took a cross-file hunt to attribute); in release buildsassert_castdoes not check at all, so the walk misbehaves on memory-unsafe reinterpretation.The new
columnMatchesTypeStructurecheck runs right before the walk, only on the missing-columns path where the walk already happens. It descends exactly the levels whose serializations pair the declared type's structure with the column's:Array,Nullable,Tuple,Map- the wrappers whose serializationsassert_castthe column;Variant-SerializationVariant::enumerateStreamswalks every alternative declared by the type and pairs it with the column's variant of the same global discriminator, so the alternative list has to match in length and element-wise;Object-SerializationObject::enumerateStreamswalks every typed path declared by the type and looks it up in the column, so the typed paths have to match by name and structure. Dynamic paths and shared data are taken from the column itself and need no check;ColumnReplicatedis unwrapped.Dynamicis checked by class only, because itsenumerateStreamstakes both the type and the column of its variant from the column itself (column_dynamic->getVariantInfo().variant_type), so the two cannot diverge. Every leaf the check does not know is accepted - leaf divergence, such as a part storingUInt32for a column widened toUInt64, is legitimate. Because the checked structure mirrors exactly what theenumerateStreamsimplementations themselves assert, the check cannot fire on any pairing that debug CI does not already abort on (or, forObject, fail with a raw typed-path lookup) - it only converts that failure into a diagnosable exception and closes the release-build hole.With the #113925 reproducer on a
RelWithDebInfobuild of master before that fix, the witness query fails with:instead of silent unchecked-cast behavior. #113925 (which fixes the type selection) has since merged and is included here, so this check now guards the invariant against future regressions of the same family.
Validation. Witness reproduced as above on a local
RelWithDebInfobuild. False-positive sweep: all 381 stateless tests matchingnested/subcolumnrun against that binary - 294 passed, 87 failed for documented bare-server environmental reasons (no Keeper, no clusters, noprotoc, no/var/lib/clickhouse), and the check's message appears zero times in the whole run. After theVariant/Objectextension, all 826 stateless.sqltests matchingvariant/dynamic/json/nested/subcolumn/objectwere run again - the check's message andBad castboth appear zero times - plus a targeted check that reads old parts through newly addedVariant,JSON,Dynamic,Tuple,MapandNestedcolumns and through unfinishedALTER TABLE ... MODIFY COLUMNmutations ofVariantandJSON. TheMemory-engine caller offillMissingColumnsalways casts columns to the requested types first (tryGetColumnFromBlock), so it cannot trip the check either.🤖 Generated with Claude Code
Version info
26.8.1.1595(included in26.8and later)