Repository navigation
Reset adopted part level to 0 on cross-engine ATTACH/CLONE/MOVE PARTITION - #107481
alexey-milovidov merged 3 commits into
Conversation
…TION CLONE AS, ATTACH/REPLACE PARTITION FROM and MOVE PARTITION TO TABLE adopt the source part keeping its merge level. A lone part at level > 0 is treated by FINAL and OPTIMIZE as already fully merged, so the row-collapsing transform of ReplacingMergeTree/SummingMergeTree/AggregatingMergeTree is skipped. When the source is a plain MergeTree (no row collapsing on merge), such a part still contains duplicate ORDER BY keys, so the rows survive SELECT ... FINAL and OPTIMIZE TABLE ... FINAL (issue ClickHouse#106798). Reset the adopted part's level to 0 when the destination merge mode differs from the source's. The destination then re-merges the part under its own collapsing semantics on the next FINAL/OPTIMIZE. Same-engine adoption keeps the level unchanged, preserving the existing optimize_on_insert behavior (test 03283_optimize_on_insert_level) and avoiding a pointless re-merge. The reset is applied at the four part-adoption sites in StorageMergeTree and StorageReplicatedMergeTree (replace and move partition) via a shared helper. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260615-074100 |
|
cc @alesapin @CurtizJ — could you review? Resets an adopted part's merge level to 0 when source and destination engines differ (CLONE AS / ATTACH / MOVE PARTITION FROM a plain MergeTree into RMT/SMT/AMT), so FINAL/OPTIMIZE deduplicate it instead of skipping the lone level>0 part. Implements the approach tuanpach picked on #106798. |
|
Workflow [PR], commit [b4c29e4] Summary: ✅
AI ReviewSummaryThe PR fixes adopted Final VerdictStatus: ✅ Approve |
The previous commit reset an adopted part's level only when the merge mode differed between source and destination. checkStructureAndGetMergeTreeData does not compare MergingParams, so two same-mode tables can still differ in semantic fields that feed the merge transforms (sign_column, is_deleted_column, columns_to_sum, version_column, allow_tuple_element_aggregation, graphite_params). ATTACH PARTITION FROM between e.g. two SummingMergeTree tables with different columns_to_sum then kept a level>0 source part that the destination treats as already-merged under its own columns_to_sum, so FINAL/OPTIMIZE leave rows that should have been summed or dropped. Preserve the source level only when the full merge semantics match (new MergingParams::hasSameMergeSemantics), and reset to 0 otherwise. Resetting is always safe: it makes the destination re-merge the lone part under its own semantics. Same-engine same-params attach is unchanged, so the optimize_on_insert signal (03283_optimize_on_insert_level) and a pointless re-merge are both avoided. Adds operator== for Graphite::Params (used by the comparison) and same-mode/ different-params regression cases (SummingMergeTree differing columns_to_sum, ReplacingMergeTree differing is_deleted_column). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (commit d3f9030 — full merge semantics)
Session id: cron:clickhouse-worker-slot-2:20260615-092500 |
Pattern::operator== compared only function->getName(), but Pattern::updateHash hashes both the name and function->getParameters(). Two GraphiteMergeTree configs with the same aggregate function name but different parameters (e.g. quantile(0.5) vs quantile(0.9)) therefore compared equal, so MergingParams::hasSameMergeSemantics would treat them as identical. A level>0 part adopted via ATTACH PARTITION FROM / CLONE AS between such tables would keep its merge level and the destination would skip the rollup under its own parameters (follow-up to issue ClickHouse#106798). Compare getParameters() too, keeping operator== in lockstep with updateHash, and add a GraphiteTest unit case covering same-name/different-parameters. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (follow-up: Graphite Pattern::operator== / commit b4c29e4)
Session id: cron:clickhouse-worker-slot-2:20260615-105600 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 63/67 (94.03%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 18 line(s) · Uncovered code |
|
CI fully finished on HEAD Session: cron:our-pr-ci-monitor:20260615-160000 |
…use#107551) Add a new DDL to change a MergeTree-family table's engine in place, e.g. plain MergeTree -> ReplacingMergeTree / SummingMergeTree / CollapsingMergeTree / VersionedCollapsingMergeTree / AggregatingMergeTree / GraphiteMergeTree. Only the merge semantics (MergingParams) change; ORDER BY / PARTITION BY / PRIMARY KEY / SAMPLE BY / columns are untouched. Syntax: ALTER TABLE t MODIFY ENGINE = ReplacingMergeTree(version). A required column for the target engine (Collapsing sign, VersionedCollapsing sign+version) may be added in the same statement, before the MODIFY ENGINE command: ALTER TABLE t ADD COLUMN sign Int8, MODIFY ENGINE = CollapsingMergeTree(sign). Gated behind the experimental setting allow_experimental_alter_modify_engine. The new engine must be the same replication kind and a MergeTree-family engine; the resulting MergingParams is validated against the columns. The new ENGINE clause is persisted into the table's CREATE query; the new merge semantics take effect when the storage is next constructed (DETACH/ATTACH or restart). A safe immediate live swap of the read-lock-free merging_params (via MultiVersion or storage recreation) and the coordinated Replicated*MergeTree path are follow-ups; Replicated tables are rejected for now. Reuses the part-level-reset rationale of ClickHouse#107481 conceptually (existing parts keep their data and re-merge under the new semantics on FINAL/OPTIMIZE). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…use#107551) Add a new DDL to change a MergeTree-family table's engine in place, e.g. plain MergeTree -> ReplacingMergeTree / SummingMergeTree / CollapsingMergeTree / VersionedCollapsingMergeTree / AggregatingMergeTree / GraphiteMergeTree. Only the merge semantics (MergingParams) change; ORDER BY / PARTITION BY / PRIMARY KEY / SAMPLE BY / columns are untouched. Syntax: ALTER TABLE t MODIFY ENGINE = ReplacingMergeTree(version). A required column for the target engine (Collapsing sign, VersionedCollapsing sign+version) may be added in the same statement, before the MODIFY ENGINE command: ALTER TABLE t ADD COLUMN sign Int8, MODIFY ENGINE = CollapsingMergeTree(sign). Gated behind the experimental setting allow_experimental_alter_modify_engine. The new engine must be the same replication kind and a MergeTree-family engine; the resulting MergingParams is validated against the columns. The new ENGINE clause is persisted into the table's CREATE query; the new merge semantics take effect when the storage is next constructed (DETACH/ATTACH or restart). A safe immediate live swap of the read-lock-free merging_params (via MultiVersion or storage recreation) and the coordinated Replicated*MergeTree path are follow-ups; Replicated tables are rejected for now. Reuses the part-level-reset rationale of ClickHouse#107481 conceptually (existing parts keep their data and re-merge under the new semantics on FINAL/OPTIMIZE). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…use#107551) Add a new DDL to change a MergeTree-family table's engine in place, e.g. plain MergeTree -> ReplacingMergeTree / SummingMergeTree / CollapsingMergeTree / VersionedCollapsingMergeTree / AggregatingMergeTree / GraphiteMergeTree. Only the merge semantics (MergingParams) change; ORDER BY / PARTITION BY / PRIMARY KEY / SAMPLE BY / columns are untouched. Syntax: ALTER TABLE t MODIFY ENGINE = ReplacingMergeTree(version). A required column for the target engine (Collapsing sign, VersionedCollapsing sign+version) may be added in the same statement, before the MODIFY ENGINE command: ALTER TABLE t ADD COLUMN sign Int8, MODIFY ENGINE = CollapsingMergeTree(sign). Gated behind the experimental setting allow_experimental_alter_modify_engine. The new engine must be the same replication kind and a MergeTree-family engine; the resulting MergingParams is validated against the columns. The new ENGINE clause is persisted into the table's CREATE query; the new merge semantics take effect when the storage is next constructed (DETACH/ATTACH or restart). A safe immediate live swap of the read-lock-free merging_params (via MultiVersion or storage recreation) and the coordinated Replicated*MergeTree path are follow-ups; Replicated tables are rejected for now. Reuses the part-level-reset rationale of ClickHouse#107481 conceptually (existing parts keep their data and re-merge under the new semantics on FINAL/OPTIMIZE). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…use#107551) Add a new DDL to change a MergeTree-family table's engine in place, e.g. plain MergeTree -> ReplacingMergeTree / SummingMergeTree / CollapsingMergeTree / VersionedCollapsingMergeTree / AggregatingMergeTree / GraphiteMergeTree. Only the merge semantics (MergingParams) change; ORDER BY / PARTITION BY / PRIMARY KEY / SAMPLE BY / columns are untouched. Syntax: ALTER TABLE t MODIFY ENGINE = ReplacingMergeTree(version). A required column for the target engine (Collapsing sign, VersionedCollapsing sign+version) may be added in the same statement, before the MODIFY ENGINE command: ALTER TABLE t ADD COLUMN sign Int8, MODIFY ENGINE = CollapsingMergeTree(sign). Gated behind the experimental setting allow_experimental_alter_modify_engine. The new engine must be the same replication kind and a MergeTree-family engine; the resulting MergingParams is validated against the columns. The new ENGINE clause is persisted into the table's CREATE query; the new merge semantics take effect when the storage is next constructed (DETACH/ATTACH or restart). A safe immediate live swap of the read-lock-free merging_params (via MultiVersion or storage recreation) and the coordinated Replicated*MergeTree path are follow-ups; Replicated tables are rejected for now. Reuses the part-level-reset rationale of ClickHouse#107481 conceptually (existing parts keep their data and re-merge under the new semantics on FINAL/OPTIMIZE). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ison `MergingParams::allow_tuple_element_aggregation` was added on master by a separate Graphite PR that was not backported to this release branch, so the `hasSameMergeSemantics` comparison introduced by #107481 fails to compile here. Remove the comparison; the tuple-element-aggregation feature does not exist on this branch. Build failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110339&sha=df86ad95c545d0abe100a8a254dca04827cdcab4&name_0=BackportPR&name_1=Build%20%28amd_debug%29 Backport of #107481 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ison `MergingParams::allow_tuple_element_aggregation` was added on master by a separate Graphite PR that was not backported to this release branch, so the `hasSameMergeSemantics` comparison introduced by #107481 fails to compile here. Remove the comparison; the tuple-element-aggregation feature does not exist on this branch. Build failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110340&sha=b26cdd397e69be9461ba1611c22b492163a8b73f&name_0=BackportPR&name_1=Build%20%28amd_debug%29 Backport of #107481 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ison `MergingParams::allow_tuple_element_aggregation` was added on master by a separate Graphite PR that was not backported to this release branch, so the `hasSameMergeSemantics` comparison introduced by #107481 fails to compile here. Remove the comparison; the tuple-element-aggregation feature does not exist on this branch. Build failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110341&sha=eba67bc76fc4cca6ecc2baf858cd80d453796adb&name_0=BackportPR&name_1=Build%20%28amd_debug%29 Backport of #107481 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Backport #107481 to 26.4: Reset adopted part level to 0 on cross-engine ATTACH/CLONE/MOVE PARTITION
Backport #107481 to 26.5: Reset adopted part level to 0 on cross-engine ATTACH/CLONE/MOVE PARTITION
Backport #107481 to 26.3: Reset adopted part level to 0 on cross-engine ATTACH/CLONE/MOVE PARTITION
…cross-engine ATTACH/CLONE/MOVE PARTITION
…cross-engine ATTACH/CLONE/MOVE PARTITION
…cross-engine ATTACH/CLONE/MOVE PARTITION
Closes: #106798
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
SELECT ... FINALandOPTIMIZE TABLE ... FINALreturning duplicate rows afterCREATE TABLE ... CLONE AS,ATTACH PARTITION ... FROMorMOVE PARTITION ... TO TABLEadopted parts from a plainMergeTreeinto aReplacingMergeTree,SummingMergeTreeorAggregatingMergeTree. The adopted part's merge level is now reset to 0 when the source and destination engines differ, so the destination deduplicates it on the next merge.Description
A part adopted via
CLONE AS,ATTACH/REPLACE PARTITION ... FROMorMOVE PARTITION ... TO TABLEkept the source part's merge level. A lone part at level greater than 0 is treated byFINAL/OPTIMIZEas already fully merged, so the row-collapsing transform ofReplacingMergeTree/SummingMergeTree/AggregatingMergeTreeis skipped. When the source is a plainMergeTree(no row collapsing on merge), such a part still holds duplicate ORDER BY keys, so they survivedSELECT ... FINALandOPTIMIZE TABLE ... FINAL.The fix resets the adopted part's level to 0 when the destination merge mode differs from the source's, so the destination re-merges the part under its own semantics. Same-engine adoption keeps the level unchanged, preserving the existing
optimize_on_insertbehavior (test03283_optimize_on_insert_level) and avoiding a pointless re-merge. Applied at the four part-adoption sites inStorageMergeTreeandStorageReplicatedMergeTree(replace and move partition) through a shared helper.This implements the approach picked by tuanpach in the issue discussion (reset level to 0 only when source and target engines differ).
Reproduction (now returns 1 on patched server, returned 2 before):
Version info
26.6.1.835(included in26.6and later)26.5.6.40,26.4.5.127,26.3.17.44