Skip to content

Pin the part layout of the read_in_reverse_order_final performance test - #122335

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-read-in-reverse-order-final-part-layout
Sep 26, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-read-in-reverse-order-final-part-layout

Conversation

@groeneai

@groeneai groeneai commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122073
Related: #121937

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

The read_in_reverse_order_final performance test now fills its table with a fixed layout of two parts and stops merges on it, so both servers measure the same parts.

Description

Performance Comparison (arm_release, master_head, 6/6) fails on unrelated PRs with this test as the only named result: #122222 (#0 0.0060 -> 0.0085 s, +40.6%, confirmed_regression; #1 +23.9%) and #122154 (#0 +37.5%, #1 +25.2%). Master reports it unstable too: 52a67f8f0e06, 5/6, 5.9 vs 8.9 ms.

Since #122073 the measured runs stop merges right after the fill. The fill writes 54 parts in about a second, so each server keeps whatever its merges reached: 21 vs 38 parts on #122222, 24 vs 44 on #122154, 22 vs 44 on that master run. FINAL ... ORDER BY x DESC LIMIT n reads the first reverse ranges of every part, about 23K rows each, so the side with more parts is slower. @ fm4v named this test in #121937 as one that needs its own fix.

The fill now merges the first insert (OPTIMIZE ... FINAL), stops merges on the table, writes the second insert as one part (min_insert_block_size_rows = 16777216, min_insert_block_size_bytes = 0), and a throwIf fails the job unless exactly 2 parts are active. This is the shape of final_read_in_order_limit.xml. The queries are unchanged.

Validated with two servers of one master release build and perf.py --stop-merges, 5 runs per side of the change: before, the servers read 14 to 19 parts, different in 5 of 5 runs, right/left up to 1.18; after, 2 parts and identical SelectedRows in 5 of 5, within 3%. Removing the OPTIMIZE or the insert settings makes the throwIf fire. The series will step down once (#0 5.7 -> 3.1 ms locally).


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

Version info

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

Since ClickHouse#122073 the measured perf.py runs stop merges on both servers right
after the fill. The old fill writes 54 parts in about a second, so each
server keeps whatever part set its background merges reached, and the two
servers of one run measure different layouts (21 vs 38 parts on ClickHouse#122222,
24 vs 44 on ClickHouse#122154, 22 vs 44 on master 52a67f8). FINAL ... ORDER BY
x DESC LIMIT n reads the first reverse ranges of every part (about 23K rows
each), so its time grows with the part count, and the dashboard scores the
side with more parts as a confirmed regression.

The fill now merges the first insert, stops merges on the table and writes
the second insert as exactly one part, so both servers read the same two
parts whatever the merge timing, like final_read_in_order_limit.xml:

- OPTIMIZE ... FINAL waits for the running merges before it selects, so
  the background merges of the first insert cannot leave it partial, and
  optimize_throw_if_noop = 1 makes a no-op OPTIMIZE fail with its reason
  instead of surfacing as a wrong part count.
- min_insert_block_size_rows = 16777216 (2^24, above the 10M rows) with
  min_insert_block_size_bytes = 0: the INSERT squashes on one stream before
  it fans out to the sinks and never reaches the minimum, so the whole
  insert is flushed as one part, independent of max_insert_threads,
  max_block_size and how the numbers_mt threads interleave.
- The throwIf over system.parts fails the job unless exactly 2 parts are
  active, because SYSTEM STOP MERGES on a missing table is a silent no-op.

Validated on two servers of one master release build with perf.py
--stop-merges, 5 runs per side of the change: before, 14 to 19 parts,
different on the two servers in every run, right/left up to 1.18; after,
2 parts and identical SelectedRows on both servers, right/left within 3%.

Related: ClickHouse#122073
Related: ClickHouse#121937

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Sep 25, 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 review (2 nits, below).

# Sev Finding Verdict Evidence / action
1 💡 The throwIf cannot detect a no-op per-table SYSTEM STOP MERGES, although the commit message gives that as its reason AGREE, noted-not-blocking Measured: without the OPTIMIZE the fill leaves 16 parts and without the insert settings 10 parts, and both fail the fill; without any stop the two parts did not merge in 130 s. So the oracle guards the OPTIMIZE and the single-part insert, and the per-table stop is defence in depth next to the harness's own stop.
2 💡 keep_merges_running="1" is not discussed as an alternative AGREE, noted-not-blocking It would let merges run during the measured queries again, so the layout would depend on timing and merges would compete with the queries, which is what #122073 removed. The pinned layout gives both servers the same 2 parts and identical SelectedRows with merges stopped.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-9:20260925-202800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Two servers of one master release build, perf.py --stop-merges: the old fill left 14 to 19 active parts, different on the two servers in 5 of 5 runs and never the 2 the new throwIf requires.
b Root cause explained? Yes. Since #122073 merges stop right after a ~1 s fill of 54 parts, so each server keeps a timing-dependent part set, and FINAL ... ORDER BY x DESC LIMIT n reads about 23K rows per part.
c Fix matches root cause? Yes. The fill builds a layout that does not depend on merge timing (merge, stop merges on the table, single-part second insert); no threshold or harness change.
d Test intent preserved / new tests added? Yes. Same table, data and queries; FINAL still merges across two parts. The throwIf fails the job if the layout ever differs.
e Both directions demonstrated? Yes. Before: 14 to 19 parts, right/left up to 1.18. After: 2 parts and identical SelectedRows on both servers in 5 of 5 runs, right/left within 3%.
f Fix is general across code paths? Yes for the class: no other test stepped at the #122073 merge with a left/right divergence. Checked with and without --stop-merges and with CI's flag set.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test fixture). Removing the OPTIMIZE or the insert settings makes the throwIf fire (16 and 10 parts).
h Backward compatible? (maintainer-approved exception only) Yes. No setting or default change; the fill runs unchanged on 25.3, 26.3, 26.8 and 26.9 with the same 2-part layout.
i Invariants and contracts preserved? Yes. Both servers hold the same parts during the measured runs; the global SYSTEM STOP MERGES replaces the table's lock with no gap, and the global start before teardown only precedes the drop.

Session id: cron:clickhouse-impl-slot-7:20260925-195700

@groeneai
groeneai requested a review from cwurm September 25, 2026 20:58
@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [45be1db]

Summary: ✅


AI Review

Summary

This PR stabilizes read_in_reverse_order_final by forcing a deterministic two-part layout before the measured FINAL ... ORDER BY x DESC LIMIT queries: it merges the first insert, stops table-local merges, forces the second insert into one part, and asserts the resulting layout. I did not find a correctness, compatibility, or benchmark-contract issue in the change; the harness still exercises the intended reverse-order FINAL path and now fails closed if the part layout drifts.

Final Verdict
  • Status: ✅ Approve

@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Sep 26, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 26, 2026
Merged via the queue into ClickHouse:master with commit 171f5ef Sep 26, 2026
176 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 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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