Repository navigation
Conversation
The non-indexed path of `mergeSingleLevelPartitionsImpl` collected up to 16 cells of the partition and prefetched their destination slots before merging them. Measured on x86 over 31 cases (7 key types, 4-64 threads, destinations of 0.03-256 MiB), the prefetch paid off in none. With a warm allocator the plain per-cell loop is 7-22% faster in merge time in 15 cases and slower in none; with jemalloc purged before each run, as the performance tests do, the two loops measure equal. Results: ClickHouse#129565 (comment) 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; 0 findings) plus my own review of the diff (5 nits, all on the PR text; fixed in the description before publication, none in the code).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261113-132700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261113-131600 |
|
Workflow [PR], commit [79a2b1d] Summary: ❌
AI ReviewSummaryThe PR replaces the destination-prefetch batch in the non-indexed single-level Findings❌ Blockers
Tests
Final Verdict❌ Block. Close the destination-state ownership gap or link an issue explicitly tracking this pre-existing defect. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (-18.33 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 Compile time of recompiled translation units7 translation units recompiled, 128 s compile time in total, 7 of them have a recent master baseline. |
… throws The map `mergeDataImpl` (serial single-level merge, two-level bucket merge, parallel fixed hash map merge) and the non-indexed loop of `mergeSingleLevelPartitionsImpl` take the state of a key found in both tables out of the source table (`src = nullptr`) and queue it in a local `PaddedPODArray` for `mergeAndDestroyDetachedBatch`. Until that call nothing owns the queued states: a throw in between, e.g. `MEMORY_LIMIT_EXCEEDED` from the destination `HashTable::resize`, leaked their heap buffers, since the catches destroyed only the deferred pairs. ClickHouse#117153 made the window after the batch starts exception-safe; this closes the collection window before it. Extract the cleanup loop of `mergeAndDestroyDetachedBatch` into `destroyDetachedSources` and call it from a catch around the collection of `mergeDataImpl` (the JIT merge and the batch call stay outside the try, the batch owns the states from there) and from the existing catch of the partition merge. `flush_merges` clears its arrays in a `SCOPE_EXIT`, because the batch takes the states also when it throws, so a state is never destroyed twice. Deferred pairs come only from batches that started and the queued states only from batches that did not, so the two cleanups are disjoint. The new ONCE failpoint `aggregator_merge_collect_states_throw` throws at the end of a collection while states are queued. The test runs it on six paths in `clickhouse local`, whose LeakSanitizer check at exit aborts on a leak. `IAggregateFunctionHelper::mergeAndDestroyBatch` and the `-Tuple` combinator also destroy the rest of their batch when a merge throws, as `mergeAndDestroyBatchOrDefer` does; the second ONCE failpoint `aggregator_merge_batch_throw` tests a throw inside the batch in both merges. Related: ClickHouse#131315 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai Merge master. |
…ion-merge-no-prefetch Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged master in 79a2b1d; CI is re-running. |
Related: #129565
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Removed the destination prefetch batch from the parallel merge of single-level
GROUP BYstates, which did not pay off in any measured case.Description
28d8e94e660e7(in #110395) made the non-indexed path ofAggregator::mergeSingleLevelPartitionsImplcollect up to 16 cells of the partition and prefetch their destination slots before merging them. That path runs in the parallel merge of single-levelGROUP BYstates when the adaptive aggregator does not index the tables, for example with a singleNullablenumeric key, aLowCardinalitykey, orenable_adaptive_aggregator = 0. This PR goes back to the plain per-cell loop, the one the indexed and the string-table branches of the same function already use.@ diegomestre2 asked whether the prefetch pays (#129565 (comment)). I measured it on x86 (#129565 (comment)): it paid off in none of 31 cases (7 key types, 4-64 threads, destinations of 0.03-256 MiB). With a warm allocator the plain loop takes 0.78-0.93 of master's merge time in 15 cases and is slower in none. With jemalloc purged before each run, as the performance tests do, the two loops measure equal: query time 0.99-1.03 of master in the
UInt64andNullable(UInt64)cases with 3 million keys at 16 and 32 threads, on two servers with the binaries swapped between them (ratio = PR / master). So this PR claims no speed-up the performance tests could show and adds no performance test; the performance CI runs the existing tests that reach this loop. aarch64 was not measured locally.Results do not change:
merge_cellsees the same cells in the same order, the checksums of all 864 measured runs are equal, and the partition-merge stateless tests pass on debug and release builds.#129180 edits the
merge_cellcall inside the removed batch; whichever PR lands second resolves one line.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131315]