Skip to content

Keep the part minmax index over _block_number / _block_offset across a reload of a mutated part - #112878

Merged
alexey-milovidov merged 23 commits into
masterfrom
fix/part-minmax-lost-on-partial-mutation
Aug 12, 2026
Merged

alexey-milovidov merged 23 commits into
masterfrom
fix/part-minmax-lost-on-partial-mutation

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

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)):

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 this CI report.

Related: #96130

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix the per-part minmax index over _block_number and _block_offset being 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

  • Documentation is written (mandatory for new features)

…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
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [65bc2c9]

Summary: ✅


AI Review

Summary

This PR repairs part-level minmax materialization for _block_number / _block_offset across hardlinking mutations and non-row-reducing merges, including legacy-broken parts and live part_minmax_index_columns widening. I reviewed the current diff, the present code, the full inline-thread history, and the latest all-green CI report, and I did not find a remaining correctness, safety, or coverage gap in the current revision.

Final Verdict

✅ No material issues found in the current revision.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.10% +0.10%

Changed lines: Changed C/C++ lines covered: 157/159 (98.74%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 1, 2026
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 17/20 (85.00%) · Uncovered code

Full report · Diff report

…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`.
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
`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.
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
…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.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @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. 00980_merge_alter_settings failed once with a transient TOO_MANY_PARTS; the CI rerun diagnosis passed 179/179, and it is unrelated to this PR.

Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Confirmed, and the fix is already in progress: it is your own #113045, which already lists 00980_merge_alter_settings in its table of affected tests. So no separate PR from me.

The failing query is INSERT INTO table_for_alter VALUES (1, '1') into an empty table with parts_to_throw_insert = 1, rejected with Too many parts (1 with average size of 669.00 B), so the only part counted is the one that query wrote itself. That is the fan-out flaw #113045 fixes, and your read is right: unrelated to the minmax change here.

Still live while #113045 is unmerged: 00980_merge_alter_settings has 7 hits in the last 5 days, this one plus five other PRs and one Fast test in the merge queue, latest 2026-08-04 10:03 UTC. The other three tests in that table add 27 more, latest 02458_relax_too_many_parts at 2026-08-04 10:59 UTC. CI on #113045 head 6f036529 is clean: 157 success, 19 skipped, 0 failures.

…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @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. test_server_overload/test.py::test_drop_connections failed once with "Expected to drop the connection due to the server being overloaded at least once" and passed on the CI rerun (retry_ok); it is unrelated to the minmax change here, and I found no open issue or in-flight fix for it (the last fix, #96106, merged in February).

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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.

node2's log for that run contains 0 occurrences of CPU is overloaded, CPU is waiting for execution way more than executing and 0 of probability used to decide whether to drop the connection, in both clickhouse-server.log and clickhouse-server.err.log. Positive control: node1 in the same run has exactly 1 of each, from the test_overload case that passed. All 60 select 1 probes were accepted and served, so the connection filter never returned false.

Three measurements from that run.

  1. The retry loop outlives the load by a factor of two. The 4 select * from numbers(1e18) clients start at 12:57:01.036 and are killed by the helper's timeout=30 at 12:57:31.120, a 30.084 s window. The 60 iterations span 12:57:01.060 to 12:57:59.218, 58.2 s, because each iteration costs the 0.3 s sleep plus the round trip. So 30 of the 60 attempts probe a completely idle server. Fix flaky test_server_overload integration test #96106 doubled both the iterations (30 to 60) and the heavy query timeout (15 to 30), which preserved that 2:1 mismatch, so the number of attempts that can possibly succeed did not increase.

  2. The load did work. Server side duration of select 1 averages 38.2 ms inside the load window against 6.3 ms after it ends, 30 samples each.

  3. Given 2, the ratio must have been reading below the gate on the accept path. If the accept path had seen the ratio node1 measured (3.7717, giving probability 0.554 at min 1.0 and max 6.0), the chance of 0 drops across the 30 loaded attempts would be about 3e-11.

On why the gate stayed shut, and why the #96106 style of change cannot close it: getCPUOverload is a delta against prev_cpu_wait_microseconds and prev_cpu_virtual_time_microseconds, and the only writer of those is AsynchronousMetrics calling it with reset = true, once per asynchronous_metrics_update_period_s (default 1, not overridden here). The connection filter therefore sees only what accumulated since the last metrics tick, and inside that partial sub-second window it must still clear os_cpu_busy_time_threshold, which the test config already lowers to 300000 us. node2 is pinned to a single CPU by taskset -c 1, so it can accrue at most about 300 ms of virtual CPU time in 300 ms of wall time even when fully saturated. That makes the busy time gate, not the ratio, the plausible binding term, and lowering min_os_cpu_wait_time_ratio_to_drop_connection further would not move it. I have not yet proved which of the two terms read as zero, so I will settle that in the PR rather than assert it here.

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 tests/integration/test_server_overload/, and of the open PRs touching src/Common/ProfileEvents.cpp or programs/server/Server.cpp, none touches the overload check.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good.

@alexey-milovidov alexey-milovidov self-assigned this Aug 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 5, 2026
@alexey-milovidov
alexey-milovidov removed this pull request from the merge queue due to a manual request Aug 5, 2026
…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]>
@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Fix PR: #113529

I settled the question I left open above, and the answer moved the fix, so I want to be explicit
about that rather than quietly ship something different from what I said I would.

Which term read as zero: neither. I instrumented checkCPUOverload in a throwaway build to log
wait_delta, busy_delta, cpu_load and probability_to_throw on every accept-path
evaluation, and drove it with a probe loop that does not stop at the first drop, which the
shipped test does. The busy-time gate was not the binding term: only about 10 percent of loaded
probes read cpu_load == 0, and every probe that passed the gate measured a ratio above
min_ratio. What actually happened is that the probability was never 1. Over 318 loaded
evaluations at the four-concurrent-query shape the test creates it averaged 0.53 and never once
reached 1, and it did not reach 1 in any of the 1236 loaded evaluations across every load shape I
measured. So my guess above that the single-CPU busy-time gate was the plausible binding term was
wrong.

The reason is the ramp itself. probability_to_throw is
(clamp(cpu_load, min, max) - min) / (max - min), so it reaches 1 only once cpu_load reaches
max_ratio. The test asked for a wait/busy ratio of 6.0 while its own load produces 3.3 to 5.3,
so every probe was a coin flip near p=0.5 and the assertion fails whenever all of them lose. The
Bernoulli model is exact: summing the measured per-probe probabilities predicted 67.0 drops where
63 occurred. That is also why #96106 did not help. More attempts do not remove the dice.

Given that, I did not fix the load/loop mismatch I promised to fix. Lowering max_ratio below
the achievable ratio makes an overloaded window drop with probability 1, so a single loaded probe
suffices and the probe count, the pacing, the 2:1 mismatch and the phase of the 1 Hz metrics
reset all stop mattering at once. Fixing the mismatch would have raised the number of coin flips;
this removes them. The change is 2 test files, 9 lines, no change under src/.

The test gets stricter rather than more tolerant, which was your other concern. Every existing
assertion is untouched, the busy_delta > os_cpu_busy_time_threshold precondition is untouched
so an idle server is still admitted, and both cases now additionally assert that the probability
the server logged is 1, so a regression back to a fractional probability fails instead of passing
on a lucky draw. Reverting only max_ratio turns both cases red on exactly that new assertion,
and removing the synthetic load turns both red on the original one.

1.5 sits 2.17x below the weakest ratio I measured at the shape the test runs, and 1.24x below it
even at a degraded three-query load. Contention on a slower runner raises the wait/busy ratio, so
it moves away from the band rather than into it.

One thing worth noting separately, since it is not a test problem and I am not proposing a change
for it: the accept path shares the asynchronous-metrics reset window, so in production the
overload decision is evaluated over a partial, randomly phased sub-second window. That makes the
filter less aggressive than its settings suggest, which degrades gracefully, so I left it alone.

@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

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.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @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.

Storage/CoordinationTestWithCompression.TestStateMachineAndLogStore/MemCompressed hung until the harness sent SIGINT: the main thread is stuck in waitDurableLogs (src/Coordination/tests/gtest_coordination_common.cpp:47) — the changelog never reports the last log as durable. Unrelated to this PR (which only touches the MergeTree part minmax index). CI history shows the same test also hung on 2026-08-06 in the Unit tests (tsan) run of #111032 and never before in the last 60 days, so this looks like a recently introduced flake on master. No open issue or in-flight fix found.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Follow-up on the Unit tests (tsan) failure above: it is not a hang and not a flaky test. The job runs the whole binary sequentially under timeout -s INT -v 45m gdb, and the summed TSan test duration has crept to 38–40 minutes (from ~30 in early July), so a slower run exceeds the 45-minute cap and blames whichever test is running when SIGINT arrives — here TestStateMachineAndLogStore/MemCompressed, which legitimately takes ~62 s and sits near the end. The interrupted run had completed ~44 minutes of tests. Fix: #113863 raises the wrapper timeout to 90 minutes. This branch was also re-merged with master and pushed to get a fresh CI run.

@groeneai

groeneai commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

I measured this run's own artifact (unit_tests_tsan/job.log for 3eea89cb). The mechanism in your follow-up is confirmed; one figure in it overstates the baseline, and that changes how the two fixes divide the problem.

The attribution is confirmed. The wrapper starts at 06:56:27 and timeout: sending signal INT to command 'gdb' lands at 07:41:27, exactly 45:00.0. MemCompressed is the last of the 19016 [ RUN ] lines and had been running 46 s when the signal arrived, while its sibling MemUncompressed PASSED in 62.7 s in the same run. So waitDurableLogs is only where the main thread happened to be.

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 DistributedQueryTest.ShuffleHashJoin alone is 33.79 min, or 76.8% ([ OK ] ... (2027458 ms), run 2316 of 19016). Everything else totals 10.20 min. A healthy run is nowhere near the cap: over the last 30 days the AllTests duration across 11003 runs has a p50 of 18.5 min and a p99 of 20.4 min, and with ShuffleHashJoin subtracted the maximum is 22.95 min. Job wall clock on recent master runs is 21.6 to 23.7 min. Exactly one of those 11003 runs exceeded 40 min, and in that one ShuffleHashJoin was 24 min.

If the 38-40 came from summing test_duration_ms in default.checks, that series double counts: each run also stores an AllTests row holding the whole total, so summing all rows of a run gives roughly twice the real time. A run from today: 39.02 min across all rows, 19.54 min for AllTests, 19.48 min for the rest. The genuine creep since early July is smaller and came in two steps, with the p50 of summed per-test time going 14.8 to 18.2 min on 07-14 and 18.5 to 19.3 min on 08-01.

Both fixes are worth having, and they cover different halves. #113863 raises the cap. #113597 removes the cause: the gtest left max_threads unset, so it resolved to the runner's core count and each distributed task multiplied it by running its own pipeline. Capping it at 4 puts ShuffleHashJoin back to what it costs in every other sanitizer, 317 ms under asan_ubsan and 202 ms under msan on this same sha. Without #113597, a 90 min budget still leaves one gtest able to consume most of it: its tsan median is 0.2 s, but its daily maximum reached 257 s at worst in the five weeks before 07-29 and has run to 1445 s since, and to 2028 s in this run.

One caveat on how far to raise the cap. The test most often blamed in Unit tests (tsan) SIGINT rows over the last 60 days is ThreadPool.GlobalFull1, and those jobs are a different shape: the two most recent of them stored no per-test rows at all, and GlobalFull1 finishes about five minutes in (run 1004 of 19016, 244 ms here). The 45 minute tail is not what interrupts those, so the cap raise will not cover them.

PR 111032 hit this same signature on 2026-08-06 and I posted the equivalent measurement there.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The two reds on bc37ae5e648 were both unrelated to this PR:

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on 023640baaf8 is Stress test (arm_tsan), unrelated to this PR: Logical error: 'Stream y.Map%28UInt64%2C%20UInt64%29.buckets_info for column y with type Dynamic(max_types=170) is not found' during a merge — the bucketed Map-inside-Dynamic serialization-pool aliasing tracked in #113914, with the fix already in progress in #113514. Once that fix merges, a master remerge here will pick it up. Everything else in the run is green, the AI review reports no new findings, and there are no unresolved review threads.

pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Aug 9, 2026
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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (300 commits, clean — the PR diff is untouched and MutateTask.cpp / IMergeTreeDataPart.cpp recompile fine) to get a fresh CI run.

The only red on the previous run (023640baa) was Stress test (arm_tsan): Logical error: Stream y.Map%28...%29.buckets_info for column y with type Dynamic(max_types=170) is not found during a merge — unrelated to this PR; it is the Map-inside-Dynamic serialization-pool aliasing of #113914, whose fix #113514 is still open, so this remerge does not pull it in. Re-running mainly re-rolls the stress randomization; if it reappears, it is still that issue.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI status for 0f6c121b3a6: 157 SUCCESS, the only red is Stress test (arm_release) — job report — and it is unrelated to this PR: the job died before any stress testing started, in install_thread_pool_fault_injection (ci/jobs/scripts/stress/stress.py:402), because the verify query

SELECT value FROM system.server_settings WHERE name = 'cannot_allocate_thread_fault_injection_probability'

hit the client receive_timeout=15 right after SYSTEM RELOAD CONFIG (exit status 159), so check_output raised and took the whole script down with script exit code: 1. No server fatal, no logical error, no test failure (fatal.log empty; Server successfully started, No lost s3 keys, No SharedMergeTree lost forever all OK).

The fix is already in flight: #114063 (retries that verify query instead of dying on a single client timeout). Not merged into master yet, so a remerge here cannot clear it.

Also remerged master into the branch (~1 day of fixes, clean merge — the PR diff is untouched, and MutateTask.cpp, IMergeTreeDataPart.cpp and gtest_minmax_index_store_prefix.cpp all recompile) to re-roll the stress randomization and pick up the latest master.

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 CHANGES_REQUESTED from @Michicosun (2026-08-05), which was fully addressed by the 2026-08-06 commits (9991b492ec2, 2cc89a39dec, 841e0ef76fe — the break in MinMaxIndex::store was restored to keep the prefix semantics, plus the file-prefix and unit tests) and the thread was resolved; it needs a re-review or dismissal.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @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 stress.py fault-injection verify query needs a retry instead of killing the job on one client timeout.)

Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

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, 6fe5a48b7b2) adds --ast_fuzzer_runs=0 to make_query_command in stress.py. That removes the cause instead of the symptom, and it is what clears this job.

