Skip to content

Clamp the randomized index granularity in 01780_column_sparse_alter - #120968

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:clamp-index-granularity-01780-column-sparse-alter
Sep 19, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:clamp-index-granularity-01780-column-sparse-alter

Conversation

@groeneai

@groeneai groeneai commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119686

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Bounded the randomized index_granularity and index_granularity_bytes in 01780_column_sparse_alter so it no longer times out in the flaky check.

Description

Asked for in #119686 (comment): "make 01780_column_sparse_alter faster (or pin its granularity) so it stops timing out under randomized MergeTree settings."

Stateless tests (amd_binary, flaky check) on #119686 failed it at 208.35 s against the 180 s cap. The test is untouched by that PR; the flaky check matches by prefix, so 01780_column_sparse selects it too.

Root cause, from that job's own query_log and part_log: the draw was index_granularity 1, so the 2000-row Compact part carried 2001 marks, and mutations_sync = 2 waited on two whole-part mutations paying a per-granule cost 2000 times, 82.99 s (Seek 2002) and 103.33 s (FunctionExecute 2000), plus 16.8 s of granule-bound reads. In the batch's other 49 draws no statement exceeded 1.31 s, so there is no slow step: the granule count is the variable, and a pure randomizer artefact.

clickhouse-test already applies these two bounds for this reason, but only on sanitizer, debug and coverage builds (tests/clickhouse-test:2101). amd_binary is none of those, so the full range applied; this test opts into the same bound rather than widening the global one. The byte bound matters too: adaptive granularity takes the minimum, so 1024 bytes gives 49 marks at index_granularity 100, against 21 at 100000.

Validation through the runner, 6000 randomized runs per arm: without the line, 7 runs drew granules below 100 rows (worst 5 rows, 400 marks); with it none did, and the worst sits on the intended 20-mark floor. Output is byte-identical to the reference at index_granularity 1, 100 and 8192, so the serialization_kind oracle is unaffected: the Sparse kind is chosen once per part at INSERT and the mutations inherit it, and the floor still leaves up to 20 granules. The seven sibling 01780_column_sparse* tests show no such failure in 30 days of CIDB and are left alone.


Workflow [PR]
Sync PR [sync-upstream/pr/120968]

Version info

  • Merged into: 26.10.1.195 (included in 26.10 and later)

Stateless tests (amd_binary, flaky check) on ClickHouse#119686 failed this test at
208.35 s against the 180 s cap (TEST_MAX_RUN_TIME_IN_SECONDS,
tests/clickhouse-test:214, enforced at :3770-3775). The test is untouched
by that PR; the flaky check matches test names by prefix, so a change to
01780_column_sparse.sql selects 01780_column_sparse_alter too and runs it
50 times, each with a fresh randomized settings draw.

That draw was index_granularity 1. With index_granularity_bytes 17728586
(never binding) and min_bytes_for_wide_part 1073741824 (so the part is
Compact), the 2000-row INSERT produced one part with 2001 marks. SET
mutations_sync = 2 then makes each ALTER wait for a mutation that rewrites
the whole part one granule at a time, so every per-chunk fixed cost is paid
2000 times. From the failing job's own part_log: DROP COLUMN + RENAME took
82 990 ms (Seek 2002, CompressedReadBufferBlocks 4000) and MODIFY COLUMN
103 184 ms (Seek 2003, FunctionExecute 2000, RWLockAcquiredReadLocks 2000),
with the three uniqExact reads adding 16 770 ms. CPU is a small fraction of
that wall time and MutatePartStart is logged in the same second as the
ALTER, so this is neither data volume nor scheduling delay.

Speeding the test up is not available: in the other 49 draws of the same
batch no single statement exceeded 1.31 s, so there is no slow step. The
granule count is the variable, and unlike the row count (an oracle input,
via the 1-in-11 and 1-in-13 densities behind the reference counts 182 and
155) it is purely a randomizer artefact. So bound the two settings that
set granule size instead.

