Repository navigation
Conversation
|
@alexey-milovidov this implements #107551 with the four decisions you gave. Two things need your call, both in the description: (1) the new merge semantics currently apply on the next table load (DETACH/ATTACH or restart), not as a live hot-swap, because Session: cron:clickhouse-worker-slot-0:20260616-015700 |
|
Workflow [PR], commit [e2c0737] Summary: ❌
AI ReviewSummaryThis PR adds experimental Findings❌ Blockers
Final Verdict❌ Changes requested. LLVM Coverage Report |
Pre-PR validation gate (commit 52ebe0c — bot CR fixes)
Session id: cron:clickhouse-worker-slot-4:20260616-144900 |
Pre-PR validation gate (commit 301eedf)
Session id: cron:clickhouse-worker-slot-4:20260616-160600 |
Pre-PR validation gate (commit 228affb)
The live hot-swap vs reload-only design (open point 3) is unchanged and remains for the maintainer call. Session id: cron:clickhouse-worker-slot-0:20260616-172600 |
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260616-185300 |
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260616-202500 |
Pre-PR validation gate (TABLE ENGINE access fix, 9b8702b)
Session id: cron:clickhouse-worker-slot-0:20260617-030200 |
9b8702b to
1140974
Compare
CI finish ledger — 1140974Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
No failed tests on this SHA. Finish Workflow + Mergeable Check + PR all pass. Session id: cron:our-pr-ci-monitor:20260702-163000 |
f3eab9b to
0b3fa52
Compare
CI finish ledger — 0b3fa52CI fully finished on this head (Finish Workflow completed 2026-07-04T16:26:47Z, 0 checks queued/in_progress). Every failure has an owner.
None of the failing tests are in this PR's diff (the PR adds Session id: cron:our-pr-ci-monitor:20260704-170000 |
|
Correction to the two arm_darwin lines above: they have a merged fixing PR, so they link directly (the "fix task moved to pending" wording was imprecise):
Session id: cron:our-pr-ci-monitor:20260704-170000 |
…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]>
04340_alter_modify_engine: experimental gate, MergeTree -> Replacing/Summing, single-statement ADD COLUMN + MODIFY ENGINE -> Collapsing, FINAL dedup/sum after reload, and validation errors (non-MergeTree target, missing required column). Docs: new alter/engine.md page documenting MODIFY ENGINE, linked from the ALTER index. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…l settings ignore list The Style check (check_cpp.sh) requires every allow_* setting in Settings.cpp to appear in either enableAllExperimentalSettings.cpp or experimental_settings_ignore.txt. allow_experimental_alter_modify_engine gates an ALTER (not a CREATE) operation, so it belongs in the ignore list alongside the sibling allow_experimental_alter_materialized_view_structure gate, rather than in enableAllExperimentalSettings (which only enables features for CREATE-query replica recovery). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ting Two correctness fixes on the MODIFY ENGINE path. Reject old-syntax MergeTree tables. A table created as MergeTree(date, key, 8192) keeps the sorting/sampling key and granularity as positional arguments inside the engine ASTFunction. The engine-clause rewrite replaces the whole function, dropping those arguments; is_custom_partitioned is false for such tables, so the key is not restored from ASTStorage either. The result was an ENGINE = ReplacingMergeTree(v) clause with no ORDER BY, unloadable on the next ATTACH (error 42). Reject these in checkAlterIsPossible, as MODIFY ORDER BY / TTL / SAMPLE BY already do. Validate the new MergingParams before persisting. applyEngineModification re-checks the candidate MergingParams and can throw; it ran after alterTable() had already written the rewritten CREATE query, so a rejection could leave an invalid engine clause on disk. Move the call before alterTable(). The deferred live merging_params swap (open point 3) is unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ing test Pre-persist MergingParams validation used the current MergeTreeSettings, not the settings after a MODIFY SETTING in the same ALTER. Switching to a Summing or Coalescing engine that needs allow_summing_columns_in_partition_or_order_key (or the coalescing variant) was checked against the old flag, so MODIFY ENGINE combined with MODIFY SETTING in one statement was wrongly rejected, and the check disagreed with the reload path. Build the candidate settings from the in-flight setting changes (getSettings with the metadata's settings_changes). Test: select v directly under FINAL instead of sum(v) for the SummingMergeTree case. sum(v) returns the same result whether or not the engine changed; reading the merged rows fails if the rewrite is absent (plain MergeTree rejects FINAL). Co-Authored-By: Claude Opus 4.8 <[email protected]>
The MODIFY ENGINE Graphite path guard has separate isVariant, isDynamic and isObject terms, and the documentation promises all three rejections, but the test file covered only Array, Tuple, Map, QBit and the LowCardinality wrappers. Deleting any one of the three guards left the suite green. The three terms are distinct TypeIndex tests, so no other term of the condition can cover them. Verified by deleting all three: exactly the three new cases fail with "query succeeded but the server error 36 was expected", one per guard, and restoring the guards returns the binary to its previous build id. The JSON case must insert a valid JSON literal; a bare string fails earlier at INSERT with Code 117 and the case would never reach the guard.
checkAlterIsPossible replays the ALTER's other commands onto a copy of the
current metadata to validate the target engine against the columns this same
statement produces. It applied them to unnormalized columns, while the real
preparation and commit paths call removeImplicitStatistics first.
auto_statistics_types defaults to 'basic, uniq_v2', so every column carries an
implicit basic statistic. Adding an explicit statistic of the same type in a
statement that also changes the engine then hit the duplicate-type check in
ColumnStatisticsDescription::merge and a valid command was rejected:
CREATE TABLE t (a UInt32, k UInt32) ENGINE = MergeTree ORDER BY a
SETTINGS auto_statistics_types = 'basic';
ALTER TABLE t MODIFY ENGINE = ReplacingMergeTree, ADD STATISTICS k TYPE basic;
-- Code: 708. Statistics type name Basic has existed in column k
The same ADD STATISTICS without MODIFY ENGINE succeeded, so only the replay was
affected; a genuine duplicate is still rejected.
Found by the second-model review of the master merge.
Five graphite arms of 04340_alter_modify_engine read back the rolled-up `Time` value. The `graphite_rollup` config CI installs has a second retention with precision 6000, and above precision 900 GraphiteRollupSortedAlgorithm rounds relative to the local day rather than to the raw timestamp, so the rounded value depends on the server time zone. CI randomizes the server time zone (ClickHouseProc.set_random_timezone rewrites /etc/localtime), and the merge thread has no query context, so DateLUT::instance() resolves to that zone. The Enum16 arm additionally reddened hard: under Europe/Paris the rounded value is -3600, which the enum cannot name, giving Code 691 UNKNOWN_ELEMENT_OF_ENUM. Assert the row collapse and the surviving version instead, which are the properties these arms exist to check and which hold in every time zone. A mutation of the expected count still reddens each arm, so the coverage is preserved. `session_timezone` is not a usable pin here: it is a session-level setting and the background merge does not read it. Verified against 599 time zones by model and end-to-end under UTC, Europe/Paris, America/Los_Angeles, Asia/Kolkata, Australia/Eucla, America/St_Johns, Pacific/Kiritimati and Africa/Khartoum. Before this change the test passes only under UTC. Plain `CREATE TABLE ... GraphiteMergeTree` rounds identically, so the rounding itself is the engine's existing behaviour and not something MODIFY ENGINE introduces.
Build profile diff (arm_release)Commit See the job log for details. |
…e Graphite arms The flaky check reported "Test runs too long (> 180s)" for 04340_alter_modify_engine. Across all 250 runs on this head the test sat at a 146s median with a 177.9s passing maximum, i.e. 2.1s of headroom against the cap, so the tail crossed the line whenever the runner was loaded. The cost driver is async_insert, not the data volume. Every INSERT in the test writes a single row and then the next statement asserts what the merge produced, so with async inserts enabled each of the ~60 INSERTs blocks on the async buffer flush instead of doing work. Measured locally with otherwise identical settings, the pre-split file ran at a 1.33s median with async_insert=0 against a 10.76s median and a 35.01s maximum with async_insert=1. Pin async_insert = 0 in the test body, which beats the runner's injected value, rather than using the blanket no-async-insert tag. The test asserts merge outcomes and never exercises the async insert path, so nothing is lost. Also split the Graphite and special-mode arms into 04353_alter_modify_engine_graphite. The two halves are independent: every SET in the moved range is already paired inside it and no table crosses the seam. The union of the two reference files is the same multiset of lines as the original, and each half is an ordered subsequence of it, so no assertion changed. After both changes, 50 runs at 16 workers with fully randomized settings give a 0.68s median / 0.98s maximum for 04340 and a 1.33s median / 1.44s maximum for 04353. Forcing async_insert=1 keeps the maximum at 1.63s. Corrupting one reference line in either half still fails the test.
…dify-engine-107551
CI finish ledger - ef48adcCI is fully finished on this head and there are no failures to own. Gates: no check queued/in_progress/pending; Coverage verified from the praktika report rather than the skip ratio:
Session id: cron:our-pr-ci-monitor:20260815-070000 |
|
📊 Cloud Performance Report ✅ AI verdict: This change adds the experimental ALTER TABLE ... MODIFY ENGINE statement (new parser keyword, AST node, alter-command handling, and CREATE-query metadata rewrite), all behind a setting that defaults off. It touches no query-execution code, so it cannot plausibly move a ClickBench SELECT. The only flagged query, clickbench Q18 (+5.0%), shows flat CPU time (+0.8%) and mixed/borderline test signals, so it is downgraded to not_sure as run-to-run variance rather than a PR effect. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. 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
|
…dify-engine-107551 One conflict, in src/Core/Settings.cpp. Master obsoleted allow_experimental_codecs (it is now MAKE_OBSOLETE) and put enable_alp_codec, enable_quantized_codec, enable_sz3_codec and enable_zxc_codec at that position, which is exactly where this branch had inserted allow_experimental_alter_modify_engine just above it. Resolved by keeping both sides: allow_experimental_alter_modify_engine stays directly after allow_experimental_unique_key, master's four codec settings follow it, and the obsoleted allow_experimental_codecs DECLARE is not restored (restoring it would both revert the obsoletion and duplicate the name).
…block Master opened the 26.9 settings-history block while this branch was behind, so the merge left this branch's entry sitting in the 26.8 block. check_settings_changes_history in ci/jobs/check_style.py requires every setting touched by a change that also edits src/ to be recorded under the block matching cmake/autogenerated_versions.txt, which is now 26.9. 26.8 was released without this setting, so a record there would also tell `compatibility` that the setting changed in a release that never had it. The entry text is unchanged; only the block it sits in.
Master turned docs/reference/statements/alter/index.mdx into generated
output while this branch was behind: the file gained
{/*AUTOGENERATED_START*/} / {/*AUTOGENERATED_END*/} markers, and this
branch's hand-written `ENGINE` row now sits inside that region. The
Mintlify docs job rejects any change to a marked region
(ci/jobs/docs_job_mintlify.py calls check_autogenerated_regions), so the
row has to come from the generator's source data instead.
The row now lives in the `ALTER` statement description in
registerStatementAlter, which is what the generator renders into that
region, so the nightly documentation run emits it. Reverting the .mdx
alone would have dropped the row at the next regeneration.
The recent master merge left `#include <Parsers/ASTIdentifier.h>` in the file twice: master had gained the include independently while this branch already carried one, and the resolution kept both sides. `Build (arm_tidy)` runs readability-duplicate-include with `WarningsAsErrors: '*'`, so this was the only error in that job, and it suppressed every downstream check on the tree. Dropping the copy this branch added leaves the include block byte-identical to master. The header is `#pragma once`, so the translation unit is unchanged, and `getIdentifierName` in the new code is still served by master's own include, which master needs for `ASTTableIdentifier`.
`FINAL` and the merge algorithms treat a part above level zero as already merged by the current engine: `IMergingAlgorithmWithDelayedChunk` and `IMergingAlgorithmWithSharedChunks` both short-circuit `rowsHaveDifferentSortColumns` when two rows come from the same source at a non-zero level. `MODIFY ENGINE` leaves existing parts at their old level, so rows with equal sorting keys that an ordinary `MergeTree` merge had already placed in one part survive the change. Measured on a debug build for all five collapsing targets, after `OPTIMIZE TABLE ... FINAL` on a plain `MergeTree` and a reload: `ReplacingMergeTree` keeps 2 rows of 1, `SummingMergeTree` and `AggregatingMergeTree` keep 10 and 20 instead of 30, `CoalescingMergeTree` keeps 7 and `NULL`, `CollapsingMergeTree` keeps both signs. A later `OPTIMIZE TABLE ... FINAL` does not repair it. The page claimed the opposite. State the actual behaviour and the rewrite workaround; the claim can be restored when the part-level handling lands. That remains a metadata and timing design call, open in the review thread on `MergeTreeData.h` together with the engine swap mechanism. Co-Authored-By: Claude Opus 5 <[email protected]>
…he other flags `MODIFY ENGINE` added an `engine` pointer to `ASTAlterCommand`, which took the class from 512 to 520 bytes. 512 is a jemalloc size class boundary, so the allocation for every `ASTAlterCommand` the parser builds rounded up to the next class, 640, costing 128 extra bytes on the AST of every `ALTER` query rather than only on `MODIFY ENGINE` ones. `Parser memory check` reported this on ten plain `ADD COLUMN`, `DROP COLUMN`, `MODIFY COLUMN` and `COMMENT COLUMN` queries, each a constant 128 bytes over master at 9.2% to 11.5%, above its 100 byte and 1.0% thresholds. `replace` was declared alone between two `String` members, so it occupied an eight byte slot of which seven bytes were padding. Declaring it next to the other flags places it in the existing padding after `move_destination_type` and returns the class to 512, making the allocation identical to master again. The member is only read by name and its JSON serialization is keyed by name, so the move does not change behaviour. Measured with a `sizeof` probe on the header and independently with `gdb` on the built binary: 520 before, 512 after, and 512 on master. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=107585&sha=3f235cce207cf3c355ff3e44bc6e454ea0a80fa7&name_0=PR&name_1=Parser%20memory%20check ClickHouse#107585
CI finish ledger - d056a20Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260907-213102 |
…-107551 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| bool share_nested_offsets = (*getSettings())[MergeTreeSetting::share_nested_offsets]; | ||
| /// Replay needs normalized columns: an implicit statistic collides with an explicit one of the same type. | ||
| removeImplicitStatistics(metadata_for_check.columns); | ||
| for (const auto & c : commands) |
There was a problem hiding this comment.
This pending-engine revalidation still only sees post-ALTER metadata, so it misses data-rewriting commands that are supposed to stay forbidden once the target engine is pending. A concrete path is ALTER TABLE t MODIFY ENGINE = CollapsingMergeTree(sign), then before reload ALTER TABLE t CLEAR COLUMN sign IN PARTITION ...: c.apply leaves sign present in metadata_for_check, new_merging_params.check passes, and the later checkAlterEligibility guard never fires because the live merging_params is still Ordinary until reload. After the reload the table runs CollapsingMergeTree over rows whose sign column was rewritten to the default 0, a mutation that the live CollapsingMergeTree path explicitly rejects. The same bypass applies to pending ReplacingMergeTree(ver) / VersionedCollapsingMergeTree(sign, ver) special columns. Please carry the pending engine into the special-column CLEAR / data-rewrite checks as well, or reject those alters while new_engine is still pending.
|
@alexey-milovidov, this is question 1 in the description, with new measurements. Between Each of these guards reads the live
I would do 1. Which do you prefer? |
CI finish ledger - dd56a3eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 173 check runs completed (153 pass, 19 not selected, 1 red) and Session id: cron:our-pr-ci-monitor:20260926-120120 |
…-107551 Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added
ALTER TABLE ... MODIFY ENGINE = ...MergeTree(...)to change the engine of a MergeTree-family table in place (for exampleMergeTreeintoReplacingMergeTreeorSummingMergeTree). Gated behind the experimental settingallow_experimental_alter_modify_engine.Description
Closes: #107551
Related: #107481
Requested by @ alexey-milovidov.
ALTER TABLE t MODIFY ENGINE = <engine>changes a MergeTree-family table's engine in place. Only the merge semantics (MergingParams) change: columns, keys and settings are kept, and data is not rewritten. Existing parts keep their merge level, so equal-key rows that an ordinaryMergeTreemerge had already placed in one part stay uncollapsed under the new engine;engine.mdxdocuments this and the rewrite workaround. Resetting the level, as #107481 does for adopted parts, depends on question 1 below.A new
MODIFY_ENGINEcommand rewrites the engine clause in the CREATE query;MergingParams::parseFromEngineASTvalidates the new merge params against the columns and final settings first, so a rejection never leaves an unloadable CREATE on disk.Supported targets:
Replacing,Summing,Aggregating,Collapsing,VersionedCollapsing,Coalescing,Graphite. A required column may be added in the same statement, beforeMODIFY ENGINE. Non-replicated tables only; old-syntax tables are rejected.Because data is not rewritten, a transition is refused when existing parts could not satisfy the target's invariants: a nullable or unreadable
Graphitepath/time column, andVersionedCollapsingwith the version column outside the sorting key.Two questions for review:
merging_paramsis read lock-free from hot paths and often bound by const reference for a whole query, and an exclusive lock cannot be taken there. An immediate swap needs either aMultiVersionmerging_paramsor recreating the storage. Which do you prefer?Replicated*MergeTreeswitch (decision 3 on the issue) is not implemented.ReplicatedMergeTreeTableMetadataalready persists the merge mode, so that is the natural next step.Tests:
04340to04343and04353intests/queries/0_stateless. Docs:docs/reference/statements/alter/engine.mdx.Workflow [PR]
Sync PR [sync-upstream/pr/107585]