Repository navigation
Fix reading a Nested member after a killed ALTER MODIFY COLUMN mutation - #121561
PedroTadim merged 4 commits into
Conversation
`NameAndTypePair` keeps the type in storage in a private `type_in_storage` field that assigning the public `type` field does not update. `MutationHelpers::getColumnsForNewDataPart` starts from `metadata_snapshot->getColumns().getAllPhysical()`, whose pairs come from the two-argument constructor, and then corrects `type` in place at four sites, so every corrected pair keeps the metadata type in storage while `type` holds the type the new part actually records. `Nested::collect`, through `getSubcolumnsOfNested`, is the only consumer on a part's stored column list that reads `getTypeInStorage()` without first checking `isSubcolumn()`, because it also has to group plain dotted entries. A wide part's reader binds to exactly that collected-Nested description, so after an `ALTER TABLE ... MODIFY COLUMN` on a Nested member whose mutation is killed, plus a later mutation that only hardlinks the column, the reader asks for a `Nullable` element from a part that holds no `.null` stream and `SerializationNullable` reads 2 elements against a 0-element null map. Every other view of the part stays correct because it reads `name` and `type`: `columns.txt`, `system.parts_columns`, the interning key, and all three `IDataType::getSerialization` overloads, which test `isSubcolumn()` first. That is why nothing on disk is wrong, and why a restart, which rebuilds the pairs from `columns.txt` through the two-argument constructor, already returns the right values today. Rebuilding the pair at those four sites restores the invariant the tree already asserts in `NameAndTypePair::setDelimiterAndTypeInStorage`, so the live process agrees with what a restart produces and no currently-correct behaviour changes. All four sites are fixed rather than only the observed one, because the shared column-list interning is keyed on `type` alone, so any desynced list decides the collected view that every later part of the same schema sees. Reproduced on 26.8.2.7 as `Code: 49`, while 26.7.6.57 returns the correct values. Observed in CI as `Stress test (arm_asan_ubsan)` and `Stress test (arm_msan)`. Co-Authored-By: Claude Opus 5 <[email protected]>
The regression test's oracle had two preconditions that the test runner happens to satisfy today but the test itself did not assert, so each was a way for the test to pass without exercising the defect. `MergeTreeData::getSharedPartColumnsForColumns` calls `Nested::collect` only when `share_nested_offsets` is on, and `IMergeTreeReader` converts the requested columns to subcolumns under the same setting. With the setting off the collected-Nested description aliases the raw one, the wrong element type is never built, and every reference row still matched on a binary carrying the defect. The setting is read-only and defaults to on, so the runner cannot turn it off, but a table created with `share_nested_offsets = 0` is legal and the suite already contains one, so pin it in the `CREATE TABLE` where a table-level value also beats any session-level injection. The `part shape` row also held for the original part, which reports the same `Wide` `Full` shape and the same `Array(String)`, so it did not prove the row described the part the `DROP COLUMN` mutation produced. `data_version` is the mutation version when there is one and the minimum block otherwise, so the original reports 1 and the mutated part reports the mutation's version: `data_version > 1` discriminates them without pinning a numbering that is free to change. Measured both ways on the same binary: with the setting at 0 the test passes and matches the reference on a binary that carries the defect, and with it at 1 the same binary aborts with the original message. Skipping the `DROP COLUMN` makes the new witness read 0. Co-Authored-By: Claude Opus 5 <[email protected]>
The regression test claimed a precondition in its header, that the second mutation only hardlinks the column under test, without asserting it anywhere. A mutation that affects no rows takes a different path: it clones the source part with the new part info instead of building a column list, so it never reaches the code under test. Such a clone keeps every file, so it reports the new data version, keeps the member as `Array(String)`, and reloads a column list whose pairs were built by the two-argument constructor, which means every assertion in the test would still pass. `system.parts_columns` enumerates the part's own stored column list, so the dropped member is absent from it exactly when the mutation produced that list, and present when the part was cloned. One row therefore turns the inferred precondition into an asserted one. Measured on one binary: removing the `DROP COLUMN` makes the new row read 1, and every arm that keeps it reads 0. Also give the comment about `share_nested_offsets` its own paragraph, since it is not a third part-shape threshold. Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the clause narrating the rebuild; keep the NameAndTypePair type-in-storage invariant on one line.
Internal second-model review (3 rounds, 2 findings, both fixed before publication)An independent cold review plus a second-model pass in each of three rounds, adjudicated against the measurements. Both findings were test-liveness gaps; the final round raised nothing.
💡 Scope of the fix versus the test. The four rebuilt sites cover every route that leaves a part's declared type behind the table metadata, including the rename and swap variants; the test pins the one scenario observed in CI. The four are fixed together because the shared column-list interning is keyed on the public 💡 Why the producer and not the consumer. 💡 Noted, not changed. Nothing on disk changes: |
|
Workflow [PR], commit [096cc9c] Summary: ✅
AI ReviewSummaryThis PR fixes a real stale-metadata bug in partial wide-part mutations: Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 096cc9c.
Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code |
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, 21 s compile time in total, 7 of them have a recent master baseline. |
|
This also aborts master stress runs with a second signature, STID 3190-56a7: The fuzzer turned the type change in 05292 into Repro on a master debug build (064b09a): CREATE TABLE t (x UInt32, w UInt8, n Nested(a UInt32, y LowCardinality(String))) ENGINE = MergeTree ORDER BY x
SETTINGS min_bytes_for_wide_part = 0, min_rows_for_wide_part = 0, min_bytes_for_full_part_storage = 0;
INSERT INTO t VALUES (1, 1, [10, 20], ['a', 'bb']), (2, 2, [30], ['ccc']);
ALTER TABLE t MODIFY COLUMN `n.a` QBit(Int8, 70) SETTINGS mutations_sync = 0;
KILL MUTATION WHERE database = currentDatabase() AND table = 't' AND NOT is_done SYNC FORMAT Null;
ALTER TABLE t MODIFY COLUMN w UInt16 SETTINGS mutations_sync = 2;
SELECT x, n.a FROM t ORDER BY x; -- Logical error: 'Stream n%2Ea%2E1 for column n.a with type QBit(Int8, 70) is not found' |
d2b0a4b
Closes: #121560
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR(Sizes of nested column and null map of Nullable column are not equal after deserialization) that made aSELECTof aNestedmember fail withCode: 49until the server was restarted, after anALTER TABLE ... MODIFY COLUMNon that member had been killed and a later mutation hardlinked the column into a new wide part.Description
On 26.8.2.7 a valid
SELECTis rejected. After anALTER TABLE ... MODIFY COLUMNretypes the Nested memberarr.ntoArray(Nullable(String))and its mutation is killed, any later mutation that only hardlinks that column leaves a read ofarr.nfailing withCode: 49. 26.7.6.57 returns the correct values, so this is a regression in 26.8. A restart clears it and nothing on disk is wrong.Root cause.
NameAndTypePairkeeps the type in storage in a private field that assigning the publictypefield does not update.MutationHelpers::getColumnsForNewDataPartstarts from the metadata column list and correctstypein place at four sites, so each corrected pair keeps its stale metadata type in storage.Nested::collect, viagetSubcolumnsOfNested, is the only consumer on a part's stored column list that readsgetTypeInStorage()without first checkingisSubcolumn(), because it also has to group plain dotted entries. A wide part's reader binds to exactly that collected-Nested description, so it asks forArray(Nullable(String))from a part that holds no.nullstream.Fix. Rebuild the pair through the two-argument constructor at those four sites instead of assigning the public field. That restores the invariant the tree already asserts in
NameAndTypePair::setDelimiterAndTypeInStorage, and it makes the live process agree with what a restart already produces today, so no currently-correct behaviour changes.CI provenance,
Stress test (arm_asan_ubsan)on my own PR #112088, whose report names the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/31885682218/job/95042650167 . It recurred on 2026-09-22 inStress test (arm_msan): https://github.com/ClickHouse/ClickHouse/actions/runs/35673237760/job/106610246137Workflow [PR]
Sync PR [sync-upstream/pr/121561]
Version info
26.10.1.1445-master(included in26.10and later)