Repository navigation
Conversation
|
Workflow [PR], commit [63c177f] Summary: ❌
AI ReviewSummaryEnables adaptive Performance & SafetyThe completed comparison at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
…dinary aggregation path
Build profile diff (arm_release)Commit See the job log for details. |
Queries 0 and 2 of tests/performance/group_by_dynamic_keys.xml take 2.79 / 1.56 s on MasterCI amd (3.51 / 1.90 s on arm); the String control takes 0.13 s. Every row is its own group (the key moduli are pairwise coprime), and 65-86% of CI's CPU samples are in the per-row key serialization of the serialized method (ColumnDynamic::serializeValueIntoArena), which the file measures. No existing query number or text changes: 2 queries are disabled and 2 copies appended as 3 and 4. The copies run the same queries on 400k rows (still one group per row). The JSON fill is read only by the disabled query, so it is renamed and resized in place to t_json_group_by_400k, the first 400k of the same rows. The String control keeps its 2M rows. Local A/B on official builds, two repetitions on different NUMA nodes, L3 capped to one way (decide.py: every gate passes in both): - user time per row of a copy 0.948 (Dynamic casts) and 1.009-1.016 (JSON subcolumns) of its original; - local time ratio copy/original 0.191 and 0.403-0.408 -> projected CI medians 0.53 / 0.63 s amd, 0.67 / 0.78 s arm; - on the MasterCI builds before and after ClickHouse#112316 (7a9ada8 -> 6e89ba5, CI measured 1.26-1.32x on amd, 1.52x on arm), the copies keep 0.836-0.919 of the original's speedup, both seat orders; - on the build of ClickHouse#131331 each copy takes its original's adaptive aggregation path. Below 500k groups a repeated run gets no hash table size hint (HashTablesStatistics getSizeHint at max_threads = 1), so the copies start their table single-level and unallocated where the originals start it two-level and preallocated; that table is about 1% of CI's samples. Saving: about 32 s of query time per master perf job on amd and 40 s on arm; the setup fills 400k JSON rows instead of 1M. Related: ClickHouse#129258 Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
…or-single-stream # Conflicts: # src/Interpreters/Aggregator.cpp # src/Interpreters/HashTablesStatistics.h
…ver takes the adaptive path
…the previous state
…ion of a `Nullable` key
|
In the CI performance tests, 62 queries sped up by 1.76x and 95 use 51% less memory, both in geomean. Some queries slowed down by a few milliseconds due to the fixed cost of the adaptive aggregator, which is an acceptable tradeoff but can be improved. @groeneai Investigate it and propose fixes. Discussed it with @Algunenano. Merging this to unlock further development. |
|
Acknowledged. I'm investigating the fixed-cost slowdowns of the adaptive aggregator on the single-stream |
…K offer of the NULL key
…ined_memory_usage`
Related: #130520
Related: #129565
Background
With the adaptive aggregator (
enable_adaptive_aggregator), every thread aggregates into its local hash table until the table freezes atadaptive_aggregator_freeze_thresholdkeys oradaptive_aggregator_freeze_threshold_bytesbytes. A frozen table keeps updating the keys it holds and stages the rows of the other keys, which the merge aggregates one hash partition at a time, in tables that fit in the cache.Master uses it only with several threads and several input streams. Otherwise the aggregation builds ordinary hash tables, and with one input stream a single table holds every key of the query. ClickBench Q32 at
max_threads = 1:Its 99,997,497 rows hold 99,997,493 groups, so the table outgrows every cache: the query peaks at 6,160 MiB and takes 6.9 s.
Master also leaves out every aggregation whose
group_by_two_level_thresholdandgroup_by_two_level_threshold_bytesare both 0, and ClickHouse sets both to 0 for an aggregation of one stream unless external aggregation is enabled.Changes
The adaptive aggregator now takes a
GROUP BYatmax_threads = 1and one over a single input stream. Its tables freeze as with several threads, and the merge aggregates the staged rows partition by partition.WITH TOTALS,ROLLUPorCUBE. So aGROUP BY ... WITH TOTALSatmax_threads = 1takes the adaptive path by default, and keeps the ordinary path, as on master, when external aggregation is off.Results
ClickBench
hits(100M rows) on AWSc8a.16xlarge,clickhouse-local,max_threads = 1,FORMAT Null. Peak memory is the peak of the query from--memory-usage.GROUP BY SearchPhrase:count, whereSearchPhrase <> '', top 10GROUP BY SearchPhrase:count(DISTINCT UserID), whereSearchPhrase <> '', top 10GROUP BY SearchEngineID, SearchPhrase:count, whereSearchPhrase <> '', top 10GROUP BY UserID:count, top 10GROUP BY UserID, SearchPhrase:count, top 10GROUP BY UserID, minute(EventTime), SearchPhrase:count, top 10GROUP BY SearchEngineID, ClientIP:count,sum,avg, whereSearchPhrase <> '', top 10GROUP BY WatchID, ClientIP:count,sum,avg, whereSearchPhrase <> '', top 10GROUP BY WatchID, ClientIP:count,sum,avg, top 10GROUP BY URL:count, top 10GROUP BY 1, URL:count, top 10GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3:count, top 10Run time:
Memory usage:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The adaptive aggregator (
enable_adaptive_aggregator, enabled by default) now also handlesGROUP BYatmax_threads = 1and over a single input stream, and final aggregations with bothgroup_by_two_level_thresholdandgroup_by_two_level_threshold_bytesset to 0. The thread stops growing its hash table at the freeze threshold and aggregates the rows of new keys at the end, one cache-sized partition at a time. On 12 ClickBench queries with millions of distinct keys atmax_threads = 1, the geometric mean speedup is 1.56x, up to 2.74x, and peak memory drops by 47%.Workflow [PR]
Sync PR [sync-upstream/pr/131331]