Repository navigation
Conversation
… to load statistics Since ClickHouse#126627, a read whose parts do not have their statistics in memory runs the bounded primary key probe `MergeTreeDataSelectExecutor::hasFewerMarksToReadThan` to decide whether loading the statistics pays off. With more than one condition it ran three times over the same parts and key condition: in `getPartsForPrewhere` (pruning by statistics, then ordering PREWHERE) and again in `selectRangesToRead`. Memoize the per-part mark count found by the probe in `ReadFromMergeTree::Indexes`, like `SkipIndexOrderCache`. An entry is reused only for the same part ranges and the same number of key condition transformations: sampling adds a transformation to `indexes->key_condition` in place after the probe, and a later analysis of the same step must not get the count of the condition before sampling. Decisions are unchanged: same parts pruned, same PREWHERE order, same `use_statistics`. The measurement and the first version of the patch are by @ snelheidai in ClickHouse#126627 (comment). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the PrimaryKeyProbeCache comment to its invariant; drop three comments that restate the code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261112-210723 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261112-203700 |
|
Workflow [PR], commit [0f48ff6] Summary: ✅
AI ReviewSummaryReviewed #131129 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No required changes. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units307 translation units recompiled, 3234 s compile time in total, 307 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.93 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
The Iceberg configuration of the performance comparison rewrites the
MergeTree table of the test as an Iceberg table, where the fill query
`SELECT throwIf(count() != 500) FROM system.parts ...` throws (Code 395),
so the test produced no metrics and the report of every Iceberg job of
the pull request failed ("Errors while building the report.").
The test measures the statistics and the primary key analysis of
MergeTree parts and reattaches the table to reload the statistics, so it
has no meaning on Iceberg tables: opt it out with `<test iceberg="0">`.
The skip list is not used because a change to
`tests/performance/iceberg_skip_list.txt` counts as a change to the
Iceberg harness and runs the configuration on every selected test.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #126627
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 (every part after a restart or
ATTACH) runs the bounded primary key probeMergeTreeDataSelectExecutor::hasFewerMarksToReadThanto decide whether loading statistics pays off. With more than one condition it ran three times over the same parts and key condition: twice ingetPartsForPrewhereand once inselectRangesToRead. @ snelheidai measured it on ClickBench Q36-Q42 (#126627 (comment)).The per-part mark count found by the probe is now memoized in
ReadFromMergeTree::Indexes, likeSkipIndexOrderCache. This is the patch of @ snelheidai (#126627 (comment)) with one guard: an entry is reused only for the same part ranges and the same number of key condition transformations, because sampling adds a transformation to the key condition in place after the probe. Decisions are unchanged.Validation, RelWithDebInfo, master
63accaa2f95dvs this PR, new perf teststatistics_small_read_many_parts(500 parts afterDETACH/ATTACH):IndexBinarySearchAlgorithmper query 2000 -> 1000 (several conditions) and 1500 -> 1000 (one condition),LoadedStatistics0 on both, identical results andEXPLAIN indexes = 1, actions = 1.perf.py --runs 15, ratio PR / master in both server orders: 0.85 / 0.93 / 0.91 and 0.89 / 0.85 / 0.80 (p < 0.001).clickhouse-benchmarkagrees with the binaries swapped between ports; with the probe disabled (min_marks_per_part_to_load_statistics = 0) the difference is within the ~2 ms port noise.SAMPLEread analyzed twice probes again after sampling (16 binary searches, 12 without the guard) and decides like master.SAMPLEstateless tests pass (4 more needtest.hitsor MinIO); 18 statistics tests 50/50 with random settings.#130221 adds another
hasFewerMarksToReadThancall; whichever PR lands second should pass the cache there.Workflow [PR]
Sync PR [sync-upstream/pr/131129]