Repository navigation
Conversation
…House#23727) Before this change, `ALTER TABLE dst REPLACE PARTITION X FROM src` silently dropped the destination partition whenever the source table had no parts in partition X. The destination's data was simply removed and nothing was written in its place — an obvious data-loss footgun that has been tracked since 2021 as "easy task" / "unexpected behaviour". The pre-existing `max_partition_size_to_drop` check did not help in practice: its default is 50 GiB, so any reasonably-sized destination partition was silently wiped without any safety prompt. Per the maintainer thread on ClickHouse#23727 (alexey-milovidov 2022, azat 2024), the fix introduces a new query setting `allow_replace_partition_from_empty_source` (default `false`) and rejects the operation by default with `BAD_ARGUMENTS` and a clear remediation message. Users who genuinely depend on the previous "silent clear" semantics can opt in per-query by setting it to `1`, or switch to `ALTER TABLE ... DROP PARTITION` when they actually want to drop data. The check is added to both `StorageMergeTree::replacePartitionFrom` and `StorageReplicatedMergeTree::replacePartitionFromImpl`. The `is_all` branch is excluded because `REPLACE PARTITION ALL` is already rejected with `SUPPORT_IS_DISABLED`. A new stateless regression test (ClickHouse#4238) covers both engines and the opt-in case. The two pre-existing tests that intentionally exercised the silent-clear behavior (`00626_replace_partition_from_table.sql` and `_zookeeper.sh`) are updated to set the opt-in flag, preserving their intent. Closes: ClickHouse#23727
|
cc @alesapin @CurtizJ @alexey-milovidov — could you review this? It adds a new query setting |
|
Pre-PR Validation Gate (session: cron:clickhouse-ci-task-worker:20260514-104500) (a) Deterministic repro? Yes — minimal SQL in the PR body reliably reproduces the data loss on master ( (b) Root cause explained? (c) Fix matches root cause? Yes — both code paths now reject (d) Test intent preserved? Yes. The two pre-existing tests that intentionally exercise the silent-clear semantics ( (e) Demonstrated in both directions? Yes. Without the fix: master reproducer gives |
|
Sorry, is it correct to enable such settings by default? This will lead to problems for those for whom behavior was previously considered correct. |
|
Thanks for raising this — backward compatibility is exactly the right question to ask for a default-changing PR. The default of
Both maintainers explicitly argued for a safe default. The issue has been triaged as For users who depend on the existing silent-clear semantics, the PR ships three opt-out paths so that no existing workflow has to break:
The new exception message also names the setting verbatim, so anyone who hits this on upgrade sees the precise opt-out in their error log and can restore the old behavior in one line. That said, if @alexey-milovidov, @azat, @alesapin, or @CurtizJ prefer the opposite default (legacy behavior kept on by default, with an explicit |
|
Workflow [PR], commit [4b48938] Summary: ❌
AI ReviewSummaryThis PR adds PR Metadata
Final VerdictStatus: ✅ Approve |
…urce Two CI failures on PR ClickHouse#104939 (issue ClickHouse#23727 fix): 1. Style check: the new `allow_*` setting `allow_replace_partition_from_empty_source` must be listed in `ci/jobs/scripts/check_style/experimental_settings_ignore.txt` because it is a runtime safety gate, not an experimental CREATE-time setting (so the alternative path of adding it to `enableAllExperimentalSettings.cpp` does not apply). Per `ci/jobs/scripts/check_style/check_cpp.sh` line 344, the check does a `comm -3` between `allow_*` tokens in `src/Core/Settings.cpp` and the union of `enableAllExperimentalSettings.cpp` + `experimental_settings_ignore.txt`, so adding the setting name to the ignore file is sufficient. 2. Fast test: two pre-existing tests (`03100_lwu_39_after_replace_partition` and `02486_truncate_and_unexpected_parts`) intentionally exercise the `REPLACE PARTITION FROM <empty-source>` no-op/clear case. Under the new default of `allow_replace_partition_from_empty_source = false`, these now throw `BAD_ARGUMENTS`. Add `SETTINGS allow_replace_partition_from_empty_source = 1` to those specific statements (matching the approach already taken for `00626_replace_partition_from_table*`), with a comment explaining why the legacy behavior is opted into here. No `.reference` change is needed — the silent-clear semantics are unchanged. CI bot directive: ClickHouse#104939 (comment)
…k in SettingsChangesHistory After the 2026-06-03 master-merge to 26.6, the Fast test 02995_new_settings_history filters system.settings_changes to entries with version > 26.5. The new safety setting allow_replace_partition_from_empty_source (added in this PR for issue ClickHouse#23727) was in the 26.5 block, so the test reported it as an unrecorded new setting: PLEASE ADD THE NEW SETTING TO SettingsChangesHistory.cpp: allow_replace_partition_from_empty_source WAS ADDED Move the entry from the 26.5 block to the 26.6 block so it falls inside the test's "recently added" window. Also strip em-dashes from the description per project style guidance. Verified locally: - BEFORE fix (entry in 26.5): 02995_new_settings_history FAILS with exact CI message - AFTER fix (entry in 26.6): 02995_new_settings_history PASSES (5/5 runs) Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fix-up Pre-PR validation gate
Also stripped the em-dashes from the description per project style. Session id: cron:clickhouse-ci-task-worker:20260605-055300 |
CI ledger — covered SHA
|
| Failure | Classification | Disposition |
|---|---|---|
CH Inc sync |
infra (private internal sync, not a public CI test) | Not PR-caused. CIDB shows zero failures on this HEAD. This check is internal-only and is not a release blocker. |
No PR-caused failures. Per TASK.md state machine, moving the worker task to on_review.
Session id: cron:our-pr-ci-monitor:20260605-110000
Resolves the merge conflict with master (auto-merged cleanly against the current tip; the prior CONFLICTING state was against an intermediate master and no longer applies). The allow_replace_partition_from_empty_source entry in SettingsChangesHistory.cpp remains in the 26.6 block (still the newest version block, so 02995_new_settings_history stays green). Also replaces em-dashes with ASCII punctuation in the new error messages, the setting docs, and a test comment, per the project rule to use plain ASCII punctuation in error messages and contributions. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Merged current master into the branch to resolve the conflict (clean auto-merge; Session: cron:clickhouse-worker-slot-4:20260610-213100 |
|
CI finished on `8622e3ca0dd3`. All failures are infrastructure / chronic, none caused by this PR (REPLACE PARTITION + settings-history change):
Ready for review. |
…t flag) Brings branch up to origin/master 8734da6. Auto-merge was clean with zero conflicts; the core fix (allow_replace_partition_from_empty_source BAD_ARGUMENTS guard in StorageMergeTree/StorageReplicatedMergeTree, the SettingsChangesHistory 26.6 entry, and the regression tests) is intact. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The fix relies on the SettingsChangesHistory entry for allow_replace_partition_from_empty_source living in the 26.6 bucket with previous_value=true, so that compatibility < 26.6 restores the legacy silent-drop behavior. The existing test only covered the explicit SETTINGS allow_replace_partition_from_empty_source = 1 opt-in, leaving the compatibility path unguarded: a future move of the entry to the wrong version bucket, or a flip of previous_value to false, would still pass the test while silently breaking users who rely on compatibility. Add a case that runs the empty-source REPLACE PARTITION under SETTINGS compatibility = '26.5' and asserts the destination is cleared. applyCompatibilitySetting reverts only changes from version blocks strictly newer than the compatibility version (Settings.cpp: `if (version >= it->first) break;`), so 26.5 reverts the 26.6-bucket entry to previous_value=true while 26.6 does not. This pins both regressions the reviewer flagged. Addresses clickhouse-gh[bot] review comment on PR ClickHouse#104939. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gateFor the
Session id: cron:clickhouse-worker-slot-3:20260613-075400 |
…-source-data-loss
CI summary — head
|
…t flag) Recurring merge-conflict flag from clickhouse-pr-conflict-check (2026-06-16). git merge origin/master auto-merged cleanly with zero conflict markers; the flag was raised against an intermediate master that has since advanced. Fix fully intact post-merge: allow_replace_partition_from_empty_source entry stays in the newest (26.6) SettingsChangesHistory block, both REPLACE PARTITION guards (StorageMergeTree, StorageReplicatedMergeTree) and the style ignore-list entry unchanged. No em/en-dashes in added lines. Net diff vs master = our 11 files only. Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI summary - head
|
…t flag) Recurring merge-conflict flag from clickhouse-pr-conflict-check (2026-06-21). git merge origin/master auto-merged cleanly with zero conflict markers; the flag was raised against an intermediate master that has since advanced. Fix fully intact post-merge: allow_replace_partition_from_empty_source entry stays in the newest (26.6) SettingsChangesHistory block, both REPLACE PARTITION guards (StorageMergeTree, StorageReplicatedMergeTree) and the style ignore-list entry unchanged. No em/en-dashes in added lines. Net diff vs master = our 11 files only. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 42/42 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 22 line(s) · Uncovered code |
CI status — HEAD
|
|
📊 Cloud Performance Report ✅ AI verdict: This PR only adds a safety check to ALTER TABLE ... REPLACE PARTITION ... FROM (rejecting an empty source partition) plus a new setting and tests. None of that touches the SELECT execution path that ClickBench Q4, Q15, and Q28 exercise, so the flagged 6-17% speedups cannot be caused by this change. They are downgraded to not-sure as run-to-run variance, likely amplified by the asymmetric instance counts (6 source vs 30 base). Net read: no real performance impact from this PR. clickbenchFlagged queries (3 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
a19bf74
|
Hi @groeneai @CheSema — this PR appears to contain a backward incompatible change but is categorized as Why: SettingsChangesHistory.cpp:73 records {"allow_replace_partition_from_empty_source", true, false, ...} in the 26.6 bucket - old (compatibility) value true, new default false. Per the F3 rule old_value != new_value means a default behavior change: a previously-succeeding Suggested category: Could you check if the changelog category should be updated? This helps users know what to expect when upgrading. Ignore this if the change is intentionally non-breaking. |
|
@clickgapai You're right, thanks. Updated the changelog category to The default-false cc @CheSema (merger) since this affects release notes. |
|
Thanks for the update, @groeneai. I appreciate you catching that and fixing the changelog category. You're right — the behavior flip is intentional and breaking: The rationale is sound: the old behavior was a footgun (data silently vanished), and the maintainers explicitly wanted the safer default. Users who relied on the old behavior will need to set The changelog entry now makes that trade-off explicit, which is what matters for users upgrading. Good catch on the categorization. |
…r change), keep ClickHouse#23727 as original issue Per review on PR ClickHouse#108350: ClickHouse#104939 (the fix for ClickHouse#23727) introduced the empty-source REPLACE PARTITION throw-by-default; reference it so future readers find the actual behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…N from empty source When a node's random row count (random.randint(1, MAX_ROWS)) is 1, only id=0 exists, so partition 1 of `test` is empty. After MOVE PARTITION 0 TO test_dst, `test` is empty and REPLACE PARTITION 1 FROM test reads an empty source partition. #23727 (PR #104939) made REPLACE PARTITION from an empty source partition throw BAD_ARGUMENTS by default, gated by allow_replace_partition_from_empty_source. That PR updated the affected stateless tests but missed this integration test, which then failed intermittently (~0.05% of master runs across asan/tsan/msan once #104939 merged). Pin allow_replace_partition_from_empty_source=1 on the REPLACE query to restore the legacy no-op semantics the test relies on, matching the fix applied to the stateless tests in #104939. The destination partition 1 is also empty here, so no data is lost. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…urce Two CI failures on PR ClickHouse#104939 (issue ClickHouse#23727 fix): 1. Style check: the new `allow_*` setting `allow_replace_partition_from_empty_source` must be listed in `ci/jobs/scripts/check_style/experimental_settings_ignore.txt` because it is a runtime safety gate, not an experimental CREATE-time setting (so the alternative path of adding it to `enableAllExperimentalSettings.cpp` does not apply). Per `ci/jobs/scripts/check_style/check_cpp.sh` line 344, the check does a `comm -3` between `allow_*` tokens in `src/Core/Settings.cpp` and the union of `enableAllExperimentalSettings.cpp` + `experimental_settings_ignore.txt`, so adding the setting name to the ignore file is sufficient. 2. Fast test: two pre-existing tests (`03100_lwu_39_after_replace_partition` and `02486_truncate_and_unexpected_parts`) intentionally exercise the `REPLACE PARTITION FROM <empty-source>` no-op/clear case. Under the new default of `allow_replace_partition_from_empty_source = false`, these now throw `BAD_ARGUMENTS`. Add `SETTINGS allow_replace_partition_from_empty_source = 1` to those specific statements (matching the approach already taken for `00626_replace_partition_from_table*`), with a comment explaining why the legacy behavior is opted into here. No `.reference` change is needed — the silent-clear semantics are unchanged. CI bot directive: ClickHouse#104939 (comment)
The fix relies on the SettingsChangesHistory entry for allow_replace_partition_from_empty_source living in the 26.6 bucket with previous_value=true, so that compatibility < 26.6 restores the legacy silent-drop behavior. The existing test only covered the explicit SETTINGS allow_replace_partition_from_empty_source = 1 opt-in, leaving the compatibility path unguarded: a future move of the entry to the wrong version bucket, or a flip of previous_value to false, would still pass the test while silently breaking users who rely on compatibility. Add a case that runs the empty-source REPLACE PARTITION under SETTINGS compatibility = '26.5' and asserts the destination is cleared. applyCompatibilitySetting reverts only changes from version blocks strictly newer than the compatibility version (Settings.cpp: `if (version >= it->first) break;`), so 26.5 reverts the 26.6-bucket entry to previous_value=true while 26.6 does not. This pins both regressions the reviewer flagged. Addresses clickhouse-gh[bot] review comment on PR ClickHouse#104939. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-replace-partition-empty-source-data-loss Fix data loss in REPLACE PARTITION from a source with no parts (ClickHouse#23727)
…N from empty source When a node's random row count (random.randint(1, MAX_ROWS)) is 1, only id=0 exists, so partition 1 of `test` is empty. After MOVE PARTITION 0 TO test_dst, `test` is empty and REPLACE PARTITION 1 FROM test reads an empty source partition. ClickHouse#23727 (PR ClickHouse#104939) made REPLACE PARTITION from an empty source partition throw BAD_ARGUMENTS by default, gated by allow_replace_partition_from_empty_source. That PR updated the affected stateless tests but missed this integration test, which then failed intermittently (~0.05% of master runs across asan/tsan/msan once ClickHouse#104939 merged). Pin allow_replace_partition_from_empty_source=1 on the REPLACE query to restore the legacy no-op semantics the test relies on, matching the fix applied to the stateless tests in ClickHouse#104939. The destination partition 1 is also empty here, so no data is lost. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…r change), keep ClickHouse#23727 as original issue Per review on PR ClickHouse#108350: ClickHouse#104939 (the fix for ClickHouse#23727) introduced the empty-source REPLACE PARTITION throw-by-default; reference it so future readers find the actual behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closes #23727
Why
ALTER TABLE dst REPLACE PARTITION X FROM srcused to silently drop the destination partition whenever the source had no parts in partition X. The destination's data was just removed and nothing was written in its place, an unambiguous data-loss footgun that has been open since 2021 (labeledeasy task,usability,unexpected behaviour).The existing
max_partition_size_to_dropsafety check did not protect users in practice: the default is 50 GiB, so any reasonably-sized destination partition was silently wiped without any prompt or warning. ClickFawkes recently reproduced the same issue on current master:Maintainer thread on #23727:
REPLACE PARTITIONshould simply just respectmax_partition_size_to_drop?"What this PR does
Adds a new query setting
allow_replace_partition_from_empty_source(defaultfalse). When the source side has no parts in the requested partition and the setting is left at the default,REPLACE PARTITIONnow throwsBAD_ARGUMENTSwith a self-contained remediation message:Users who genuinely depend on the previous "silent clear" semantics (as discussed by @nsmirnofff in the issue thread) can opt in per query with
SETTINGS allow_replace_partition_from_empty_source = 1, or switch to an explicitALTER TABLE ... DROP PARTITIONwhen they really want to drop data.The check is added in both
StorageMergeTree::replacePartitionFromandStorageReplicatedMergeTree::replacePartitionFromImpl, exactly wheresrc_parts/src_all_partsis computed but before any destructive action. Theis_allbranch is excluded becauseREPLACE PARTITION ALLis already rejected withSUPPORT_IS_DISABLEDearlier in the function.ATTACH PARTITION FROM(replace = false) is unaffected because its empty-source case has always been a safe no-op (earlyreturnatdst_parts.empty()).Tests
tests/queries/0_stateless/04238_replace_partition_from_empty_source_23727.sql. Covers bothMergeTreeandReplicatedMergeTree, both directions of the new setting, plus the regression case that normal REPLACE with a non-empty source still works and that ATTACH PARTITION FROM an empty source remains a safe no-op. Verified locally with--test-runs 50under full randomization (50/50 OK).00626_replace_partition_from_table.sqland00626_replace_partition_from_table_zookeeper.sh) are updated to set the new opt-in flag on theREPLACE emptystep, preserving their intent without changing their reference output.02271_replace_partition_many_tables,02731_replace_partition_from_temporary_table,02455_improve_feedback_when_replacing_partition_with_different_primary_key, and01901_test_attach_partition_fromall still pass with no edits; they never relied on the broken empty-source behavior.SettingsChangesHistoryupdateRecorded under 26.6 with a previous_value of
trueso thecompatibilitysetting can restore the old behavior in one step (compatibility<=26.5).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ALTER TABLE ... REPLACE PARTITION ... FROM ...no longer silently drops the destination partition's data when the source table has no parts in the requested partition. Previously such a request removed the destination partition and wrote nothing in its place, an unambiguous data-loss footgun (issue #23727). It is now rejected withBAD_ARGUMENTSby default. This is a backward incompatible change: aREPLACE PARTITIONfrom an empty source that used to succeed (clearing the destination) will now throw after upgrade. To restore the previous silent-clear behavior, set the new settingallow_replace_partition_from_empty_source = 1(per query or in the profile), or setcompatibilityto26.5or lower. To explicitly drop destination data, useALTER TABLE ... DROP PARTITION ....Documentation entry for user-facing changes
The new setting
allow_replace_partition_from_empty_sourceis documented inline insrc/Core/Settings.cpp.Version info
26.6.1.1177