Repository navigation
Conversation
A mutation on a compact part could fail permanently with Unknown expression identifier `h` in scope d, b, h, c, a, d, b, h, c, a and be retried by the background executor for as long as the part and the mutation entry both existed, so the mutation never completed. The compact / dynamic-column / non-full-storage branch of splitAndModifyMutationCommands reconciles the part's columns against the table's. When a part column is absent from both the table metadata and the virtuals, the branch consults the metadata versions to decide whether the column was dropped. That test cannot decide on a plain MergeTree, where both versions are 0 and metadata_version.txt is written, so control fell through and a READ_COLUMN command was emitted for the column anyway. MutateTask builds the interpreter with the table's physical columns as the available set, so that identifier cannot resolve and the analyzer throws. Skip the column instead, which is what the block's own comment already says the compact policy is, what the metadata-version path does when it can decide, and what the wide branch has always done because it iterates the commands rather than the part's columns. The LOGICAL_ERROR for replicated tables is left untouched: on those engines the metadata version is meaningful, so a part column missing from the table is a real bug and the assertion still fires ahead of the new skip. A column that is still in the table metadata is unaffected and keeps being rewritten; the new test covers that as well as both part types. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (click to expand)Two independent reviews were run against this diff before it was pushed: a cold code review Second-model gate: 0 findings. It read Cold review: no blockers, no majors. Three nits, all resolved against measurements rather
Independently verified during the cold review, before reading the implementation notes:
One residual is disclosed rather than folded in: Session id: cron:clickhouse-review-slot-48:20260822-234000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260822-184900 |
|
Workflow [PR], commit [f22d208] Summary: ❌
AI ReviewSummaryThis PR fixes the reported Findings❌ Blockers [src/Storages/MergeTree/MutateTask.cpp:550] Suggested fix: reject Final VerdictStatus: Minimum required actions: close the equal-version stale-rename hole above, or otherwise prove that cloned replicated parts reaching this branch cannot still depend on pending metadata mutations. Add a focused regression test for that carrier. LLVM Coverage ReportMeasured on commit f22d208.
Changed lines: Changed C/C++ lines covered: 20/25 (80.00%) · Uncovered code |
|
cc @alesapin @tiandiwonder, could you review this? The compact-part branch of |
Build profile diff (arm_release)Comparing commit See the job log for details. |
The previous commit skipped reading a part column the table no longer has, but only when the column was not in ignored_columns. MATERIALIZE TTL with ttl_only_drop_parts = 1 pre-populates ignored_columns with every non-mutated part column, so the absent-column test was bypassed and the loop still emitted READ_COLUMN for a dropped column. The mutation then failed UNKNOWN_IDENTIFIER forever, the same way it did before, on the same detach / drop / re-attach shape. The ignored_columns term is dropped from that test. It cannot mask a working read: for a column still present in table metadata the first clause already decides, so the term only ever applied to a column absent from metadata, and such a read cannot resolve at all because the interpreter is built with available_columns = getColumns().getNamesOfPhysical(). The term was moved into this inner condition by 83dcc26 ("correct set of columns on materialize ttl for compact parts when ttl_only_drop_parts=1"), to stop an ignored column being dropped from the new part's column set. That property is unaffected here, because it concerns columns that are still in the metadata. Extends 04880 with a MATERIALIZE TTL case. Verified both directions through clickhouse-test: it fails on the previous commit and passes with this one, with the part type, surviving rows and metadata-absence preconditions all asserted, and the row digest unchanged.
CI finish ledger - 188fa2cCI is fully finished on this head and nothing failed, so no line needs an owner.
Measured at this head: 172 distinct checks, 0 incomplete, 0 failing. The praktika aggregator is This head is the bot change-request fix (the Session id: cron:our-pr-ci-monitor:20260823-090000 |
…read-column-dropped-part-column # Conflicts: # src/Storages/MergeTree/MutateTask.cpp
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.
|
#119354 merged the same Measured on master at
The mechanism is that under a rows-only TTL with The diff is now one line plus a 43-line SQL test. That check was the set's only reader, so the set, the loop that filled it and the parameter gating it are removed with it. The four-arm shell test is gone, since |
…read-column-dropped-part-column
|
Dropping Repro
The guard conflates two opposite cases. This is pre-existing rather than introduced here - tracked as #102153, and Two notes on the test: this PR also repairs plain |
`splitAndModifyMutationCommands` tolerated a part column that the table no longer has only when the part was behind the table's metadata version, or when it carried no metadata version on disk at all. `ATTACH`/`REPLACE PARTITION FROM` and `MOVE PARTITION TO TABLE` stamp the destination's metadata version on a part that keeps the source's `columns.txt` (`metadata_version_to_write` in `executeReplaceRange`, `replacePartitionFromImpl` and `movePartitionToTable`) and require matching structures, so a partition cloned out of a table that had dropped the column arrives with `part_metadata_version == table_metadata_version` and a column that is in no schema at all. That reached the logical error, which is an abort on a debug or sanitizer build, and the `MUTATE_PART` entry replays from Keeper after the restart. The throw is kept for `part_metadata_version > table_metadata_version`, where the replica is behind an `ALTER ADD COLUMN` and the column is real data: that is the case ClickHouse#96008 turned into a logical error and ClickHouse#97301 reverted as "replace LOGICAL_ERROR with potential dataloss", and `ReplicatedMergeTreeQueue` now postpones the mutation before it can get here. The test gains a `ReplicatedMergeTree` arm and a cloned-partition arm, and drops `no-shared-merge-tree`: with the change every arm takes the version comparison, which does not consult `supportsReplication()`. Measured on debug builds, per arm (`MergeTree` / `ReplicatedMergeTree` / cloned by `ATTACH PARTITION FROM`): master @ 45efaa4 FAIL / FAIL / FAIL Code: 47, retried forever this branch, no fix OK / OK / ABORT signal 6, split... -> prepare this branch OK / OK / OK part-vs-table mv 0/0, 1/2, 0/0 Reported on the PR, with the repro and the one-line diff, by Avogar.
|
Folded in, all three, in
Debug builds, per arm: master fails all three with
The description and the changelog entry now state that the equal-version case is accepted for every mutation on this split path, not only |
| /// `ATTACH`/`REPLACE PARTITION FROM` and `MOVE PARTITION TO TABLE` stamp the destination's | ||
| /// version on a part that keeps the source's columns and require matching structures, so | ||
| /// an equal version with the column absent means it is in no schema at all. | ||
| if (part_metadata_version <= table_metadata_version) |
There was a problem hiding this comment.
part_metadata_version <= table_metadata_version is not enough evidence that this extra column was dropped. In replicated ATTACH/REPLACE PARTITION FROM and MOVE PARTITION TO TABLE, cloneAndLoadDataPart rewrites metadata_version.txt on the clone but keeps the source columns.txt (src/Storages/StorageReplicatedMergeTree.cpp, src/Storages/MergeTree/MergeTreeData.cpp); MergeTreeData::loadPartAndFixMetadataImpl already documents why overwriting the version is unsafe for parts detached before schema changes such as RENAME COLUMN (src/Storages/MergeTree/MergeTreeData.cpp).
A concrete carrier is: re-attach in the source table a part that still stores a while the current schema reads it as b through a pending RENAME COLUMN, then ATTACH PARTITION FROM into a fresh replicated table whose current schema also has b. The clone arrives here with part_mv == table_mv, this branch skips a as if it were dropped, and the full rewrite default-fills b because the destination has no rename conversion for it. Before this change that state failed loudly at the LOGICAL_ERROR; with the new <= branch it can silently rewrite the renamed data to defaults.
I think this needs a stronger proof than equal metadata versions, or a guard that refuses ATTACH/REPLACE/MOVE of parts that still depend on pending metadata mutations. A focused regression for the stale-rename carrier would also help pin this down.
There was a problem hiding this comment.
The carrier reproduces, and it does land in a real defect, but not one this change introduces: the destination already answers the renamed column with defaults before any mutation exists, on master too.
Fixture: replicated bc_src(id, a, val, p), partition detached, RENAME COLUMN a TO b, partition re-attached; bc_dst(id, b, val, p) never altered; ATTACH PARTITION 1 FROM bc_src; then ALTER TABLE ... UPDATE val = val + 0 so the guard is reached without MATERIALIZE TTL. Oracle is sum(b) over 10 rows: 10045 means the renamed data survived, 0 means default-filled. Same script, three debug binaries.
master 45efaa4356741 |
this branch without the one-liner | with it | |
|---|---|---|---|
source table reads b |
10045 | 10045 | 10045 |
| clone: part columns, table mv / part mv | ['a','id','p','val'], 0 / 0 |
same | same |
clone reads b, no mutation issued yet |
0 | 0 | 0 |
source table reads b after a mutation on it |
10045 | 10045 | 10045 |
clone reads b after a mutation on it |
abort, signal 6 | abort, signal 6 | 0 |
So the rewrite default-fills nothing. sum(b) on the clone is 0 the moment ATTACH PARTITION FROM returns and it is still 0 afterwards; what the <= branch changes is only that the unreadable a bytes leave the disk instead of the mutation aborting the server. The loud failure was not guarding a value any query could reach, and the carrier is itself one more instance of the abort this change removes.
The < case is not exposed either. In the source table the rename is still an unapplied metadata mutation for that part, so RENAME_COLUMN is in the part's command list and the DROP_COLUMN/RENAME_COLUMN branch of the same helper puts a into mutated_columns, which means the missing-column guard is never reached: the file is renamed and sum(b) stays 10045 (part columns go from ['a', ...] to ['b', ...]). The log carries exactly one Ignoring column line, for the clone, and none for the source.
That is also why a stronger predicate cannot live at this site. By the time the split runs, the part is in a table whose mutation history never saw the rename, so nothing in the destination records that a was ever b; the discriminating information exists only at clone time, where cloneAndLoadDataPart stamps the destination's version over the source's unapplied conversion. So the second half of the suggestion is the right one and the guard belongs on ATTACH/REPLACE/MOVE. #116646 is the same skipped-conversion outcome from a different trigger, a missing metadata_version.txt; it is on the PR as Related: now and I am not fixing it here.
On the focused regression: written against this branch it would have to assert sum(b) = 0, which pins the pre-existing wrong result as expected behaviour. The assertion worth having is 10045, or a refusal at ATTACH PARTITION FROM, and it belongs with the fix at that layer.
CI finish ledger - f22d208Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task CI is fully finished on this head: 176 checks, 155 pass, 18 skipped, 2 failed,
Session id: cron:our-pr-ci-monitor:20260915-190256 |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
307af81
`05210_materialize_ttl_of_attached_part_with_dropped_column`, merged with ClickHouse#115962, clones a partition whose source part carries an unapplied `DROP COLUMN` conversion and asserts that the clone succeeds. The guard added here refused it, so merging master into this branch turned `Fast test` red. An unapplied conversion reaches a reader only through a column the table still has: a `RENAME COLUMN` is read under its new name, which the part does not store, and a `DROP COLUMN` masks the part's stale data for a column of that name. When the column is in neither schema, which is what a partition detached before a plain `DROP COLUMN` and re-attached after it leaves behind, nothing resolves to it and the clone just carries a column no reader asks for. Master already keeps that state on a same-table re-attach (ClickHouse#96351 made it preserve the part's own metadata version), so refusing only its cross-table twin rejected a valid command and contradicted the same-table behaviour. The predicate therefore resolves each column of the table the way a reader resolves it: the rename lookup, the part's own carriers for the name it resolves to, and `isColumnDropped` with the table's `share_nested_offsets`, which decides whether dropping `n` also drops the part's `n.a`. A column skipped by `skip_empty_columns_on_insert` has no files and is read from its marker in `serialization.json`, so it is a carrier as well, and like the reader the guard discards that marker when either the part-time name or the current one was dropped. A part is refused only where that resolution and the destination's plain read of the same name disagree, which is what makes the refusal exactly as wide as the wrong answer it prevents. `CLEAR COLUMN` is a `DROP_COLUMN` carrying `clear`, and a merge writes its defaults without discharging the command, so the refusal names the mutation for it instead of naming OPTIMIZE. Seven cases in the test pin that boundary, each measured to change outcome when the resolution is weakened. Three are refused: a part holding both names of a rename, where the source reads the renamed column and a clone reads the part's own stale one (70 against 10045); a `Nested` parent dropped and re-added, whose shared offsets make the part's subcolumn data stale as well (0 against 45); and a column skipped on insert, then dropped and re-added with a `DEFAULT`, where the source evaluates that default and a clone honours the marker (9990 against 0). Four are cloned: a `DROP COLUMN` whose column is in neither schema, which this guard refused before; a `RENAME COLUMN` of a column the part never stored; a dropped dotted prefix under `share_nested_offsets = 0`; and a marker that the drop of the current name invalidates, where both sides read 5550. A pending `CLEAR COLUMN` gets its own refusal arm. The file also declares the `zookeeper` tag that its `ReplicatedMergeTree` sources need.
Related: #115416
Related: #119354
Related: #102153
Related: #116646
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ALTER TABLE ... MATERIALIZE TTLfailing withUNKNOWN_IDENTIFIERand being retried forever on a table withttl_only_drop_parts = 1when a part still holds a column that the table dropped while that part's partition was detached. Mutating such a partition after cloning it into another table withATTACH PARTITION FROMno longer fails with a logical error either.Description
#119354 merged the same skip for the general case and closed #115416, leaving only the
MATERIALIZE TTLfast path it does not reach.With only a rows TTL and
ttl_only_drop_parts = 1,MATERIALIZE TTLmarked every column it does not rewrite as ignored, and an ignored column skipped the check for columns absent from the table. A partition detached beforeDROP COLUMNand re-attached after it still carries that column, so the split emitted aREAD_COLUMNwhose identifier no longer resolved, and the mutation was retried for as long as the part existed:Dropping that term makes the fast path take the same decision as every other mutation command, which exposed a second case, reported in review (#102153) and folded in here:
ATTACH/REPLACE PARTITION FROMandMOVE PARTITION TO TABLEstamp the destination's metadata version on a part that keeps the source's columns, so a partition cloned out of a table that had dropped the column arrives at the table's own version with a column in no schema at all, which took the logical error in the split and aborted a debug or sanitizer build. Every mutation on this path now treats an equal metadata version like a smaller one; the throw is kept only for a part AHEAD of the table, where the column is real data (#96008, reverted by #97301) and the queue already postpones the mutation.The test has three arms,
MergeTree,ReplicatedMergeTreeand a cloned partition, and dropsno-shared-merge-tree: every arm now takes the version comparison, not the branch that asks whether the storage is replicated. On debug builds master fails all three withUNKNOWN_IDENTIFIER, this branch without the one-line change passes the first two and aborts on the third, and with it all three pass.Workflow [PR]
Sync PR [sync-upstream/pr/115962]
Version info
26.9.1.1602(included in26.9and later)