Repository navigation
Ignore a column absent from the table when mutating a Compact part - #119354
Conversation
A partition detached before `DROP COLUMN` and re-attached after it comes back with a part that still
carries the dropped column on disk. Reads and merges ignore such a column, but every mutation of that
part failed:
Code: 341. Exception happened during execution of mutation 'mutation_4.txt' with part '1_3_3_0'
reason: 'Code: 47. Unknown expression identifier `c`. (UNKNOWN_IDENTIFIER)'
and, because what is poisoned is the part and not the mutation, `KILL MUTATION` did not help: the next
mutation failed identically, so the table's mutation queue stayed wedged, and any client using
`mutations_sync >= 1` got `UNFINISHED`. Only `OPTIMIZE ... FINAL` (a merge rewrites the part) or
dropping the partition recovered, and a partition with no insert traffic never gets merged.
A Compact part cannot leave a column behind, so `splitAndModifyMutationCommands` turns every column of
the part that the mutation does not touch into a `READ_COLUMN` command - including a column the table
no longer has, which the mutation then tries to resolve as an identifier against the table. There is
already a guard for this: if the part's metadata version is behind the table's, the column is logged
and skipped as dropped. A plain `MergeTree` has no metadata versions, so the guard never fires there
(and the `LOGICAL_ERROR` below it is only raised for a replicated table, where the version-based branch
handles the case - the same reproducer on `ReplicatedMergeTree` completes). Skip the column in that case
too and let the rewrite drop it, which is what reads and merges do.
Wide parts were never affected: they take the other branch of `splitAndModifyMutationCommands`, which
rewrites only the columns the mutation touches.
Closes: #115416
|
Workflow [PR], commit [33db3b5] Summary: ✅
AI ReviewSummaryThis PR teaches compact-part mutations on plain Findings❌ Blockers
Final Verdict
LLVM Coverage ReportMeasured on commit 33db3b5.
Changed lines: Changed C/C++ lines covered: 5/8 (62.50%) · Uncovered code |
The part type decides which branch of the mutation command split runs - only a Compact part turns the columns it keeps into `READ_COLUMN` commands - and the test run randomizes `min_bytes_for_wide_part`, so the first table was built as a Wide part and the assertion on the part type failed. Set both `min_bytes_for_wide_part` and `min_rows_for_wide_part` on the table, which wins over the randomized session value. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119354&sha=9194a24319b3033abeb6e0f5f7c45a5e9b6d0d3f&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 #119354
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, 20 s compile time in total, 7 of them have a recent master baseline. |
The fix is reached only when the storage does not support replication - a table with no metadata version to reason with. An engine substituted for `MergeTree` supports replication, so it still takes the branch above, which deliberately throws `LOGICAL_ERROR`, and the test tripped it. Tag it `no-shared-merge-tree`.
| @@ -0,0 +1,67 @@ | |||
| -- Tags: no-shared-merge-tree | |||
There was a problem hiding this comment.
MergeTree is automatically rewritten to SharedMergeTree in Cloud (src/Storages/MergeTree/registerStorageMergeTree.cpp:4527, tests/clickhouse-test:7483-7486), so skipping this case means the reported ENGINE = MergeTree surface is still unfixed there. The note here says the same reproducer still hits the supportsReplication() LOGICAL_ERROR path in splitAndModifyMutationCommands, so the mutation never reaches the new ignore-and-rewrite branch. Can we handle the SharedMergeTree path too instead of hiding it with no-shared-merge-tree?
ClickHouse#119354 landed the same skip for the general case, so all that is left of this PR is the fast path that MATERIALIZE TTL takes. With a rows-only TTL and ttl_only_drop_parts, the command split marked every column it does not rewrite as ignored, and an ignored column bypassed the check for columns the table no longer has, so a partition detached before DROP COLUMN and re-attached after it still wedged the mutation queue through that one command: Code: 341 ... mutation 'mutation_4.txt' with part '1_3_3_0' reason: 'Code: 47 ... Unknown expression identifier `c`. Maybe you meant: ['p']. In scope id, val, p, ts, c, c, ts, p, val, id. (UNKNOWN_IDENTIFIER)' ... (UNFINISHED) Dropping that term takes the decision the other mutation commands already take, including the deliberate logical error on a replicated part whose metadata version does not explain the extra column. ignored_columns had this one reader, so the set, the loop that filled it and the suitable_for_ttl_optimization parameter that gated it are removed as well; the caller keeps its own local for drop_expired_parts. The set was moved into that condition by 83dcc26 to keep the rewritten part's column set correct, which concerns columns the table still has, and those never reach the branch. Measured on master at 5a49d1b, which carries ClickHouse#119354: the new test fails 5/5 without the change and passes 10/10 with it, while 05202 (ClickHouse#119354's own test) and 03285_materialize_ttl_only_drop_parts pass either way. The four-arm shell test is replaced by that single SQL case, because 05202 now covers the compact and wide DELETE/UPDATE arms it used to share.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a wedged mutation queue after
ATTACH PARTITIONof a partition that was detached before aDROP COLUMN: mutations of a Compact part carrying the dropped column failed withUNKNOWN_IDENTIFIERand kept failing for every later mutation.Documentation entry for user-facing changes
...
A partition detached before
DROP COLUMNand re-attached after it comes back with a part that still carries the dropped column on disk. Reads and merges ignore such a column, but every mutation of that part failed:and, because what is poisoned is the part and not the mutation,
KILL MUTATIONdid not help: the next mutation failed identically, so the table's mutation queue stayed wedged and any client usingmutations_sync >= 1gotUNFINISHED. OnlyOPTIMIZE ... FINAL(a merge rewrites the part) or dropping the partition recovered, and a partition with no insert traffic never gets merged.A Compact part cannot leave a column behind, so
splitAndModifyMutationCommandsturns every column of the part that the mutation does not touch into aREAD_COLUMNcommand — including a column the table no longer has, which the mutation then tries to resolve as an identifier against the table. There is already a guard for this: if the part's metadata version is behind the table's, the column is logged and skipped as dropped. A plainMergeTreehas no metadata versions, so the guard never fires there (and theLOGICAL_ERRORbelow it is only raised for a replicated table, where the version-based branch handles the case — the same reproducer onReplicatedMergeTreecompletes). Skip the column in that case too and let the rewrite drop it, which is what reads and merges do.Wide parts were never affected: they take the other branch of
splitAndModifyMutationCommands, which rewrites only the columns the mutation touches. The new test pins both part types.New test:
05202_mutation_of_attached_part_with_dropped_column. Verified in both directions, and a differential run of themutation/attach_partition/detach/drop_column/compact_part/alter_columnstateless tests (343 tests) shows no new failures.Closes: #115416
Workflow [PR]
Sync PR [sync-upstream/pr/119354]