Repository navigation
Do not copy the aggregate function registry entry on every lookup - #128359
alexey-milovidov merged 1 commit into
Conversation
`AggregateFunctionFactory::getImpl` and `tryGetProperties` copied the registered `AggregateFunctionWithProperties` (two `std::function` creators, the whole `FunctionDocumentation` and the properties) into a local on every lookup, and `getAssociatedFunctionByNullsAction` returned another copy by value. `get` calls both, so every resolved aggregate function copied its documentation strings at least twice. Point to the entry instead. The maps are written only by `registerFunction`, before any lookup, and it rejects a null creator, so `found != nullptr` is the same test as the old `found.creator`. Measured on a release build (x86, server pinned to 4 cores, 100M-row ClickBench `hits`): `EXPLAIN PLAN` of ClickBench Q30 (90 `SUM` terms) uses 4.4% fewer instructions in the query thread and runs ~7% faster (7.48 -> 6.96 ms); `EXPLAIN PLAN SELECT SUM(AdvEngineID), COUNT(*), AVG(ResolutionWidth) FROM hits` runs ~14% faster (1.32 -> 1.13 ms). Related: ClickHouse#128352 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review: my own cold review (4 findings) and an independent model (engine: codex; 0 findings).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261031-082900 |
|
cc @azat @KochetovNicolai, could you review this and add the |
|
Workflow [PR], commit [465e838] Summary: ✅
AI ReviewSummaryThe PR avoids copying Missing context / blind spots
Final VerdictStatus: ✅ Approve — no changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units223 translation units recompiled, 1649 s compile time in total, 223 of them have a recent master baseline. |
ba0d3f0
Closes: #128352
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Resolving an aggregate function during query analysis no longer copies its registry entry, including its documentation, so queries with many aggregate functions are planned faster:
EXPLAIN PLANof ClickBench Q30 (90SUMterms) executes 4.4% fewer instructions and about 2% fewer CPU cycles.Description
AggregateFunctionFactory::getImplandtryGetPropertiescopied the registeredAggregateFunctionWithProperties(twostd::functioncreators, the wholeFunctionDocumentationand the properties) into a local on every lookup, andgetAssociatedFunctionByNullsActionreturned another copy by value.getcalls both, so resolving one aggregate function copied its documentation at least twice. They now point to the entry. The maps are only written byregisterFunction, before any lookup, and it rejects a null creator, sofound != nullptris the same test as the oldfound.creator.Release build, x86, server pinned to 4 cores, 100M-row
hits, master vs this PR, 3 server restarts each:EXPLAIN PLANof Q30: 4.4% fewer instructions in the query thread (79.55M -> 76.03M, spread under 0.02%) and 1.8% fewer cycles (27.10M -> 26.62M, measured on idle cores).use_columns_cache = 1, changes by less than the benchmark noise. Memory usage is unchanged.EXPLAIN QUERY TREEandEXPLAIN actionsof 22 queries (sum/count/avg rewrite and fusion, Nullable, Decimal, LowCardinality, aliases,RESPECT NULLS/IGNORE NULLS, combinators, window functions,remote) are identical to master on release and debug builds.#128352 also proposed caching
sum/countandplus/minusinRewriteSumFunctionWithSumAndCountPassand reusing equal replacements inFuseFunctionsPass. On top of this change the two caches save 1.1% of the instructions ofEXPLAIN PLANQ30 each, too little to see in time, so they are not included. Reusing the replacements saves another 5.7% of the instructions and 7.9% of the cycles ofEXPLAIN PLANQ30, but it changes different code, so it goes in a separate PR: #128371.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128359]
Version info
26.11.1.1050-master(included in26.11and later)