Repository navigation
Parallelize the final merge of single-level aggregation hash tables - #110395
Conversation
|
Workflow [PR], commit [da301c9] Summary: ✅
AI ReviewSummaryThis PR adds a new Findings
Final VerdictChanges requested until the setting contract matches the actual set of single-level methods that can use the new parallel merge. |
|
📊 Cloud Performance Report
Release-transition baseline: compared against the last 26.7 master because no 26.8 master baseline exists at or before the trusted base-commit anchor. This PR parallelizes the final merge of per-thread single-level aggregation hash tables (new setting enable_parallel_single_level_merge, defaulted on), splitting the key space into disjoint hash partitions merged independently. The ClickBench improvements line up cleanly with that: the wins are all GROUP BY queries (Q12, Q13, Q18, Q32-Q34, ×2 faster range in percent terms), while Q4 and Q5 have no GROUP BY and their small deltas are within master's normal variance. The one regression, TPC-H Q7 at +12.1%, is a low-cardinality GROUP BY where the extra partitioning/coordination overhead outweighs the parallelism — worth a look but consistent with the change's tradeoff. Q15 was suppressed as within-variance but exercises the same merge path, so it is surfaced as uncertain rather than a confirmed win. clickbench🟢 6 improved · Flagged queries (7 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🔴 1 regressed Flagged queries (1 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
Every failure in `Stateless tests (amd_tsan, flaky check)` on `b734075dd9f` was the 180 s per-run budget, not a wrong result: `03168_query_log_privileges_not_empty` (232 s and 199 s, passing at 94-145 s), `03008_optimize_equal_ranges` (185 s, passing at 158 s), `01343_min_bytes_to_use_mmap_io` (182 s, passing at 106 s) and `03735_async_insert_mergetree_count` (186 s, passing at 140-159 s). The three query-log ones failed on `SYSTEM FLUSH LOGS query_log` hitting its own 180 s timeout while the loaded TSan server drained the log queue. None of them is a signal this PR can produce: all three tests it touches are tagged `no-random-detach`, so the feature is off there and the change is the tag line itself; `03735_async_insert_mergetree_count` is not touched by this PR at all and fails the same way on unrelated pull requests (#110395, #110461). Tag them the same way as `03735_async_insert_mergetree` and the three tests tagged in `b734075dd9f`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=b734075dd9ff4ad835fa799a594445569fc02613&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| if (params->params.max_rows_to_group_by != 0 && params->params.group_by_overflow_mode == OverflowMode::ANY) | ||
| return false; | ||
|
|
||
| if (!params->aggregator.canMergeSingleLevelInPartitions(*data->at(0))) |
There was a problem hiding this comment.
enable_parallel_single_level_merge still misses several reachable single-level methods here. AggregatedDataVariants::chooseAggregationMethod returns nullable_key8 / nullable_key16 for Nullable(UInt8/UInt16), low_cardinality_key8 / low_cardinality_key16 for LowCardinality(UInt8/UInt16), and keys16 for fixed-key tuples that pack into 2 bytes, but worthParallelMergeSingleLevel only parallelizes plain key8 / key16 and this canMergeSingleLevelInPartitions check rejects the rest. So the new setting/docs still over-promise coverage: those GROUP BYs stay on the serial merge even with the setting enabled.
Please either extend one of the parallel merge paths to these variants, or narrow the setting text/tests so they explicitly say these small-key methods also remain serial.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 514/525 (97.90%) · Uncovered code |
|
@groeneai Investigate the CI failures. |
|
Both remaining reds on 1. The failing query in the report is from That is the AST fuzzer widening CREATE TABLE t_nan_asc (g UInt32, r Float64) ENGINE = MergeTree ORDER BY (g, r) SETTINGS index_granularity = 1;
INSERT INTO t_nan_asc VALUES (1, 3), (1, 5), (1, 0/0), (1, 0/0), (2, 7), (2, 0/0);
SELECT count() FROM t_nan_asc WHERE g = 1 AND r = 5 SETTINGS use_lightweight_primary_key_index_analysis = 0; -- 1
SELECT count() FROM t_nan_asc WHERE (g = toUInt128(1)) AND (r = 5) SETTINGS use_lightweight_primary_key_index_analysis = 0; -- abortsThe first statement returns The abort frame is Breadth over the last 60 days: 292 rows across 219 distinct pull requests and 16 master runs, first seen 2026-06-15, well before this branch. Per STID: 5182-2f27 = 209 rows / 170 PRs / 11 master; 5182-684a = 63 / 57 / 5. Note #111964 is not the owner for this shape: it suppresses the check only when the in-memory index does not resolve the whole used key prefix, and here both key positions are resolved with 2. One statement on a pristine master ASan+UBSan build, no table and no settings: SELECT toStartOfInterval(
reinterpret(toInt64(-9223372036854775808), 'DateTime64(9, \'Europe/Berlin\')'),
toIntervalHour(2),
reinterpret(toInt64(-9223372036854775808), 'DateTime64(9, \'Europe/Berlin\')'));That gives the same file, line and column as the CI report, Owner is #112045, which adds a Breadth over the last 60 days: 58 rows across 49 distinct pull requests and 7 master runs, first seen 2026-06-29. Neither is reachable from your diff. Your 18 changed files are the aggregator, the aggregating transform and plan step, settings and your two new tests; nothing under One thing on this PR that is worth your attention
1 failure in 100 runs, and the same 1-in-100 on the earlier head For the two stress reds, no action is needed on your side. Merging master once #112045 and #109023 land will clear them. |
|
@groeneai Why style check is falling in merge queue? |
|
It is not your diff and not a style violation. Only 1 of the 13 Style sub-checks fails, Root cause is a praktika bug in merge-queue event detection. Consequence: It is deterministic and unrelated to your change: the same single red on all three of your merge-queue refs ( Your entry itself is fine: A fix task is open on my side and I will post the fixing-PR link here when it opens. One caveat worth stating: fixing the predicate makes the settings-history validator actually run in the merge queue for the first time, so unrelated merge-queue entries touching that file may start showing genuine reds. |
|
@groeneai Create a PR fixing the issue. |
|
Acknowledged. I am opening a PR that fixes I will post the link here. |
|
@nihalzp the fix is open: #112227 It ships two of the three things I listed above:
The third item, making a real diff-fetch failure report its cause instead of the generic "no data Your PR needs no change. Once #112227 merges, the merge-queue run records the settings-history diff |
0f33598
|
Following up on the third item from #110395 (comment): it is now open as #112970. It routes the settings-history diff fetch through Nothing is needed on your side; #112227 already unblocked this PR. |
…the new join algorithm from ClickHouse#109005 - tests/clickhouse-test: randomize `allow_distinct_partitions_independently`, `force_distinct_partitions_independently`, `max_number_of_partitions_for_independent_distinct` and `enable_parallel_single_level_merge`. `force_*` is conditional on `allow_*`, because forcing is a no-op when the optimization is not allowed. - ci/jobs/scripts/stress/stress.py: add `parallel_full_sorting_merge` to the `join_algorithm` rotation (skipped in Upgrade check, because the previous release may not know this value). - BuzzHouse: add the four new settings next to their aggregate analogs. Related: ClickHouse#109005 Related: ClickHouse#108326 Related: ClickHouse#110395 Co-Authored-By: Claude Fable 5 <[email protected]>
In a parallel
GROUP BY, every thread aggregates into its own hash table. When those tables stay below the two-level threshold, the final merge combined them serially on one thread.This PR merges them in parallel: the key space is split into disjoint partitions by key hash, and each partition is merged independently by one of the threads — a merging thread reads all hash tables tables (this is okay because the hash tables are already small) and combines the keys that belong to its partition, so no two threads ever touch the same key. Controlled by the new setting
enable_parallel_single_level_merge(enabled by default).ClickBench:
TPCDS
Others
There are some slowdowns in the performance tests but none of them are related and they are already flaky in master (verified with Claude).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Parallelize the final merge of single-level aggregation hash tables: the key space is split into disjoint hash partitions that the threads merge independently (setting
enable_parallel_single_level_merge, enabled by default). Speeds upGROUP BYqueries whose per-thread hash tables stay below the two-level threshold but whose merge dominated the runtime.