clickhouse-test already applies exactly these two bounds, for exactly this
reason, at tests/clickhouse-test:2101-2103, but only on sanitizer, debug
and coverage builds; amd_binary is none of those, so randint(1, 65536)
applied in full. This test opts into the same bound rather than widening
the global one.

index_granularity_bytes is clamped as well because adaptive granularity
takes the minimum of the two, so a low byte draw shrinks granules even at
index_granularity 100: measured, 1024 gives 49 marks against 21 at 100000.

Coverage is kept. index_granularity still ranges over [100, 65536], i.e.
1 to 20 granules over 2000 rows, so multi-granule sparse serialization is
still exercised, and the assertions are untouched: the Sparse kind is
chosen once per part at INSERT in MergeTreeDataWriter::writeTempPartImpl
(choose_kind = true) and the mutations inherit it (MutateTask.cpp,
choose_kind = false), while index_granularity affects only mark layout.
The test's output is byte-identical to the reference at index_granularity
1, 100 and 8192, and with index_granularity_bytes 1024 and 100000.

Validated through the runner with 6000 randomized runs per arm: without
this line 7 runs produced granules below 100 rows (worst 5 rows, 400
marks), with it none did and the worst run sits on the intended floor of
20 marks. The directive itself fails silently when unparsed, so it was
also checked against the real parser and randomizer over 20000 draws, with
a negative control that corrupts one character of the prefix and brings
sub-100 draws back (25 of 20000, minimum 1).

The seven sibling 01780_column_sparse* tests are subject to the same
randomizer but show no too-long failure in 30 days of CIDB, so they are
left alone.

Asked for in ClickHouse#119686 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 gate finding and 5 reviewer nits, the
rows with reader value listed below; bounded: 1 full pass, no fix round needed).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test has no live oracle proving the new limits are honored, so the claimed timeout prevention needs runner-level verification (01780_column_sparse_alter.sql:1) DISAGREE, already evidenced Fair ask, since this directive fails silently when unparsed, so it was measured before publication. 20000 draws through the real parser and randomizer stayed at or above 100 and 100000; corrupting one character of the prefix brings sub-bound draws back, 25 of 20000 with minimum 1, the exact CI draw. End to end, 6000 runs per arm: 7 runs drew a granule under 100 rows on pristine master (smallest 5 rows) against 0 with the line, worst run on the intended 20-granule floor. The 50-run flaky-check leg passed 50/50 in 8.95 s against a cap that applies per run.
2 💡 clickhouse-test derives object_shared_data_target_chunk_rows from the unclamped index_granularity (tests/clickhouse-test:2121-2126) before the clamp is applied (:3017), so a clamped test can still get a chunk size derived from index_granularity 1 DISAGREE, out of scope Pre-existing runner behaviour, neither introduced nor worsened by this line, and inert for this test, which has no Object column. Reported rather than changed.
3 💡 The description credited part_log with the two ALTER wall times, which come from query_log AGREE, fixed before publication The sentence now names both logs; the part_log counters it cites (Seek 2002, FunctionExecute 2000) are unchanged.

Severity: blocker / major / nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20260919-033900

@clickhouse-gh clickhouse-gh Bot closed this Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1dab0eb]

Summary: ✅


AI Review

Summary

This PR adds a Random settings limits: directive to 01780_column_sparse_alter so the flaky-check runner no longer draws pathological one-row MergeTree granules for this test. I did not find a correctness or coverage regression in the current code: tests/clickhouse-test parses and applies this directive to randomized MergeTree settings, the test's oracle still checks the same sparse-serialization behavior, and sparse-vs-default selection is driven by per-part default ratios rather than index_granularity, so clamping the random mark layout does not change the contract being exercised. CI for PR #120968 is fully green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? YES, neither leg waits for a rare draw. Parser/randomizer: 20000 draws through the real read_test_tags_and_random_settings_limits -> apply_random_settings_limits. End to end: tests/clickhouse-test 01780_column_sparse_alter --test-runs 6000 --jobs 16. The pathological granularity itself is forced deterministically with --merge-tree-settings "--index_granularity 1", giving 2001 marks on the part.
b Root cause explained? YES. Randomized index_granularity = 1 makes granules equal rows (2001 marks on the 2000-row Compact part); mutations_sync = 2 then waits on two whole-part mutations paying a per-granule cost 2000 times (82.99 s with Seek 2002, 103.33 s with FunctionExecute 2000), plus 16.8 s of granule-bound reads, for 208.35 s against the 180 s flaky-check cap (TEST_MAX_RUN_TIME_IN_SECONDS, tests/clickhouse-test:214, enforced :3770-3775). Reachable because the runner's own granularity floor at :2101 applies only to sanitizer, debug and coverage builds, and amd_binary is none of those.
c Fix matches root cause? YES. Cost is proportional to granule count, a pure randomizer artefact, so the fix bounds exactly the two settings that set granule size, to the same two values clickhouse-test already uses on slow builds. Rejected: a blanket no-random-merge-tree-settings tag; -- Tags: long (suppresses the cap and mislabels a 6 s test); a fixture shrink (in the other 49 draws of the same batch no statement exceeded 1.31 s, so there is no slow step to speed up).
d Test intent preserved / new tests added? Preserved exactly. .reference untouched, and the serialization_kind oracle is byte-identical at index_granularity 1, 100 and 8192 and with index_granularity_bytes 1024 and 100000 (5 arms, 0 mismatches), plus 12000 runner runs with 0 FAIL. index_granularity still ranges over [100, 65536], i.e. 1 to 20 granules, so multi-granule sparse serialization is still exercised. No new test: 61 tests use this directive and none asserts its own clamp, and an in-test assertion on a randomized value would itself be flaky.
e Both directions demonstrated? YES, at both layers. Parser/randomizer: 20000 draws all clamped (min 100 / 100000) versus 25 of 20000 below 100 (min 1) when one character of the directive prefix is corrupted, which is this directive's silent-failure mode. End to end, 6000 runs per arm: pristine master produced 7 runs with granules below 100 rows (worst 5-row granules, 400 marks), with the line 0, worst run exactly on the intended floor of 20 marks.
f Fix is general across code paths? YES for this defect's scope. Granule size has exactly two randomized carriers and both are clamped; merge_max_block_size governs merges and this test performs none, and min_bytes_for_wide_part selects Compact versus Wide rather than granule count. The seven sibling 01780_column_sparse* tests are untouched: 30 days of CIDB show zero too-long failures for any of them. Making the runner's floor unconditional across all build flavours would fix the whole class, but that is a coverage decision for the owners rather than part of this test fix.
g Fix generalizes across inputs (params/datatypes/wrappers)? YES. The setting matrix is the input space for a randomization fix, and it was swept: index_granularity in {1, 100, 8192} crossed with index_granularity_bytes in {default, 1024, 100000}, plus 12000 full randomized draws over the ~90 MergeTree and ~200 query settings the runner injects. Every arm reference-identical. Second carrier measured: at index_granularity = 100, index_granularity_bytes = 1024 yields 49 marks versus 21 at 100000, which is why both are bounded.
h Backward compatible? (maintainer-approved exception only) N/A, vacuously: the change is one comment line in one stateless test. No setting default changes, so no SettingsChangesHistory.cpp entry; no format, version or wire surface.
i Invariants and contracts preserved? YES. The invariant is that the granule count of this test's single part stays small enough for two synchronous whole-part mutations to finish far inside the flaky-check cap; the measured worst case under the bound is 20 granules. The Sparse/Default classification is decided once per part at INSERT (MergeTreeDataWriter::writeTempPartImpl, choose_kind = true) and inherited by the mutations (MutateTask.cpp, choose_kind = false), and index_granularity affects only mark layout, so no serialization contract is touched.

Session id: cron:clickhouse-impl-slot-5:20260919-030500

@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit e4dac56 Sep 19, 2026
176 of 349 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-datatype-wrapper Type modifiers/wrappers (Nullable, LowCardinality, etc.). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci 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.

3 participants