Repository navigation
Conversation
|
Workflow [PR], commit [fd0fe72] Summary: ❌
AI ReviewSummaryReviewed PR #130269 at Consumers checked: All five added stateless tests ( Final Verdict✅ Approve |
|
Workflow [PR], commit [fd0fe72] Summary: ❌
AI ReviewSummaryReviewed PR #130269 at Consumers checked: All five added stateless tests ( Final Verdict✅ Approve |
Related: #123531
Related: #128495
Background
The adaptive aggregator (
enable_adaptive_aggregator, enabled by default) lets every thread aggregate into its own hash table until the table holds 16,384 keys. Then the table freezes: a row whose key is in the table still updates it, and every other row, a miss, is staged as a record that the merge aggregates later. A record keeps what the merge needs from its row: the key and the arguments of the aggregate functions. The records of a thread go into buffers by the slice of the key hash their key falls in, its partition.Master combines misses only into
count()records, and only within a block. Every other miss stages a record of its own, so a query that keeps one row per key, such as a deduplication by the latest version, stages nearly every row with all its arguments:Over
hitssorted byEventTime, master stages 99.0 million records for its 100.0 million rows at 64 threads and needs 23.0 GiB. In the order ofhitsit needs more memory than the aggregation without the adaptive aggregator: 12.5 GiB against 11.5 GiB at 16 threads.What changes
Every thread now remembers the last record it staged into each partition, the partition's tail. A miss whose key equals the key of its partition's tail goes into that record instead of a new one, so the rows of a key that arrive close together end up in one record:
count()record adds the rows of the miss;argMax(x, ts),argMin(x, ts),max(ts)andmin(ts), optionally withanyandcount, the record keeps the best of its rows and the number of rows, which the merge adds tocount.For example, take five missed rows of one block, of two
UInt64keys A and B that fall into different partitions:count()argMax(x, ts), count()ts9) and 3 rows, B keeps row 5 (ts8) and 2 rowsThe selection applies when the ordering column is an integer, date, time,
Enum,IPv4,Decimal32orDecimal64column and no argument isNullable; other aggregations stage their rows as before. The results stay the same, except which of several rows with an equal ordering valueargMaxorargMinreturns, which parallel aggregation does not define anyway. The new settingadaptive_aggregator_combine_arg_min_max, enabled by default, turns the selections off.Results
AWS
c8a.16xlarge(64 cores, one thread per core),FORMAT Null, 5 runs per query with the average of runs 3 to 5, the binaries alternating run by run, against master.ClickBench has no query of this kind, so the table runs four with
clickhouse-localoverhitsin two orders: the order ofhits, where the rows of a user come in runs, and sorted byEventTimeinhits_by_time, where the rows of different users interleave. Peak memory is the peak of the query from--memory-usage.The five numbers are
RegionID,ResolutionWidth,CounterID,OSandAge.GROUP BY UserID:argMaxof 5 numbers byEventTime,hitsGROUP BY UserID:argMaxof 5 numbers byEventTime,hits_by_timeGROUP BY UserID:argMin(URL, EventTime),min(EventTime),hitsGROUP BY UserID:argMin(URL, EventTime),min(EventTime),hits_by_timeGROUP BY UserID:argMax(URL, EventTime),argMax(Title, EventTime),count,hitsGROUP BY UserID:argMax(URL, EventTime),argMax(Title, EventTime),count,hits_by_timeGROUP BY UserID:count,hits_by_timeOn
hits, 78% of the missed rows combine, and the selections need 54-69% less memory than master. Onhits_by_time, rows of other users often come between two rows of a user, so 26-28% of the missed rows combine at 16 threads and 33-37% at 64 threads.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
GROUP BYqueries that pick one row per group, such asSELECT id, argMax(name, updated_at), argMax(status, updated_at), max(updated_at) FROM t GROUP BY id, which keeps the latestnameandstatusof everyid, use less memory and run faster with the adaptive aggregator (enable_adaptive_aggregator, enabled by default). When every aggregate function isargMax,argMin,maxorminby the same integer, date or time column, optionally withanyandcount, the aggregator now keeps only the best of the rows of a group that arrive close together, instead of a copy of each of them until the end of the aggregation. On six such queries over the ClickBenchhitstable, the geometric mean speedup is 1.31x at 16 threads and 1.27x at 64 threads, up to 2.03x, and peak memory drops by 43% and 48%. The optimization is controlled by the new settingadaptive_aggregator_combine_arg_min_max, enabled by default.Workflow [PR]
Sync PR [sync-upstream/pr/130269]