Repository navigation
Keep the part minmax index over _block_number / _block_offset across a reload of a mutated part - #112878
Conversation
…oss a reload of a mutated part
A mutation that does not rewrite the whole part (the usual case for a `Wide` part: `ALTER UPDATE` of a
single column, `RENAME COLUMN`, `DROP COLUMN`) only hardlinks the source part's files and copies its
in-memory minmax index into the new part. That is enough for the partition-key columns, whose minmax
files the source part always has on disk, but not for `_block_number` / `_block_offset` under
`part_minmax_index_columns = 'with_block_number_offset'`: a level-0 unmutated part has no minmax file for
them, because `MinMaxIndex::load` synthesizes their ranges from the part name and the row count. The
mutated part is no longer eligible for that synthesis - its `mutation` is not zero, and a mutation may
drop rows, so the offset range is no longer `[0, rows_count - 1]` - so the very next reload of the table
(`DETACH`/`ATTACH`, or a server restart) read back the whole universe and the index stopped pruning.
`finalizeMutatedPart` now materializes the inherited minmax index for the files that were not carried
over, and `MinMaxIndex::store` skips a file the caller already recorded in the checksums, so a hardlinked
file is never written through into the source part.
Reproducer (before this change the second `SELECT` reports `(NULL,NULL)`):
```sql
CREATE TABLE t (d Date, s String) ENGINE = MergeTree ORDER BY tuple()
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1,
part_minmax_index_columns = 'with_block_number_offset', min_bytes_for_wide_part = 0;
INSERT INTO t SELECT toDate('2018-10-01') + number % 3, toString(number) FROM numbers(9);
ALTER TABLE t UPDATE s = 'x' WHERE 1 SETTINGS mutations_sync = 2;
SELECT DISTINCT part_name, minmax__block_number FROM mergeTreeIndex(currentDatabase(), 't', with_minmax = 1);
DETACH TABLE t SYNC; ATTACH TABLE t;
SELECT DISTINCT part_name, minmax__block_number FROM mergeTreeIndex(currentDatabase(), 't', with_minmax = 1);
```
Found by the `DETACH`/`ATTACH` randomization of #96130,
which made `04652_part_minmax_block_columns_mutation` fail in
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=c4401c88193b6b28480990e9363f21ab7523b061&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29
|
Workflow [PR], commit [65bc2c9] Summary: ✅
AI ReviewSummaryThis PR repairs part-level minmax materialization for Final Verdict✅ No material issues found in the current revision. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 157/159 (98.74%) · Uncovered code |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 17/20 (85.00%) · Uncovered code |
…n part Addressing the review: materializing the inherited index only helps parts mutated from now on. A part that was mutated earlier - by a server that did not materialize the index, or while `part_minmax_index_columns` did not yet cover the block columns - has no `minmax__block_number.idx` of its own, and `MinMaxIndex::load` may not synthesize the range for a mutated part, so the range comes back as the whole universe and every later column-only mutation carries it forward until a merge or a full rewrite happens. `finalizeMutatedPart` now re-derives the `_block_number` range from the part's own block range before storing the index, for a part that still covers a single block. That is exactly the range `load` would have synthesized had the part not been mutated - every row of such a part was inserted by that one block - so the repair adds no assumption the loading path does not already make. The `_block_offset` range is deliberately left alone: a mutation may have dropped rows, and the row count of the original block is no longer recoverable from the mutated part. `MinMaxIndex::store` no longer stops at the first column whose range is unknown, but skips it, so a column with an unknown range does not suppress the files of the columns after it. Test `04671_part_minmax_block_columns_legacy_repair`.
…t-on-partial-mutation
`finalizeMutatedPart` repaired the copy of the minmax index it writes to disk, but then installed the source part's index on the new part, so a part whose `_block_number` range was lost by an older mutation kept the whole-universe range in memory - and kept missing the prune - until the next `DETACH` / `ATTACH` or restart. Install the repaired index instead, and cover the pre-reload path in `04671_part_minmax_block_columns_legacy_repair`. Also pin `min_bytes_for_full_part_storage = 0` in both new tests: the CI randomization of that setting puts the part into packed storage, where a mutation rewrites the whole part instead of hardlinking it, so the tested code path is not taken and the expected ranges differ.
…t-on-partial-mutation
…ck parts too The inherited `_block_number` range is now repaired to `[min_block, max_block]` of the part's own name for any non-patch part, not only for a part that still covers a single block: every row's `_block_number` lies within that range, and for a single-block part it degenerates to the exact value `MinMaxIndex::load` would have synthesized. `_block_offset` intentionally stays unrepaired.
…t-on-partial-mutation
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112878&sha=b3b2ecfc1bb0ac834fe215bb4c529cc640da415d&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
Confirmed, and the fix is already in progress: it is your own #113045, which already lists The failing query is Still live while #113045 is unmerged: |
…ns` was widened on a live table Widening `part_minmax_index_columns` with `ALTER TABLE ... MODIFY SETTING` does not reload the parts already in memory, so a part written under `partition_key_only` still carries a minmax index without the block column slots at all. `repairInheritedBlockNumberMinMax` and `MinMaxIndex::store` both stopped at `hyperrectangle.size()`, so the first column-only mutation after the setting change committed a part with no `_block_number` minmax to repair or store, and it read back as the whole universe after a reload. Now the repair grows the inherited index to the current set of minmax columns with unknown (whole universe) ranges - the same value `load` gives a column whose file is missing - before repairing and storing, so `_block_number` is healed to the part's own block range. Verified that the new test `04757_part_minmax_block_columns_setting_widened` fails without this change (`(NULL,NULL)` and no pruning) and passes with it. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112878&sha=8f9de6fcea91353218cef07111e5cfe32380143d&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%201%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
Root cause so far: the server never dropped anything, so the client had nothing to observe. This is not a missed drop on the client side.
Three measurements from that run.
On why the gate stayed shut, and why the #96106 style of change cannot close it: Next step: I will open a separate PR. Item 1 is a defect regardless of the above and I will fix it so that every attempt probes a loaded server. If that alone does not make the test deterministic, the honest fix is on the server or config side, not a wider tolerance, and I will say so with the measurement. I will not weaken the assertions, and I will verify both directions, including that the test still fails when the drop path cannot fire. I will link the PR here. I also confirm your search at a fresh clock: the only issue on this test is the closed 96195, no open PR touches |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Looks very good.
…ource part is a single never-mutated block A column-only mutation keeps every row, and a single never-mutated block holds every row of that block, so its offsets are exactly `[0, rows_count - 1]` - the same range `MinMaxIndex::load` would still synthesize for the source part. Once the chain has passed through a mutation or a merge, rows may have been dropped and the range stays as the whole universe, as before. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Fix PR: #113529 I settled the question I left open above, and the answer moved the fix, so I want to be explicit Which term read as zero: neither. I instrumented The reason is the ramp itself. Given that, I did not fix the load/loop mismatch I promised to fix. Lowering The test gets stricter rather than more tolerant, which was your other concern. Every existing 1.5 sits 2.17x below the weakest ratio I measured at the shape the test runs, and 1.24x below it One thing worth noting separately, since it is not a test problem and I am not proposing a change |
…t-on-partial-mutation
Build profile diff (arm_release)No arm_release build profile data for commit 65bc2c9 - the build was skipped, reused from cache, or predates profile upload. |
…t-on-partial-mutation
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112878&sha=3eea89cbb616eee24f1777cefb80ac39140aee60&name_0=PR&name_1=Unit%20tests%20(tsan) and provide a fix in a separate PR. If the fix is already in progress, link it here.
|
|
🕵 Follow-up on the |
|
I measured this run's own artifact ( The attribution is confirmed. The wrapper starts at 06:56:27 and The 38-40 minutes is one test, not a broad creep. Summing the per-test durations in this run gives 43.99 min, of which If the 38-40 came from summing Both fixes are worth having, and they cover different halves. #113863 raises the cap. #113597 removes the cause: the gtest left One caveat on how far to raise the cap. The test most often blamed in PR 111032 hit this same signature on 2026-08-06 and I posted the equivalent measurement there. |
…t-on-partial-mutation
|
🕵 The two reds on
|
|
🕵 The only red on |
The unit tests run sequentially in one binary under `timeout -s INT -v 45m gdb`. The summed test duration under TSan has grown from ~30 minutes in early July to 38-40 minutes now, leaving almost no headroom: a run on a slower machine exceeds the budget and the report blames whichever test happened to be running when `SIGINT` arrived - most recently `Storage/CoordinationTestWithCompression.TestStateMachineAndLogStore/MemCompressed`, which legitimately takes ~62 seconds and sits near the end of the run. Seen in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112878&sha=3eea89cbb616eee24f1777cefb80ac39140aee60&name_0=PR&name_1=Unit%20tests%20(tsan) (ClickHouse#112878) and in the same job on ClickHouse#111032 the day before. Co-Authored-By: Claude Fable 5 <[email protected]>
…t-on-partial-mutation
|
🕵 Merged The only red on the previous run ( |
…t-on-partial-mutation
|
🕵 CI status for hit the client The fix is already in flight: #114063 (retries that verify query instead of dying on a single client timeout). Not merged into Also remerged The AI review verdict is ✅ "No material issues found in the current revision" and there are no unresolved review threads. The remaining blocker is the stale |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112878&sha=0f6c121b3a65fcacb289b358e27634902aa1dcc1&name_0=PR&name_1=Stress%20test%20%28arm_release%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. (A fix is already open: #114063 — the |
|
The owner is already merged, and it is not #114063. @ azat's #114127 ("Fix stress test failures due to internal queries was fuzzed", merged 2026-08-10 12:09 UTC, The mechanism on this run's own artifact is the server-side AST fuzzer, not a slow
The failing command line in One correction to the status comment: the remerge did pick the fix up. The head moved from So no separate PR is owed from me. #114063 still has value as defence in depth, since a retry also covers timeouts that are not fuzzer-induced, but it is not what unblocks this. #113248 carries both halves, and its cause half is now redundant with #114127. For the record, the unretried call this aborts in came from my own merged Minor, no action needed: #114127's hunk left a trailing comma, so |
…t-on-partial-mutation
Address review: the widened-setting repair only ran in `finalizeMutatedPart`, so a non-row-reducing merge of parts loaded under `part_minmax_index_columns = 'partition_key_only'` still seeded the merged part with `merge` over width-1 indexes, which truncates the merged index to the narrow width - the merged part was stored without the block column files and read back the whole universe after a reload. Move the repair into `IMergeTreeDataPart::MinMaxIndex::repairInheritedBlockColumns` and apply it in `MergeTask` to a copy of each source part's index before merging. The repaired `_block_number` range is now derived from the source part's own block range (identical to the new part's range in the mutation case); `_block_offset` is still repaired only for a single never-mutated block, which a non-row-reducing merge carries over unchanged. Add test `04843_part_minmax_block_columns_setting_widened_merge` (the `04757` setup with three inserts and `OPTIMIZE TABLE ... FINAL` instead of the `UPDATE`); negative-verified: without the `MergeTask` repair it fails with `(NULL,NULL)` ranges and `TOO_MANY_ROWS` on the prune.
|
🕵 CI status for Also addressed the AI-review Major (merges of parts loaded under the narrow |
…t-on-partial-mutation
|
🕵 CI status for Everything else is green: AI review verdict ✅ "No material issues found in the current revision", zero unresolved review threads, |
A mutation that does not rewrite the whole part (the usual case for a
Widepart:ALTER UPDATEof a single column,RENAME COLUMN,DROP COLUMN) only hardlinks the source part's files and copies its in-memory minmax index into the new part. That is enough for the partition-key columns, whose minmax files the source part always has on disk, but not for_block_number/_block_offsetunderpart_minmax_index_columns = 'with_block_number_offset': a level-0 unmutated part has no minmax file for them, becauseMinMaxIndex::loadsynthesizes their ranges from the part name and the row count. The mutated part is no longer eligible for that synthesis — itsmutationis not zero, and a mutation may drop rows, so the offset range is no longer[0, rows_count - 1]— so the very next reload of the table (DETACH/ATTACH, or a server restart) read back the whole universe and the index stopped pruning.finalizeMutatedPartnow materializes the inherited minmax index for the files that were not carried over, andMinMaxIndex::storeskips a file the caller already recorded in the checksums, so a hardlinked file is never written through into the source part.Reproducer (before this change the second
SELECTreports(NULL,NULL)):Found by the
DETACH/ATTACHrandomization of #96130, which made04652_part_minmax_block_columns_mutationfail in this CI report.Related: #96130
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix the per-part minmax index over
_block_numberand_block_offsetbeing lost after a table reload when the part was produced by a mutation that does not rewrite the whole part.Documentation entry for user-facing changes