Repository navigation
Optimize aggregate function uniqCombined - #109794
Conversation
Add `insertMany` to `CombinedCardinalityEstimator`: it dispatches on the container type once per batch and runs a tight per-container loop, so the per-value container dispatch and the non-inlined `insert` call are gone from the hot path. Container promotions stay exactly size-triggered because they are observable in results and in serialized states. Override `addBatchSinglePlace` and `addBatchSinglePlaceNotNull` in `AggregateFunctionUniqCombined`: rows are hashed a chunk ahead into a stack buffer, so hash computation pipelines independently of the set inserts. The String path reads `ColumnString` chars and offsets directly instead of calling the virtual `getDataAt` per row. Override `addManyDefaults` to insert the default value once instead of once per row, which speeds up aggregation of sparse columns. Aggregation without GROUP BY speeds up by 6-25%, measured both on synthetic data and on `hits_100m_single` with the query added to the perf test; results and serialized states are bit-identical to the previous implementation, and GROUP BY queries are unaffected. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [a6d151e] Summary: ❌
AI ReviewSummaryThis PR adds batched insertion for Final VerdictStatus: ✅ Approve |
|
📊 Cloud Performance Report ✅ AI verdict: This PR optimizes the batched insertion path of uniqCombined/uniqCombined64 (chunked hashing plus a new insertMany on the cardinality estimator). The two flagged ClickBench improvements, Q10 (-16.3%) and Q11 (-27.1%), are COUNT(DISTINCT UserID) queries that resolve to uniqExact by default and never touch the modified code, and the heavier distinct queries (Q4, Q8, Q9) did not move. Both flagged queries are also historically noisy, so these deltas look like run-to-run variance rather than a real PR effect; both have been downgraded to not sure. No regressions were flagged. clickbenchFlagged queries (2 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
|
`hashOne` returned `HashValueType`, truncating `CityHash64` to 32 bits for `String` and `IPv6`, while `Data::Key` is deliberately `UInt64` for these types: plain `uniqCombined` keeps the full 64-bit hash for them for compatibility of aggregate function states. Return `Key` instead, restoring states byte-identical to master; fixes the failures of test 02751_ip_types_aggregate_functions_states. Suggested in: ClickHouse#109831 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
Requested in: ClickHouse#109794 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 86/101 (85.15%) · Uncovered code |
|
Performance dashboard: https://performance.ci.clickhouse.com/runs?q=109794. I didn't notice any slowed down queries relevant to changes in this PR. |
6c60943
|
Hi @CurtizJ @novikd — while reviewing this PR I found the following:
Could you review the test PR and add the |
Requested in: ClickHouse#109794 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
Optimize aggregate function `uniqCombined`

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimized aggregate function
uniqCombinedin case of aggregation without key.Additional Context
It may be more important in a context of a new
uniqstatistic (#107863) that usesuniqCombined64(12)as an aggregate function for estimation.Version info
26.7.1.869(included in26.7and later)