Repository navigation
Inline the per-row emplace of a GROUP BY without aggregate functions - #116267
Conversation
`executeImplBatchNoAggregates` reached the hash table through an `emplace` lambda that
returned the `EmplaceResult` of either the map or the set branch. For the string methods
the compiler outlined that lambda and called it once per row - 448 out-of-line
instantiations in the binary - and the call costs more than the work it wraps. Let the
lambda return nothing, do the `if constexpr` split inside it and force-inline it: no
outlined copy is left and `.text` grows by 0.09%.
Measured with `clickhouse local`, 100M/200M rows, min of 5, two builds of the same
configuration:
`transform(...)` GROUP BY, `key_string` 0.719 -> 0.492 s (-32%)
same, `key_packed_string` 0.671 -> 0.523 s (-22%)
two-group short string key 0.744 -> 0.600 s (-19%)
`UInt64`, 100k distinct keys (set method) 0.541 -> 0.404 s (-25%)
This is the slowdown reported in #115804,
which is not the `HashSet` switch itself - single string keys still use the map methods -
but the lambda introduced alongside it.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013zKvKuuxDYe2HxRi3hiUJq
|
Workflow [PR], commit [9833d46] Summary: ✅
AI ReviewSummaryThis PR removes the per-row outlined lambda call from PR Metadata
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 16/21 (76.19%) · Uncovered code |
…tring keys The queries from #115804, on both string map methods: `key_packed_string` and, with `enable_packed_string_keys_in_aggregation = 0`, `key_string`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013zKvKuuxDYe2HxRi3hiUJq
| The queries are the ones from https://github.com/ClickHouse/ClickHouse/issues/115804. | ||
| --> | ||
|
|
||
| <query>SELECT length(URL) > 1000 ? 'LONG' : 'SHORT' as x FROM hits_100m_single GROUP BY x FORMAT Null</query> |
There was a problem hiding this comment.
Performance Improvement requires a concrete changelog entry, but the PR body still has todo. Please replace it with a user-readable line such as Improved performance of \GROUP BY` queries without aggregate functions over short string keys.`
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o |
20.06 MiB | 20.33 MiB | +271.64 KiB (+1.32%) |
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
593 translation units recompiled, 5210 s compile time in total, 593 of them have a recent master baseline.
|
📊 Cloud Performance Report ✅ AI verdict: This PR is a targeted inlining refactor of the no-aggregate GROUP BY execution path (executeImplBatchNoAggregates), aimed at the string-key case, plus a new perf test. The three flagged ClickBench queries (Q18, Q33, Q34) all group with COUNT() and therefore run the separate aggregating path this change does not touch, so their ~6% deltas fall inside master's current variance band and read as run-to-run noise, not a real regression. The deterministic within-envelope suppression is consistent with the diff; no directional verdict is warranted. clickbenchFlagged queries (3 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🟢 No significant changes Debug info
|
Backport #116267 to 26.8: Inline the per-row emplace of a `GROUP BY` without aggregate functions
|
@fm4v why do we backport perf? |
|
Yes if this is regression fix (in 26.8): #115804 |
…GROUP BY` without aggregate functions
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up
GROUP BYwithout aggregates by inlining some functions.Closes: #115804
Workflow [PR]
Sync PR [sync-upstream/pr/116267]
Version info
26.9.1.124(included in26.9and later)26.8.2.3