Repository navigation
Load the primary indexes of parts in parallel when deciding whether to load statistics - #131667
Conversation
`hasFewerMarksToReadThan` (added in ClickHouse#126627) analyzes the primary key of the parts one after another to decide whether loading statistics pays off. Analyzing a part loads its primary index when it is not in memory, so after a restart or `ATTACH` the first selective read loads the indexes of its parts serially during plan optimization, before the index analysis of the read, which would load them in parallel. Analyze the parts in windows of `num_threads` consecutive parts. A window in which more than one primary index is not in memory (neither loaded nor in the primary index cache, see the new `IMergeTreeDataPart::isIndexInMemory`) is analyzed in a thread pool, then consumed in part order with the same early return as before, and the next window starts only after that. The decision and the exception are those of the serial analysis; at most `num_threads - 1` parts after the stopping part are analyzed in addition. Hot reads, `max_threads = 1` and windows with at most one index to load are analyzed in the calling thread as before. Reported by @ snelheidai: ClickHouse#126627 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test checked only the decision of the probe, which the parallel analysis preserves by construction, so it stayed green if the parts were analyzed serially, and the primary index cache path was never run. Count, per read, the probes that analyzed the parts in parallel through the existing trace line in `system.text_log`, and add a read with `use_primary_key_cache = 1`, where an index in the cache counts as in memory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the window-probe comment to its ordering invariant and drop the pool's creation narration, keeping the destruction-order invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (2 rounds)Pre-publication review by an independent model (engine: codex; round 1: 1 finding, round 2: 0) plus my own cold review of each round.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261114-170501 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261114-112900 |
|
Workflow [PR], commit [471046d] Summary: ✅
AI ReviewSummaryThe PR parallelizes cold primary-index loading in Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+17.92 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units289 translation units recompiled, 3072 s compile time in total, 289 of them have a recent master baseline. |
d6fa719
is the same fix) Upstream ClickHouse#131667 (merged 2026-11-15) loads the statistics probe's primary indexes in parallel the same way, so the branch is not to be submitted. Run 1 of the A/B (-6.1%) had 2 of the 13 serial index loads in its window; gen.sh now writes query.sql for the data it generates, and the lab README says what a cold T1 run should select. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #126627
Related: #126627 (comment)
Related: #131129
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Since #126627, a read whose parts do not have their statistics in memory first runs
hasFewerMarksToReadThan, a bounded primary key probe, to decide whether loading statistics pays off. The probe analyzes the parts one after another, and analyzing a part loads its primary index if it is not in memory, so after a restart orATTACHthe first selective read loads the indexes of its parts serially during plan optimization, while the read's own index analysis loads them in parallel.The probe now takes windows of
num_threadsconsecutive parts. A window with more than one index not in memory (newIMergeTreeDataPart::isIndexInMemory, which also checks the primary index cache) is analyzed in a thread pool, then consumed in part order with the same early stop, so the decision and the exception are those of the serial probe, and at mostnum_threads - 1extra parts are analyzed. Hot reads andmax_threads = 1keep the serial path.RelWithDebInfo, ClickBenchhitsin 12 parts with default statistics, cold (restart, page cache evicted,SELECT count(), query), 8 rounds, ratio = PR / master. EBS, 4 threads: Q37/Q40/Q41/Q42 0.69/0.65/0.67/0.64 (plan optimization ~310 ms -> ~110 ms; 1.6 ms without statistics); 16 threads: 0.47-0.52. NVMe, 4 threads: Q40-Q42 0.78-0.84, Q36-Q39 within noise. Hot (hits; a 500-part table): within noise, except that withuse_primary_key_cacheon 500 parts the cache lookups of the in-memory check add ~0.5 ms of planning (ratios 1.00-1.06). Selected parts, marks and results are identical. Performance tests prewarm every query and cannot see this. The new test checks that the probe runs in parallel only while the indexes are not in memory (also with the primary index cache) and decides as the serial one.Independent of #131129 (memoization of the same probe); whichever lands second resolves a small conflict.
Workflow [PR]
Sync PR [sync-upstream/pr/131667]
Version info
26.11.1.2336-master(included in26.11and later)