Skip to content

Pin the part layout of the lazy_final_early_exit_limit performance test - #122660

Merged
egor-click merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-lazy-final-early-exit-limit-part-layout
Sep 28, 2026
Merged

egor-click merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-lazy-final-early-exit-limit-part-layout

Conversation

@groeneai

@groeneai groeneai commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120186 (comment)

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 lazy_final_early_exit_limit performance test now writes each of its two inserts as exactly one part, so both compared servers read the same table.

Description

Performance Comparison (arm_release, master_head, 5/6) failed on #120186 with this test as its only red reason: job, #0 20.7 -> 24.4 ms and #1 30.4 -> 36.3 ms, both confirmed_regression. That PR removes a Distributed setting these queries do not use; the new server read 31% more rows for both (16 parts on each side). Master shows the same shift between near-identical builds: d122a9ff658f, #1 +21.5% rows, +17.2% time.

Each insert squashes numbers_mt blocks in thread-arrival order and cuts a part once 1,048,449 rows have accumulated, so it writes 8 parts with timing-dependent key ranges. Both servers are filled concurrently with merges stopped, so each measures its own layout, and #0/#1, which stop at their LIMIT, read a layout-dependent number of rows. In 150+ arm runs since 2026-09-27, the two servers read different row counts in 99-100% of runs, and time follows rows (correlation 0.93 / 0.90).

Both inserts now set min_insert_block_size_rows = 10000000, min_insert_block_size_bytes = 0 (an insert is ~350 MB, above the 256 MiB default), so each writes exactly one part, and a throwIf fails the job unless 2 parts are active. That is the "2 intersecting parts" fixture the test was measured with, and the shape of #122479. Only the fill changes; each query's lazy FINAL decision is unchanged.

Validated with the master release build (amd64): two concurrent fills built different layouts in 6 of 6 runs before and the same two parts in 6 of 6 after. Under perf.py --stop-merges, one server read 5% more rows for #1 in 2 of 3 runs before; after, both read identical rows from byte-identical parts in 3 of 3. The per-run early-exit race of #0 remains, and the fill takes ~1.5 s longer. Releases 25.3 to 26.9 (six tested) also get 2 parts.

🤖 Generated with Claude Code


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

Version info

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

Each fill INSERT squashes the numbers_mt stream in the order the SELECT
threads deliver its 65409-row blocks and cuts a part once
min_insert_block_size_rows (1048449) rows have accumulated, i.e. every 17
blocks, so each INSERT writes 8 parts whose key ranges depend on thread
timing. perf.py fills both servers at the same time and merges stay
stopped, so the two servers of a comparison measure different 16-part
tables for the whole test. Queries #0 and ClickHouse#1 stop at their LIMIT and read
a layout-dependent number of rows: on ClickHouse#120186 the new server read 31%
more rows for both, and the dashboard gate reported +17.9% and +19.3% as
confirmed regressions.

Both INSERTs now set min_insert_block_size_rows = 10000000 (above the
8000000 rows of an INSERT) and min_insert_block_size_bytes = 0 (an INSERT
is ~350 MB, so the 256 MiB default would still cut it in two). Each INSERT
becomes one block, sorted by the key when written, so both servers get the
same two intersecting parts, the fixture the test was measured with. A
throwIf fill query fails the test if the table does not have exactly 2
active parts. max_insert_threads cannot do this: it only fans the squashed
blocks out to the insert sinks.

Co-Authored-By: Claude Opus 5.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 28, 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 (0 findings). Nothing to adjudicate.

