Repository navigation
Fix settings-only ALTER on MergeTree with SimpleAggregateFunction in ORDER BY - #105111
Conversation
|
cc @azat @alesapin @CurtizJ @KochetovNicolai — could you review? Small fix in session: cron:clickhouse-ci-task-worker:20260516-100000 |
|
Pre-PR validation gate (worker) (a) Deterministic repro? Yes — running the exact (b) Root cause explained? (c) Fix matches root cause? Yes — the (d) Test intent preserved / new tests added? Existing tests are untouched. A new stateless test (e) Both directions demonstrated? Yes. Locally, on a debug build of the patched branch with the fix reverted (via (f) Fix is general, not a narrow patch? session: cron:clickhouse-ci-task-worker:20260516-100000 |
|
Workflow [PR], commit [0783b1c] Summary: ❌
AI ReviewSummaryThis PR narrows Final Verdict✅ No new findings. The current change looks correct to merge. |
|
Pushed commit 52c3849 addressing the mixed-command gap flagged by Bot's concern, restated
ALTER TABLE t MODIFY COMMENT 'x', MODIFY SETTING merge_with_ttl_timeout = 60;contains commands that satisfy one predicate each but not both, so both helpers return false. The mixed shape then fell through to the trailing (Note: FixAdded a dedicated TestsExtended
Pre-PR validation gate
Verification
Session: |
|
This was fixed by #105146. Let's update the branch. |
|
@groeneai check the CI failures, maybe another merge with master is needed |
|
@PedroTadim master merged in The only failing job was
Neither test touches The mixed-command |
azat
left a comment
There was a problem hiding this comment.
Why not simply check that sorting_key has been changed?
CI ledger — covered SHA:
|
| Check | Test | Disposition |
|---|---|---|
Stateless tests (amd_tsan, parallel, 1/2) |
00096_obfuscator_save_load |
flaky chronic trunk — task 2026-06-02-ci-00096obfuscatorsaveload-chronic-f |
Stateless tests (amd_tsan, parallel, 1/2) |
00175_obfuscator_schema_inference |
flaky chronic trunk — task 2026-06-02-ci-00175obfuscatorschemainference-ab |
Unit tests (asan_ubsan) |
(check-level) | infra/chronic UBSan UntrackedMemoryCounter — task 2026-06-03-ci-p1-chronic-ubsan-in-untrackedmemoryc |
BuzzHouse (amd_debug) |
Logical error: Mutation of \Memory` table produced incomplete output (STID: 2380-2e8c)` |
chronic trunk family bug (StorageMemory APPLY PATCHES) — tracked in 2026-04-23-ci-p0-storagememorymutate-assertion-, our fix PR #105286 awaiting review/merge. NOT PR-caused (this PR only touches StorageMergeTree.cpp ALTER ordering). |
No PR-caused failures. Awaiting human review (@ azat, @ alesapin, @ CurtizJ, @ KochetovNicolai).
Session: cron:our-pr-ci-monitor:20260604-213000
Pre-PR validation gate
Session id: cron:clickhouse-ci-task-worker:20260605-075800 |
CI ledger — covered SHA
|
| Failure | Classification | Disposition |
|---|---|---|
Config Workflow / Pre Hooks (HTTP 504 from gh api orgs/ClickHouse/members) |
infra (GitHub API transient) | Not PR-caused. The PR has the can be tested label. A maintainer-triggered re-run on this HEAD would clear it. |
No PR-caused failures. Per TASK.md state machine, moving the worker task to on_review for the prior body of feedback already addressed.
Session id: cron:our-pr-ci-monitor:20260605-110000
|
@groeneai check the CI failures. |
|
@PedroTadim CI triage for HEAD 1. 2. The PR is now the minimal #104463 fix: Note: the pre-existing ON CLUSTER divergence for mixed settings/comment (and comment-only |
Pre-PR validation gateFor the regression-test update in commit 885800b (placement-modifier coverage requested by the review bot).
Session id: cron:clickhouse-worker-slot-1:20260610-202318 |
|
CI finished on `7b5a4fcaa036`. All failures are infrastructure / chronic, none caused by this PR (which touches MergeTree ALTER/sorting-key validation):
Ready for review. |
The verifySortingKey gate in StorageMergeTree::alter and StorageReplicatedMergeTree::alter compared only the resolved sorting-key data-type names. A MODIFY ORDER BY that swaps one key column for another of the same type (e.g. (key, value) -> (key, value2) where value2 is a newly added SimpleAggregateFunction(sum, UInt64)) leaves the type-name list unchanged, so the gate skipped the check and let a new suspicious key column be introduced under allow_suspicious_primary_key = 0. Compare the resolved key column/expression list (KeyDescription.column_names) in addition to the data types. The data-type comparison is kept so an in-place key-column retype (same column name, suspicious new type) still fires. Renamed sortingKeyTypesChanged -> sortingKeyChanged accordingly. Added a regression case to 04248 covering the column-swap bypass. Reported by clickhouse-gh[bot] on PR ClickHouse#105111. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (update for the column-swap bypass fix)
Session id: cron:clickhouse-worker-slot-0:20260615-081200 |
CI status — HEAD
|
| Check / test | Class | Disposition |
|---|---|---|
| Bugfix validation: Lost forever for SharedMergeTree / Lost s3 keys / S3_ERROR No such key / OOM in dmesg / Exception in test runner | infra (chronic) | 44 PRs, 0 master in 7d. Not PR-caused. |
| Fast test (arm_darwin): 01951_distributed_push_down_limit, 01952_optimize_distributed_group_by_sharding_key | flaky (env) | 45 PRs, 0 master in 3d. macOS loopback-alias leak tracked in #107435. Not PR-caused. |
No PR-caused failures. Awaiting review.
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260621-075100 |
|
CI finished on HEAD
No PR-caused failures. ( Session: cron:our-pr-ci-monitor:20260621-133000 |
|
Merged current One conflict-free follow-up was needed: the master merge introduced Verified the three changed translation units ( The two reds on the previous head (
Both will re-run on the new head. |
CI finish ledger — b81fedaCI fully finished (Finish Workflow + Mergeable Check pass). All checks green on this HEAD; only the private ClickHouse-Inc sync mirror is non-green.
Session id: cron:our-pr-ci-monitor:20260703-053000 |
CI finish ledger — 605227cCI fully finished on this head (the 2026-07-05 merge-conflict resolution merging current master). Every individual test row is green in CIDB; the only red check is the private CH Inc sync.
Session id: cron:our-pr-ci-monitor:20260705-153000 |
azat
left a comment
There was a problem hiding this comment.
Ok, but, the PR description and comments and tests requires significant cleanup, it is way too verbose, please keep only essentials
Besides this is a very minor thing, we do not want to keep too much code for this.
| { | ||
| const auto & old_type = old_types[i]; | ||
| const auto & new_type = new_types[i]; | ||
| if (!old_type && !new_type) |
There was a problem hiding this comment.
It is the explicit-PRIMARY KEY key same-type swap that is now covered in 04498_104463_*: start from ORDER BY (key, value), then under allow_suspicious_primary_key = 0 run ADD COLUMN value2 SimpleAggregateFunction(sum, UInt64), MODIFY ORDER BY (key, value2). The resolved type list stays [Int32, SimpleAggregateFunction(sum, UInt64)], so a types-only comparison misses it even though the second key expression changed from value to value2.
|
Trimmed to essentials in da6f985 (PR now +77/-4, was +243/-4):
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260705-185300 |
|
Trimmed in fca2e3e:
It is not, and that dead branch is gone. The On the two bot notes:
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260705-204500 |
|
Squash all changes to one commit, 24 commits just for now is too much |
A settings-only ALTER (e.g. MODIFY SETTING, MODIFY COMMENT, codec changes) on a MergeTree family table whose sorting key contains a SimpleAggregateFunction column was incorrectly rejected as if the key type had changed. The sorting-key re-verification ran on every ALTER and compared key data types with IDataType::equals(), which ignores the SimpleAggregateFunction wrapper, producing a spurious mismatch. Re-verify the sorting key only when the ALTER actually changes it, and compare by type name (getName()) so the SimpleAggregateFunction wrapper is taken into account. Genuine key retyping and key-column swaps that would bypass allow_suspicious_primary_key are still rejected. Closes ClickHouse#104463
fca2e3e to
0783b1c
Compare
|
@azat Squashed the branch to a single commit: |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 23/23 (100.00%) · Uncovered code |
CI finish ledger — 0783b1cCI is complete (Finish Workflow passed; only the private "CH Inc sync" check remains, which does not run for fork PRs). This commit is a pure squash of the prior head
Session id: cron:our-pr-ci-monitor:20260707-220000 |
|
📊 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
|
d8b6fab
|
Hi — this looks like a backport candidate for |
…ettings-simple-aggregate Fix settings-only ALTER on MergeTree with SimpleAggregateFunction in ORDER BY
Closes: #104463
StorageMergeTree::alterandStorageReplicatedMergeTree::alterre-ranverifySortingKeyon almost everyALTERwhenallow_suspicious_primary_keywas off, so unrelated ALTERs (settings, comments, codecs, adding a non-key column, ...) failed withDATA_TYPE_CANNOT_BE_USED_IN_KEYon tables created withallow_suspicious_primary_key = 1. The check now runs only when the resolved sorting key actually changed (MergeTreeData::sortingKeyChanged, comparing key column names and data-type names), in the same place in both engines.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix an unexpected
DATA_TYPE_CANNOT_BE_USED_IN_KEYerror onALTERqueries that cannot change the sorting key (settings, comments, codecs, adding a non-key column, etc.) forMergeTreetables that have aSimpleAggregateFunction(or another type allowed only withallow_suspicious_primary_key = 1) in the sorting key.Version info
26.7.1.850(included in26.7and later)