The mechanism on this run's own artifact is the server-side AST fuzzer, not a slow SYSTEM RELOAD CONFIG. The stress profile sets ast_fuzzer_runs=5 and ast_fuzzer_any_query=true for default, and the fuzzer runs as a query-finish callback on the same connection, so the harness's own maintenance query pays for its mutants. In clickhouse-server.stress.log, query 6c3a9f4c:

  • the verify query itself read 439 rows in 0.072 sec;
  • 5 fuzzed follow-ups ran on that connection, the slowest being SELECT value FROM merge(REGEXP('^'), '.*') from 02:56:42.931 to 02:57:01.846, ending in Code: 139 for catboost_lib_path;
  • TCPHandler: Processed in 19.226 sec, past the client's 15 s receive_timeout.

The failing command line in job.log has no --ast_fuzzer_runs=0, which places that build before #114127.

One correction to the status comment: the remerge did pick the fix up. The head moved from 0f6c121b3a6 to f9a10f17586, whose make_query_command already carries --ast_fuzzer_runs=0, so the run now in flight should be clean on this point.

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 b55839ac9c6.

Minor, no action needed: #114127's hunk left a trailing comma, so make_query_command returns a 1-tuple while annotated -> str. I checked that check_output and call with shell=True both accept that and run the first element, so behaviour is unchanged; only the log line prints ('...',).

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.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI status for f9a10f17586f: the only red was Stress test (arm_release) — job report — Hung check failed, possible deadlock found, unrelated to this PR: the hung query is stuck deep in QueryAnalyzer resolution (constant folding of an expensive function during analysis, before the cancellation machinery exists), which is the known issue #112203.

