Skip to content

Faster Adaptive Aggregator - #123531

Merged
nihalzp merged 249 commits into
ClickHouse:masterfrom
nihalzp:faster-adaptive-aggregator
Oct 26, 2026
Merged

nihalzp merged 249 commits into
ClickHouse:masterfrom
nihalzp:faster-adaptive-aggregator

Conversation

@nihalzp

@nihalzp nihalzp commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Related: #111459

ClickBench hits (100M rows) on AWS c8a.16xlarge (64 cores, one thread per core), FORMAT NULL. Master already runs Adaptive Aggregator. So, the speedups are on top of the runtime improvements of #111459.

Query Shape Master → PR (16 threads) Speedup (16 threads) Master → PR (64 threads) Speedup (64 threads)
Q8 GROUP BY RegionID: count(DISTINCT UserID) 189.3 → 141.4 1.34× 214.2 → 73.3 2.92×
Q9 GROUP BY RegionID: sum, count, avg, count(DISTINCT UserID) 207.0 → 170.6 1.21× 225.8 → 78.9 2.86×
Q12 GROUP BY SearchPhrase: count, where SearchPhrase <> '' 103.3 → 77.7 1.33× 54.2 → 47.8 1.13×
Q13 GROUP BY SearchPhrase: count(DISTINCT UserID), where SearchPhrase <> '' 152.4 → 104.7 1.46× 87.8 → 59.4 1.48×
Q14 GROUP BY SearchEngineID, SearchPhrase: count, where SearchPhrase <> '' 129.7 → 97.5 1.33× 68.1 → 55.0 1.24×
Q15 GROUP BY UserID: count 83.8 → 43.5 1.93× 42.5 → 26.5 1.60×
Q16 GROUP BY UserID, SearchPhrase: count 243.0 → 161.8 1.50× 124.7 → 85.2 1.46×
Q18 GROUP BY UserID, minute(EventTime), SearchPhrase: count 391.8 → 241.4 1.62× 233.1 → 120.0 1.94×
Q30 GROUP BY SearchEngineID, ClientIP: count, sum, avg, where SearchPhrase <> '' 74.7 → 59.9 1.25× 40.1 → 35.6 1.13×
Q32 GROUP BY WatchID, ClientIP: count, sum, avg 478.0 → 180.4 2.65× 275.1 → 110.2 2.50×
Q33 GROUP BY URL: count 448.9 → 414.7 1.08× 238.2 → 192.9 1.23×
Q34 GROUP BY 1, URL: count 444.0 → 406.3 1.09× 241.0 → 196.4 1.23×
Q35 GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3: count 78.0 → 39.4 1.98× 38.9 → 25.2 1.54×
Geomean 1.47× 1.62×

Additionally, this PR improves GROUP BY spilling for Adaptive Aggregator path significantly. For the same machine at 64 threads with max_bytes_before_external_group_by = 500 MiB.

