Repository navigation
Fix loss of a lightweight UPDATE made before RENAME COLUMN when a merge runs before the rename's mutation - #124653
Conversation
…ses the rename On ReplicatedMergeTree, a merge writes the merged part at the current metadata version. Every mutations snapshot took its ALTER bound from the base parts only, and ReplicatedMergeTreeQueue::getMutationsSnapshot dropped every ALTER entry at or below that bound. A patch part written before a RENAME COLUMN still stores the old name and needs the rename, but once every base part had passed it the snapshot no longer carried it: reads looked the new name up in the patch and found nothing, and the rename's own MUTATE_PART skipped the patch column, after which the patch was dropped as unused. With apply_patches_on_merge = 1 a merge of parts already at the new version consumed the patch the same way. The snapshot now lowers its ALTER bound by the metadata versions of the patch parts it is applied with: those fetched in getMutationsSnapshot (read path, MutateTask) and the patches of a merge (MergeTask, new Params::min_patch_metadata_version). ALTERs that every base part has passed are kept with their RENAME and DROP COLUMN commands only and are given to a patch only when the patch has not passed them. Patches written before patches carried a metadata version are all at version 0, also those written after the rename (they already store the new name), so for a patch at version 0 the rename applies only if the patch's data predates the rename's mutation version; block numbers of patches and mutation versions come from the same per-partition sequence. Entries above the base bound are handled exactly as before. The test also covers an UPDATE by the old name on a replica that has not applied the rename yet, whose patch carries the metadata version from before the rename. Follow-up of ClickHouse#119144 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Cold review of the diff plus an independent model review (Gate B, 2 rounds, 0 findings).
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261008-133515 |
|
Workflow [PR], commit [95698d3] Summary: ✅
AI ReviewSummaryThis PR fixes a real Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 95698d3.
Changed lines: Changed C/C++ lines covered: 52/52 (100.00%) · Uncovered code |
A merge marks a storage column as expired when no source part stores it and it has no default, and it took the targets of pending renames only from the conversions of the base parts. A column added by ADD COLUMN and filled only by a lightweight UPDATE exists only in the patch, under its old name. Once every base part had passed the following RENAME COLUMN, the new name was marked as expired, so a merge with apply_patches_on_merge = 1 never read the patch and the update was lost. Rename targets are now also taken from the conversions of the patches. Reported by the AI review in ClickHouse#124653 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #119144
Related: #116733
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a lightweight
UPDATEmade beforeALTER TABLE ... RENAME COLUMNon aReplicatedMergeTreetable being lost when a merge ran before the rename's mutation (for example withapply_patches_on_merge = 0): queries returned the old value, and the mutation then dropped the update from disk.Description
On 26.3.42.3, with
apply_patches_on_merge = 0,INSERT (1, 1),UPDATE t SET v = 5,RENAME COLUMN v TO w, thenOPTIMIZE TABLE t FINALbefore the rename'sMUTATE_PARTruns,SELECT wreturns1instead of5, and after the mutationSELECT w ... SETTINGS apply_patch_parts = 0returns1. Follow-up requested in #119144 (comment).A merge writes the part at the current metadata version, and
ReplicatedMergeTreeQueue::getMutationsSnapshotkept only ALTERs above the base parts' lowest metadata version. The patch still storesv, but the snapshot no longer had the rename, so reads lookedwup in the patch and the rename'sMUTATE_PARTskipped the patch column, after which the patch was dropped as unused. The same happens in a merge withapply_patches_on_merge = 1over parts already at the new version.The snapshot now lowers its ALTER bound by the metadata versions of the patch parts it is applied with (
MergeTaskpasses its patches through the newParams::min_patch_metadata_version, and also takes rename targets from them, so a column whose values are only in a patch is not dropped as expired). ALTERs that every base part has passed keep only theirRENAME/DROP COLUMNcommands and go to a patch that has not passed them. Patches written before #119144 are all at metadata version 0, also those written after a rename, so for a version-0 patch the rename applies only if the patch's data predates the rename's mutation version.checkAlterIsPossible(dropped_columns) reads no patches, so it is unchanged.The new test fails on master and passes with the fix (50 randomized runs); it also covers an
UPDATEby the old name on a replica that has not applied the rename yet. Data written by 26.3.42.3 reads correctly after the upgrade; without the version-0 rule itsUPDATEmade after the rename becomes invisible.Workflow [PR]
Sync PR [sync-upstream/pr/124653]
Version info
26.10.1.1985-master(included in26.10and later)