Also addressed the AI-review Major (merges of parts loaded under the narrow part_minmax_index_columns losing the block column ranges — fixed in b60f534683f with test 04843) and remerged master (~500 commits, clean; this also pulls in #113514, the fix for the earlier unrelated Map-inside-Dynamic stress red #113914).

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI status for b60f534683f: the only reds were Stress test (amd_debug) and Stress test (arm_release), both Hung check failed, possible deadlock found, and both unrelated to this PR: in each case the hung query is stuck deep in QueryAnalyzer resolution (IFunctionOverloadResolver::getReturnType during resolveFunction — constant folding of an expensive function during analysis, before the cancellation machinery exists), which is the known open issue #112203. Fixes are in flight (#114009, #114032) but not merged yet, so a master remerge cannot clear it deterministically — remerged master (~350 commits, clean; the PR diff is untouched and MutateTask.cpp, MergeTask.cpp, IMergeTreeDataPart.cpp recompile fine) to re-roll the stress randomization anyway.

Everything else is green: AI review verdict ✅ "No material issues found in the current revision", zero unresolved review threads, CH Inc sync green. The remaining blocker is the stale CHANGES_REQUESTED from @Michicosun (2026-08-05), fully addressed by the 2026-08-06 commits (the break in MinMaxIndex::store was restored to keep the prefix semantics, plus the file-prefix test and unit tests) — it needs a re-review or dismissal.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
Merged via the queue into master with commit 3c6a662 Aug 12, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix/part-minmax-lost-on-partial-mutation branch August 12, 2026 21:05
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants