Skip to content

Pin merge_max_block_size in 05210_skip_index_type_from_alter_session_setting - #121126

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:pin-merge-max-block-size-in-05210-granule-oracle
Sep 22, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:pin-merge-max-block-size-in-05210-granule-oracle

Conversation

@groeneai

@groeneai groeneai commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119799

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

...

Description

05210_skip_index_type_from_alter_session_setting failed once on master in Stateless tests (amd_tsan, parallel) (report): the first assertion flipped 1 to 0, and the runner's minimization isolated --merge_max_block_size 110 (52/52 reproducible).

Root cause. The test asserts an exact Granules: 16/32 on the merged part. A merge computes index granularity per output block (MergeTreeDataPartWriterCompact.cpp:257), and a block tail shorter than a full granule gets its own short mark (:501-510, deliberate per the comment at :507). At 110 the 128-row merge emits 110 + 18 and writes 33 marks instead of 32, so the plan prints Granules: 17/33. merge_max_block_size is randomized, and was the one block-splitting setting not pinned beside index_granularity and index_granularity_bytes.

Not a server bug. At 110 the merge does not throw, force_data_skipping_indices = 'idx' raises no INDEX_NOT_USED, both counts are still 64, and idx still prunes half the granules. Only the exact-count literal moved; the invariant #119799 added this test for is intact.

The change pins merge_max_block_size = 8192, the setting's own default, in the table's SETTINGS clause; .reference and the assertion are unchanged. It is enforced, not best-effort: the client only injects a randomized MergeTree setting the clause does not already carry (ClientBase.cpp:3953). 49 other stateless tests pin it the same way.

Validation. Deterministic FAIL at 110 before, OK after; reverting only the pin brings the failure back. Swept 14 values from 1 to 8192 including all 7 predicted to break: green with the pin. 50/50 green, randomization confirmed live; the pin also suffices for Wide parts and vertical merges. CIDB: 832 passes against this one failure over 30 days, zero PR carriers.

7 other stateless tests assert an exact granule count after a merge without this pin; they measure 583k+ runs with zero master failures in the window, so I left them alone. Happy to extend the pin on request.

CIDB query and result (30 days, measured 2026-09-20)
SELECT if(pull_request_number = 0, 'master/release', 'PR') AS ref,
       countIf(test_status = 'OK')              AS ok,
       countIf(test_status = 'SKIPPED')         AS skipped,
       countIf(test_status IN ('FAIL','ERROR')) AS fail,
       uniqExact(commit_sha)                    AS shas
FROM default.checks
WHERE test_name = '05210_skip_index_type_from_alter_session_setting'
  AND check_start_time > now() - INTERVAL 30 DAY
GROUP BY ref ORDER BY ref
ref ok skipped fail shas
PR 618 5 0 87
master/release 214 0 1 29

The single failing row: Stateless tests (amd_tsan, parallel), 2026-09-19 23:37:18, ee32c21d2f6541c526f6d7fcef5062406aad7bd5, head_ref = master, pull_request_number = 0.


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

Version info

  • Merged into: 26.10.1.419-master (included in 26.10 and later)

…setting

`05210_skip_index_type_from_alter_session_setting` asserts an exact granule
count, `LIKE '%Granules: 16/32%'`, on the part left by `OPTIMIZE FINAL`: 128
rows at `index_granularity = 4` is 32 granules, and `idx` prunes the 16 that do
not hold `v = 1`. The table pins `index_granularity` and
`index_granularity_bytes` for exactly that reason, but not
`merge_max_block_size`, which the stateless runner randomizes from
`random.randint(1, 8192 * 3)` (`tests/clickhouse-test:2015`).

`merge_max_block_size` bounds the rows per merge output block, and the Compact
part writer computes granularity per written block,
`computeIndexGranularity(result_block)` at
`MergeTreeDataPartWriterCompact.cpp:257`. In `fillIndexGranularityImpl`
(`:501-510`) a block tail shorter than a full granule gets its own short mark
when `rows_left_in_block * 2 >= index_granularity_for_block`, which the comment
at `:507` describes as deliberate, and `getGranulesToWrite` then reports that
short granule as complete, so the next block starts a fresh mark instead of
filling it. At `merge_max_block_size = 110` the merge emits 110 + 18 rows and
writes 33 marks rather than 32, `v = 1` starts at mark 16, and the plan prints
`Granules: 17/33`. The literal stops matching and the assertion returns 0.

ClickHouse is correct at that value, and the invariant the test was added for
holds: the merge does not throw in `MergeTreeIndexAggregatorSet::update`,
`force_data_skipping_indices = 'idx'` raises no `INDEX_NOT_USED`, both counts
are still 64, and `idx` still prunes about half the granules. Only the
exact-count literal moved, so the fix belongs in the fixture.

Pinning the setting in the table's own `SETTINGS` clause is enforced rather than
best-effort: `ClientBase::addMergeTreeSettings` injects a randomized MergeTree
setting only when the clause does not already carry that name,
`if (!storage_settings.changes.tryGet(change.name))` at
`src/Client/ClientBase.cpp:3953`. Measured under the runner's own injection
form, a pinned table records `merge_max_block_size = 8192` while an unpinned one
records the injected 110. `8192` is the setting's own default
(`MergeTreeSettings.cpp:483`), so the test keeps running the configuration it
has passed 832 times under, and `.reference` is unchanged.

Measured over 14 values of `merge_max_block_size` from 1 to 8192: the 7 the
writer model predicts will break (3, 5, 7, 23, 63, 110, 127) all fail without
the pin and all pass with it, and the 7 it predicts are safe (1, 2, 4, 64, 100,
128, 8192) give `16/32` either way. A negative control that keeps the added
comment and reverts only the pin brings the failure back. 50 randomized runs
pass, with randomization confirmed live in `system.query_log`. The pin is also
sufficient for Wide parts and for vertical merges; the short-mark branch is
Compact-specific, since the Wide writer carries a partial mark across blocks
through `rows_written_in_last_mark` and gives `16/32` even at 110.

A `-- Random settings limits:` clamp was rejected. It is parsed out of a comment
and so fails silently when mistyped, it bounds only the random draw rather than
the table's own layout contract, and the conventional
`merge_max_block_size=(100, None)` floor used by 12 in-tree tests would not have
excluded the drawn 110, which measuring 100 as a good value confirms.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 20, 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; 0 findings), plus my own cold
re-review of the diff (1 nit, corrected before publication).

# Sev Finding Verdict Evidence / action
1 💡 The precedent count in the description counted stateless tests that mention merge_max_block_size, which also sweeps in merge_max_block_size_bytes and 9 tests whose only mention is a -- Random settings limits: clamp line AGREE, corrected in the description before publication Recounted as non-comment merge_max_block_size = in a CREATE TABLE clause, MODIFY SETTING and serverError lines excluded, deduplicated by test name: 50 tests, 49 of them not this one

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

The obvious question on a pin like this is whether it hides a real bug, so I checked that
independently of the fix author: at merge_max_block_size = 110 the short final mark is the writer's
documented intent (MergeTreeDataPartWriterCompact.cpp:507), OPTIMIZE FINAL completes,
force_data_skipping_indices = 'idx' raises no INDEX_NOT_USED, both counts are still 64, and idx
still prunes half the granules. Only the exact-count literal moved, and the Wide writer, which has no
short-mark branch, returns 16/32 even at 110.

Session id: cron:clickhouse-review-slot-9:20260920-020700

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

clickhouse-gh Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [75115b0]

Summary: ✅


AI Review

Summary

This PR pins merge_max_block_size in 05210_skip_index_type_from_alter_session_setting so the exact Granules: 16/32 assertion no longer depends on the stateless harness's randomized MergeTree settings. I did not find a correctness or coverage issue in the current change: the explicit table-level setting at tests/queries/0_stateless/05210_skip_index_type_from_alter_session_setting.sql wins over the harness injection on CREATE TABLE, and the test still exercises the same skip-index rebuild contract after the ALTER.

Missing context / blind spots
  • ⚠️ I could not rerun 05210_skip_index_type_from_alter_session_setting locally because this checkout has no build* directory. Fast test passed on the PR head, but the rest of the PR CI was still pending during review.
Final Verdict

✅ No findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2393163

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 02572_system_logs_materialized_views_ignore_errors flaky: that test's final SELECT orders by event_time_microseconds alone, which is not a total order, so two rows sharing a microsecond can come out either way. The failure is a pure row-order swap (queryfinish of the second system flush logs query_log against querystart of drop table log_proxy_02572), with no content change a fix task is created (investigating at full effort, fixing PR link to follow on this PR)
Mergeable Check, PR aggregators, red only because of the row above a fix task is created (the same one as above)

Not caused by this PR: the diff is one line in tests/queries/0_stateless/05210_skip_index_type_from_alter_session_setting.sql (it appends merge_max_block_size = 8192 to an existing table-level SETTINGS clause) and touches no source file, no materialized view and not 02572. The Linux Fast test on this same head passed, 02572 was the only failing test in the darwin job, and in the last 30 days the CI database has that test failing exactly once: this run, on no other pull request and never on master.

Session id: cron:our-pr-ci-monitor:20260920-100125

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the 02572_system_logs_materialized_views_ignore_errors ordering flake in the ledger above: #121183. It keys that test's final listing on script_query_number, type, the recorded statement order, so the listing no longer reads a clock.

pull Bot pushed a commit to infdahai/ClickHouse that referenced this pull request Sep 20, 2026
The final listing ordered by `event_time_microseconds`, which holds the
statement's start time on a `QueryStart` row and its end time on a
`QueryFinish` row. The committed reference is statement order, so that key
reproduced it only while every finish timestamp compared strictly less than
the next statement's start timestamp. Those are two independent clock reads
and the only margin between them is one client round trip, so when the margin
collapsed the sort was free to emit the other permutation, which is what the
failure below shows: identical content, two adjacent rows transposed.

`script_query_number` is the client's 1-based statement counter and the
QueryFinish log element is a copy of the QueryStart one, so both rows of a
statement carry the same value and `type` separates them. In this result set
`(script_query_number, type)` is unique per row, so the listing is ordered
without reading a clock at all. The reference is unchanged, which is the
cheapest proof the ordering semantics were preserved rather than redefined.

Failure this fixes, Fast test (arm_darwin):
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121126&sha=239316397592d4fd59cfac529b039ba88282c3be&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
ClickHouse#121126
@PedroTadim PedroTadim self-assigned this Sep 21, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Sep 22, 2026
Merged via the queue into ClickHouse:master with commit e15e033 Sep 22, 2026
177 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2026
alexey-milovidov added a commit that referenced this pull request Sep 22, 2026
Pulls in #121126, which pins `merge_max_block_size` in `05210_skip_index_type_from_alter_session_setting`, the only red of the previous CI run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. 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-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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