Skip to content

Fix reading a Nested member after a killed ALTER MODIFY COLUMN mutation - #121561

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-mutatetask-stale-type-in-storage-nested-collect
Oct 3, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-mutatetask-stale-type-in-storage-nested-collect

Conversation

@groeneai

@groeneai groeneai commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #121560

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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 a SELECT of a Nested member fail with Code: 49 until the server was restarted, after an ALTER TABLE ... MODIFY COLUMN on 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 SELECT is rejected. After an ALTER TABLE ... MODIFY COLUMN retypes the Nested member arr.n to Array(Nullable(String)) and its mutation is killed, any later mutation that only hardlinks that column leaves a read of arr.n failing with Code: 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. NameAndTypePair keeps the type in storage in a private field that assigning the public type field does not update. MutationHelpers::getColumnsForNewDataPart starts from the metadata column list and corrects type in place at four sites, so each corrected pair keeps its stale metadata type in storage. Nested::collect, via 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 it asks for Array(Nullable(String)) from a part that holds no .null stream.

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 in Stress test (arm_msan): https://github.com/ClickHouse/ClickHouse/actions/runs/35673237760/job/106610246137


Workflow [PR]
Sync PR [sync-upstream/pr/121561]

Version info

  • Merged into: 26.10.1.1445-master (included in 26.10 and later)

groeneai and others added 4 commits September 22, 2026 09:56
`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.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
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.

⚠️ Round 1: the test did not pin the setting its mechanism depends on (AGREED, fixed). The read only reaches the collected-Nested description when share_nested_offsets is on, so with the setting off the test matched its reference while never touching the defective path; the table now pins it and the part row carries a data_version > 1 witness. Two copies of the test differing by that one token, on the same pre-fix binary, give a vacuous pass and an abort.

⚠️ Round 2: nothing asserted that the second mutation had rewritten the part's column list (AGREED, fixed). A mutation that finds no rows affected clones the source part and still receives the new mutation version; that clone path is not reachable for this DROP COLUMN, but the test now asserts the dropped member is absent from system.parts_columns. A control with the DROP COLUMN removed reads 1 where the test reads 0.

💡 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 type alone.

💡 Why the producer and not the consumer. getSubcolumnsOfNested has to read the type in storage for plain dotted entries, so it cannot check isSubcolumn() first, and teaching it to distrust its input would hide any other producer of a desynced pair. The rebuild restores the invariant NameAndTypePair::setDelimiterAndTypeInStorage already asserts and makes the live process agree with what a restart already produces, so no currently-correct behaviour changes.

💡 Noted, not changed. share_nested_offsets is pinned but not asserted, unlike the two part-format axes: it is read-only, is not randomized by the test runner, was measured honoured at CREATE, and the only way to assert it would be to pattern match system.tables.engine_full, which checks the CREATE text rather than the effective value.

Nothing on disk changes: columns.txt and system.parts_columns are written from the public type only, so the existing coverage is untouched and its reference stayed byte-identical.

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [096cc9c]

Summary: ✅


AI Review

Summary

This PR fixes a real stale-metadata bug in partial wide-part mutations: getColumnsForNewDataPart was updating the public NameAndTypePair::type without rebuilding type_in_storage, which left the in-memory part schema inconsistent and let Nested::collect reconstruct a Nested parent with the wrong element type after a killed ALTER TABLE ... MODIFY COLUMN. The four changed sites in MutateTask are the relevant producers of that stored column list, and the new stateless test exercises the reported killed-mutation-plus-hardlink path with the necessary preconditions pinned. I did not find an unresolved correctness, test-liveness, or PR-metadata issue in the current diff.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 096cc9c.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 096cc9cd5 with master f59c98752 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 21 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). label Sep 22, 2026
@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

This also aborts master stress runs with a second signature, STID 3190-56a7: Stream n%2Ea%2E1 for column n.a with type QBit(Int8, 70) is not found in Stress test (azure, amd_msan) on master 35a35bc, 2026-10-02: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=35a35bc242ed2597e37016a924ccea5aea7bea41&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29

The fuzzer turned the type change in 05292 into MODIFY COLUMN n.a QBit(Int8, 70). Its mutation failed and was killed, and the next MODIFY COLUMN n.z Array(String) of the test hardlinked n.a. This time the stale type in storage is not an Array, so getSubcolumnsOfNested skips the member and Nested::collect still drops the plain n.a entry: the wide reader no longer finds n.a in the part and binds it to the metadata type. It is the same-named hardlink site in getColumnsForNewDataPart that this PR rebuilds, so the PR should cover it too.

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'

@PedroTadim PedroTadim self-assigned this Oct 3, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 3, 2026
Merged via the queue into ClickHouse:master with commit d2b0a4b Oct 3, 2026
176 of 177 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

3 participants