Query Shape master, adaptive off master, adaptive on PR PR vs master adaptive on PR vs master adaptive off
Q8 GROUP BY RegionID: count(DISTINCT UserID) 322 ms, 526 MiB 366 ms, 518 MiB 342 ms, 611 MiB 1.07× 0.94×
Q9 GROUP BY RegionID: sum, count, avg, count(DISTINCT UserID) 486 ms, 547 MiB 449 ms, 536 MiB 501 ms, 613 MiB 0.90× 0.97×
Q12 GROUP BY SearchPhrase: count, where SearchPhrase <> '' 378 ms, 1,008 MiB 966 ms, 703 MiB 116 ms, 817 MiB 8.35× 3.27×
Q13 GROUP BY SearchPhrase: count(DISTINCT UserID), where SearchPhrase <> '' 652 ms, 1,540 MiB 1808 ms, 907 MiB 170 ms, 744 MiB 10.61× 3.83×
Q14 GROUP BY SearchEngineID, SearchPhrase: count, where SearchPhrase <> '' 607 ms, 1,241 MiB 1104 ms, 743 MiB 147 ms, 768 MiB 7.52× 4.14×
Q15 GROUP BY UserID: count 364 ms, 755 MiB 588 ms, 720 MiB 69 ms, 619 MiB 8.56× 5.31×
Q16 GROUP BY UserID, SearchPhrase: count 1219 ms, 2,477 MiB 1840 ms, 1,497 MiB 249 ms, 904 MiB 7.38× 4.89×
Q18 GROUP BY UserID, minute(EventTime), SearchPhrase: count 2450 ms, 4,290 MiB 2914 ms, 3,371 MiB 373 ms, 1,368 MiB 7.81× 6.56×
Q30 GROUP BY SearchEngineID, ClientIP: count, sum, avg, where SearchPhrase <> '' 282 ms, 522 MiB 603 ms, 669 MiB 44 ms, 482 MiB 13.70× 6.41×
Q32 GROUP BY WatchID, ClientIP: count, sum, avg 2585 ms, 4,988 MiB 3516 ms, 4,180 MiB 332 ms, 1,331 MiB 10.60× 7.79×
Q33 GROUP BY URL: count 3402 ms, 7,307 MiB 3457 ms, 7,384 MiB 623 ms, 978 MiB 5.55× 5.46×
Q34 GROUP BY 1, URL: count 3453 ms, 7,423 MiB 3457 ms, 7,508 MiB 621 ms, 1,000 MiB 5.57× 5.56×
Q35 GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3: count 263 ms, 703 MiB 526 ms, 767 MiB 36 ms, 507 MiB 14.78× 7.38×
Geomean 6.22× 4.09×
Geomean without Q30 5.83× 3.94×

Q30 does not spill for Adaptive Aggregator because the algorithm uses less memory than 500 MiB.

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

GROUP BY queries with many distinct keys run faster with the adaptive aggregator (enable_adaptive_aggregator, enabled by default). Across 13 ClickBench aggregation queries, speedups reach 2.9x, with geometric mean speedups of 1.62x at 64 threads and 1.47x at 16 threads. The adaptive aggregator's profile events are reworked to match: AdaptiveAggregationGiveUps, AdaptiveAggregationPressureDrainedRecords, AdaptiveAggregationPressureStandDowns, AdaptiveAggregationPressureSweeps, AdaptiveAggregationResidueReleases, AdaptiveAggregationSealNormalizations, AdaptiveAggregationSealedChunks, AdaptiveAggregationSharedTableSpills, AdaptiveAggregationSpillBacklogSheds, AdaptiveAggregationStagedChunkPiecesOverBound, AdaptiveAggregationStagedChunkSplits, AdaptiveAggregationStagedClaimsClosedAtBound and AdaptiveAggregationStagedRecordsMerged are removed, and AdaptiveAggregationSpills, AdaptiveAggregationSpilledRecords, AdaptiveAggregationSpilledBytes, AdaptiveAggregationFrozenTableSpills, AdaptiveAggregationMergeUnits, AdaptiveAggregationPrunedUnits, AdaptiveAggregationPrunedRecords and AdaptiveAggregationCountFirstUnits are added.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [29df2b4]

Summary: ✅


AI Review

Summary

PR #123531 reworks adaptive aggregation around partitioned records, streamed spills, parallel merges, and bucket top-K pruning. The benchmark evidence supports the performance improvements. No actionable findings remain at 29df2b414c02e8d5fa37d2b8a9a9a3f070ffce16; the previous staged-reader input-progress finding is fixed and its thread is resolved.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 2, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). label Oct 2, 2026
Comment thread src/Interpreters/AdaptivePartitions.h Resolved
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 3, 2026
@fm4v fm4v removed pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR v26.10-must-backport labels Nov 3, 2026
qoega pushed a commit to qoega/ClickHouse that referenced this pull request Nov 5, 2026
Since ClickHouse#123531 the numbers_mt 400k-700k queries of this test take one of two
run times per run on arm CI (about 6.7 or 9.9 ms for 500k) with the same CPU
time. numbers_mt opens floor(N / 65409) streams, so these sizes aggregate in
6-10 streams and then fan out to 12 output streams. With max_threads = 4
every size from 300000 rows on reads, aggregates and outputs in 4 streams.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-relocation-headroom-ok Accept an expected decrease of the relocation headroom in the build check comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

5 participants