Skip to content

Ignore a column absent from the table when mutating a Compact part - #119354

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-mutation-dropped-column-attached-part-115416
Sep 13, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-mutation-dropped-column-attached-part-115416

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

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 to CHANGELOG.md):

Fix a wedged mutation queue after ATTACH PARTITION of a partition that was detached before a DROP COLUMN: mutations of a Compact part carrying the dropped column failed with UNKNOWN_IDENTIFIER and kept failing for every later mutation.

Documentation entry for user-facing changes

...

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. 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 the mutation/attach_partition/detach/drop_column/compact_part/alter_column stateless tests (343 tests) shows no new failures.

Closes: #115416


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

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
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [33db3b5]

Summary: ✅


AI Review

Summary

This PR teaches compact-part mutations on plain MergeTree to ignore an on-disk column that was dropped while the partition was detached, and it adds a regression test for the attach/drop-column reproducer. High-level verdict: the local MergeTree fix looks sound, but the change is still incomplete because the same ENGINE = MergeTree surface is skipped and left broken when Cloud/private runs rewrite it to SharedMergeTree.

Findings

❌ Blockers

  • [tests/queries/0_stateless/05202_mutation_of_attached_part_with_dropped_column.sql:1-5] The PR now skips the exact regression under no-shared-merge-tree, but MergeTree is a user-facing alias for SharedMergeTree in ClickHouse Cloud (src/Storages/MergeTree/registerStorageMergeTree.cpp:4527, tests/clickhouse-test:7483-7486). The note here says the same attach/drop-column reproducer still takes the supportsReplication() LOGICAL_ERROR path in src/Storages/MergeTree/MutateTask.cpp:567-583, so the bug this PR claims to fix remains on a supported ENGINE = MergeTree surface.
    Suggested fix: extend the same ignore-and-rewrite behavior to the SharedMergeTree path, or narrow the claimed contract and avoid skipping the only regression that exercises the Cloud alias.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: fix the SharedMergeTree / Cloud MergeTree alias path, or explicitly narrow the PR so it no longer claims the generic MergeTree case is resolved.

LLVM Coverage Report

Measured on commit 33db3b5.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 5/8 (62.50%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 10, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). label Sep 10, 2026
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
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 33db3b5ea with master e960a0f8f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of c9d36f690; 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, 20 s compile time in total, 7 of them have a recent master baseline.

Job report

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into master with commit 5a49d1b Sep 13, 2026
176 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-mutation-dropped-column-attached-part-115416 branch September 13, 2026 04:31
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 13, 2026
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.
leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). 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

Development

Successfully merging this pull request may close these issues.

Re-attached partition carrying a since-dropped column permanently wedges the mutation queue (UNKNOWN_IDENTIFIER); KILL MUTATION does not recover

2 participants