Session id: cron:clickhouse-review-slot-11:20260928-102100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Two concurrent clickhouse local fills with the test's own create/fill queries built different 16-part layouts in 6 of 6 runs (8 and 12 threads); real perf.py --stop-merges on two servers: #1 read 5% more rows on one server in 2 of 3 runs.
b Root cause explained? Each fill insert squashes numbers_mt blocks in thread-arrival order and cuts a part once 1,048,449 rows have accumulated, so it writes 8 parts with timing-dependent key ranges; both servers are filled concurrently with merges stopped, so they measure different tables, and #0/#1 stop at their LIMIT after a layout-dependent number of rows.
c Fix matches root cause? Yes. Each insert becomes one squashed block, hence one sorted part that does not depend on arrival order. No thresholds, run counts or marks changed.
d Test intent preserved / new tests added? Yes. Queries unchanged; EXPLAIN shows the same lazy FINAL decision for all three; #2 stays 4.7x faster with lazy FINAL (4.8x before); the scan a wrongly applied lazy FINAL adds is 2.0x / 1.3x of #0 / #1 (1.7x / 1.1x before). The new throwIf fails the job if the layout drifts (checked: the old fill fails it).
e Both directions demonstrated? Yes. Layouts: 6 of 6 different before, 6 of 6 identical after. perf.py: #1 rows differed beyond the per-server range in 2 of 3 runs before, identical from byte-identical parts in 3 of 3 after. Same-server A/A: #1 rows equal in 5 of 5 fresh fill pairs after.
f Fix is general across code paths? N/A for engine code (test-only). All three queries share the one fixture; both inserts are changed.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked at 8 and 12 threads and on releases 25.3, 26.3, 26.5, 26.6, 26.8, 26.9: always exactly 2 parts. Type wrappers N/A.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, default or format change; only this test's fill.
i Invariants and contracts preserved? Both compared servers read the same table (parts byte-identical under perf.py); merges stay stopped; re-runs re-create the same layout; the throwIf enforces 2 active parts.

Session id: cron:clickhouse-impl-slot-41:20260928-093500

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7593f8f]

Summary: ✅


AI Review

Summary

This PR stabilizes the lazy_final_early_exit_limit performance fixture by forcing each setup INSERT to produce one part and by asserting that the table ends up with exactly two active parts before measurement. I reviewed the changed XML, the relevant min_insert_block_size_* / use_strict_insert_block_limits semantics in the insert pipeline, the performance harness setup ordering, and the prior PR discussion, and I did not find a new correctness or reliability issue in the current diff.

Final Verdict

✅ No findings.

@egor-click
egor-click added this pull request to the merge queue Sep 28, 2026
Merged via the queue into ClickHouse:master with commit ac31ad6 Sep 28, 2026
149 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
shankar-iyer pushed a commit to shankar-iyer/ClickHouse that referenced this pull request Oct 2, 2026
…test

The two compared servers each built a different copy of the fixture:

- `rand64() % 5000000` makes the number of rows with key 5, which queries
  ClickHouse#1 and ClickHouse#3 look up, a fresh draw per server (0 to 3 over 10 local fills);
- each INSERT is squashed into ~5 parts (cut at min_insert_block_size_rows),
  which merge until perf.py's --stop-merges freezes them at a per-server
  point.

ClickHouse#1 and ClickHouse#3 read about one granule per part, so each server read its own
number of granules: in CI the servers read different parts in 80% of runs,
and time follows the rows read (correlation 0.85-0.88). This redded
unrelated PRs (e.g. ClickHouse#118662, arm 4/6, ClickHouse#1 +37.5% confirmed_regression) and
inflated the learned threshold of ClickHouse#1/ClickHouse#3 to 0.41-0.53 (0.04-0.09 for
#0/ClickHouse#2/ClickHouse#4 on the same tables); the dashboard now caps both at
likely_regression as "Flaky lately", so a real regression there cannot red.

Use deterministic data, cityHash64(number, 7) and cityHash64(number, 11)
modulo 5000000 (same key range and duplicate profile; the seeds put key 5
once in each table, the modal case of the random draw, so ClickHouse#1/ClickHouse#3 keep
measuring a non-empty point join), and write each table as one part with
min_insert_block_size_rows = 10000000, min_insert_block_size_bytes = 0
(5M rows give one squashed block). A throwIf on system.parts fails the
fill if the layout ever drifts. Same shape as ClickHouse#122479 and ClickHouse#122660.

Validated through perf.py --stop-merges on two servers, 5 fresh fills per
arm: new fixture identical on all 10 server fills (one part per table, same
data, ClickHouse#1/ClickHouse#3 read 2 granules on both, #0/ClickHouse#2/ClickHouse#4 read 10M rows); old fixture
different on all 5 iterations. Without the insert settings the throwIf
fails the fill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. 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-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. 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