Repository navigation
Add aggregation memory tracker for two-level conversion - #107490
Conversation
|
Workflow [PR], commit [a4bec74] Summary: ✅
AI ReviewSummaryThis PR scopes the two-level aggregation conversion decision to memory attributed to non-merge aggregation work, keeps the merge path on query-memory delta accounting where input aggregate states may already own memory, and adds a profile event plus focused tests for the false-positive conversion case. I did not find any remaining blocker or major issue in the current diff; the previously open fallback-baseline bot thread is fixed in the current code and has been resolved. Final VerdictStatus: ✅ Approve |
|
📊 Cloud Performance Report 🟢 AI verdict: This PR changes the runtime decision for converting aggregation hash tables to two-level so it is driven by the aggregation's own state memory rather than total query memory. ClickBench Q4, Q15, and Q28 are all aggregation/GROUP BY queries and improved by -16%, -19.6%, and -6% respectively, each consistent across both tests with low measurement noise. These improvements map directly onto the path the PR modifies: avoiding unnecessary two-level conversion for aggregations whose own state is small, so the verdicts are well-supported by the change. clickbench🟢 3 improved Flagged queries (3 of 43)
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🟢 No significant changes Debug info
|
nickitat
left a comment
There was a problem hiding this comment.
Conceptually, IMO, it is right for the aggregation to track only its own memory, because the description of the group_by_two_level_threshold_bytes implies that quite unambiguously.
I'd explicitly ensured that the conversion on the merge stage is still working properly. Let's add a test that ensures all pre-aggregation tables remain single-level, are converted only during merge, and that it still happens.
Seems like conversion during merge only triggers if at least one of the tables was converted during execution, so this case shouldn't happen, is that what you meant? |
Yeah, I confused myself here. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 37/39 (94.87%) · Uncovered code |
…reVariantsToMerge When some per-thread aggregation states converted themselves to two-level mid-scan (after the accurate aggregation memory accounting from ClickHouse#107490 made `group_by_two_level_threshold_bytes` engage for queries with few groups but heavy states, e.g. uniqExact), the merge preparation converted all the remaining single-level variants sequentially on one thread. Initializing a two-level variant allocates and zeroes 256 bucket tables, and there is one variant per query thread, so on machines with many cores this serial loop dominates short aggregation queries: ClickBench Q10/Q11 on c7a.metal-48xl (192 cores) regressed 2-3x. Convert the variants in parallel on the aggregator thread pool instead. Bisected and validated on c7a.metal-48xl via ClickBench manual runs: ClickHouse/ClickBench#1360 Closes: ClickHouse#114640
…ry-usage-accounting Add aggregation memory tracker for two-level conversion
The Aggregator used
current_memory_usage - memory_usage_before_aggregationto decide whether to switch to two-level aggregation or not. Sincememory_usage_before_aggregationwas recorded at construction time it reflected the memory usage during pipeline build, so the difference tocurrent_memory_usagecould include more than the aggregation memory (e.g. memory held by a join hash table lower in the pipeline). This leads to converting small aggregations to two-level.This PR attempts to attach a memory tracker in the Aggregator to account only for the aggregation state.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Avoid converting single-level aggregations with small memory usage to two-level aggregations by attaching a memory tracker for the aggregation state instead of using whole query memory.
Version info
26.7.1.337(included in26.7and later)