Skip to content

Pin the part layout in the prewhere_subcolumns performance test - #128387

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:perf-prewhere-subcolumns-pin-part-layout
Oct 31, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:perf-prewhere-subcolumns-pin-part-layout

Conversation

@groeneai

@groeneai groeneai commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

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 prewhere_subcolumns performance test now gives every server the same part layout, so its where n.null query no longer reports a false regression.

Description

Related: #119175 (same fixture pin). No related open issue found.

Performance Comparison (arm_release, master_head, 4/6) reported prewhere_subcolumns #1 (where n.null) as a confirmed +30% regression on 11 unrelated PRs on 2026-10-30/31, e.g. report 1, report 2.

The two servers measured different tables: the slower one read 784908 rows (229 marks), the other 130818 (39). The column statistics prune n.null to the one part holding row 0. The INSERT writes 8 parts, and a background merge of the first 6 can finish before perf.py --stop-merges stops merges, which happens only after both servers filled. The server that fills faster gives that merge more time, so a fill-speed difference between the two binaries decides the layout, and the confirmation reruns refill and repeat it.

The test now stops merges for its table before the INSERT and cuts parts by rows (max_insert_threads = 1, max_block_size = 65536, min_insert_block_size_rows = 131072, min_insert_block_size_bytes = 0), the same pin as join_convert_full_to_left_or_right.xml, then checks the layout with throwIf. The queries are unchanged; #1 reads 131072 rows on every server.

Validation with the official master build and two local servers: the master XML with the merge allowed to finish reads 784908 rows / 229 marks (3/3); perf.py --stop-merges with one server CPU-throttled reproduces the 784908 vs 130818 pair on master (2/2) and gives 131072 on both servers with this change (2/2, plus 3/3 unthrottled). Removing either pin makes the throwIf fail.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.992-master (included in 26.11 and later)

groeneai and others added 2 commits October 31, 2026 15:35
`where n.null` is pruned by the automatic column statistics (basic,
null_count) to the one part that holds row 0. The unpinned INSERT writes
8 parts (7 x 130818 + 84274 rows), and a background merge of parts 1-6
into a 784908-row part can complete before `perf.py --stop-merges` stops
merges, which it does only after BOTH servers finished their fill. The
server that fills faster gives that merge more time, so a fill-speed
difference between the two compared binaries decides which layout each
side measures: one server read 784908 rows / 229 marks, the other
130818 / 39, and the dashboard confirmed a +30% regression of query ClickHouse#1
on 11 unrelated PRs in Performance Comparison (arm_release, 4/6), where
the official build used as the reference filled in ~3.9 s vs ~2.7 s.
The confirmation reruns refill the table, so they repeat the asymmetry.

Stop merges for the table before the INSERT and cut the parts by rows
(max_insert_threads = 1, max_block_size = 65536,
min_insert_block_size_rows = 131072, min_insert_block_size_bytes = 0),
then assert the layout (8 parts, 7 x 131072 + 82496) with throwIf, the
same pin as join_convert_full_to_left_or_right.xml (ClickHouse#119175). Queries are
unchanged; query ClickHouse#1 now reads one 131072-row part on every server.

Validated with the official master build and two local servers: the
master XML with the merge allowed to finish reads 784908 rows / 229
marks (3/3); with the pin every trial reads 131072 rows and an OPTIMIZE
is refused; perf.py --stop-merges with one server CPU-throttled gives
784908 vs 130818 on master and 131072 on both servers with the pin;
removing either pin makes the throwIf fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous check accepted any 8-part layout with one 131072-row part;
the fill now requires 7 x 131072 + 82496 rows in block order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 2 rounds; 1 finding; plus my own cold review).

# Sev Finding Verdict Evidence / action
1 ⚠️ The layout throwIf checked only count() = 8 and max(rows) = 131072, so a different 8-part layout with row 0 in a smaller part would pass (prewhere_subcolumns.xml) AGREE, fixed @ e537a88 the fill now asserts the exact ordered layout [131072 x7, 82496]; the counterexample passes the old check and fails the new one

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:20261031-155900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Master XML on the official master build, merge allowed to finish before the global SYSTEM STOP MERGES: query #1 reads 784908 rows / 229 marks in 3/3 trials (the CI numbers). Through perf.py --stop-merges with one server CPU-throttled: 784908 vs 130818 rows on the two servers, 2/2.
b Root cause explained? where n.null is pruned by the column statistics to the one part holding row 0. The unpinned INSERT writes 8 parts and a background merge of parts 1-6 can finish before perf.py stops merges after both fills, so the server that fills faster ends with a 784908-row part and the comparison runs over two different tables.
c Fix matches root cause? Yes. The table's merges are stopped before the INSERT, parts are cut by rows, and the layout is asserted, so it no longer depends on merge timing or fill speed. No threshold, skip or no-random tag; queries unchanged.
d Test intent preserved / new tests added? Yes. #1 still measures a statistics-pruned read of one part (131072 rows, was 130818 in most runs); #0 and #2 still read all 1M rows. Test-only change.
e Both directions demonstrated? Yes. Master XML: 784908 rows (3/3); with this change: 131072 rows on every trial (9/9) and on both servers in 5/5 perf.py runs. Without either pin the throwIf raises Code: 395.
f Fix is general across code paths? The pin covers all three queries of the test (#0/#2 had 298 vs 293 marks on the two servers as well).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test fixture). The random string column has a constant width and parts are cut by rows, so the layout is identical on every server (asserted).
h Backward compatible? (maintainer-approved exception only) Yes. Test-only; all statements and settings exist in every reference build.
i Invariants and contracts preserved? Both compared servers measure the same part layout; the fill fails loudly if that ever stops holding.

Session id: cron:clickhouse-impl-slot-6:20261031-152400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @egor-click, could you review this and add the can be tested label so CI runs? The n.null query is pruned by column statistics to the part holding row 0, and a background merge that sometimes finished before perf.py --stop-merges gave the two servers different layouts (784908 vs 130818 rows read); the test now stops merges before the insert, cuts parts by rows and asserts the layout.

@clickhouse-gh

clickhouse-gh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e537a88]

Summary: ✅


AI Review

Summary

PR #128387 makes the prewhere_subcolumns performance fixture deterministic by stopping merges before insertion, setting row-based block boundaries, and asserting the exact ordered eight-part layout. Reviewed commit e537a887cf08e4fd5c0db27b809f31242a2922a2 and all prior discussion; no actionable findings. Runtime evidence consists of the before/after reproductions documented in the PR; these were not rerun locally because no ClickHouse binary is available.

Final Verdict

Status: ✅ Approve

@alexey-milovidov alexey-milovidov self-assigned this Oct 31, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 31, 2026
Merged via the queue into ClickHouse:master with commit 24037cf Oct 31, 2026
354 of 355 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 31, 2026
@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. 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.

4 participants