Skip to content

Optimise AggregateFunctionSumMap functions family - #107554

Open
jh0x wants to merge 26 commits into
ClickHouse:masterfrom
jh0x:jh-summap-typed
Open

jh0x wants to merge 26 commits into
ClickHouse:masterfrom
jh0x:jh-summap-typed

Conversation

@jh0x

@jh0x jh0x commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Improves #92093

Also fixes: https://fiddle.clickhouse.com/38de3c8b-8da9-4af0-810f-223b3ec395fa

Changelog category (leave one):

  • Performance Improvement

Changelog entry:

Improved performance of sumMap, sumMapWithOverflow, sumMapFiltered, minMap, and maxMap by using typed aggregation paths for supported key and value types.


Workflow [PR]
Sync PR [sync-upstream/pr/107554]

for (const auto & elem : merged_maps)
/// Sort entries by key before serializing to produce a canonical byte
/// representation, independent of hash-map iteration order.
constexpr bool sort_serialize = true;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Decide if to keep it or drop it. Dropping it would change the serialized format - by entries being unsorted.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5a7dc69]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) FAIL
05515_global_subquery_projection_where FAIL cidb
02995_bad_formatting_union_intersect NOT_FAILED cidb
01513_optimize_aggregation_in_order_memory_long NOT_FAILED cidb
01414_push_predicate_when_contains_with_clause NOT_FAILED cidb
01283_max_threads_simple_query_optimization NOT_FAILED cidb

AI Review

Summary

The PR adds typed aggregation for the sumMap, sumMapWithOverflow, sumMapFiltered, minMap, and maxMap family, and replaces the generic ordered map with a hash map while sorting output and serialized entries. No unresolved actionable findings remain at 5a7dc692ec6c22f393ac16406b465f2e1e80fc5f. The earlier small-group memory regression is fixed for numeric and string keys; its bot-authored thread has been resolved. Both new aggregate test files passed locally with the current CI binary and matched their reference outputs exactly. An additional 1,520-case comparison found no aggregate result differences between typed and generic paths.

Missing context / blind spots
  • ⚠️ Current-head release, sanitizer, and performance CI results are pending. The completed fast test passes, and local checks used its binary. Earlier performance results at c104116315ba736b91a78bb9a3777d134e11475a provide before/after evidence of improvements, but predate the latest allocator and wide-key hashing fixes. Current-head performance reports will confirm their final effect. CI report.
Final Verdict

Status: ✅ Approve. No new inline findings; remaining CI should complete before merging.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jun 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 32 queries analysed

This PR only changes the sumMap/minMap/maxMap family: it adds a typed hash-map fast path, switches the generic path to an unordered map, and sorts keys at output. None of the ClickBench or TPC-H queries call these functions, so the benchmarks cannot show the PR's effect either way. ClickBench Q31 (-17.5%) was correctly held at no change because it falls within master's recent spread, and its CPU time barely moved. Q34 (-9.8%) stays not sure because master's own timings for it shifted around 2026-10-08, and the query does not reach the changed code.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 34 not_sure 1092 984 -9.8% <0.0001 aggregation: This is a GROUP BY query that does not use the -Map aggregate functions this PR rewrites. The -9.8% shift and lower CPU time line up with an unstable master baseline, not with this diff.

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
  • StressHouse run: 91aa64ec-dd81-4ca0-8a9f-b0c471e6cede
  • MIRAI run: 1f6429a5-2ada-4d25-99be-0e8353ddc694
  • PR check IDs:
    • clickbench_431813_1791492415
    • clickbench_431819_1791492415
    • clickbench_431825_1791492415
    • tpch_adapted_1_official_431836_1791492415
    • tpch_adapted_1_official_431852_1791492415
    • tpch_adapted_1_official_431884_1791492415

@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.30% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 755/844 (89.45%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 58 line(s) · Uncovered code

Full report · Diff report

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
Comment thread src/Common/FieldVisitorHash.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5a7dc692e with master 4088c421f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

112 object files changed (+2.51 MiB total), 1 added.

Object file Master PR Δ
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSumMapTyped.c… new 2.05 MiB +2.05 MiB
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSumMap.cpp.o 2.99 MiB 3.44 MiB +466.61 KiB (+15.25%)

719 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

4289 translation units recompiled, 19843 s compile time in total, 4285 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/AggregateFunctions/AggregateFunctionSumMapTyped.cpp: 11.4 s
  • programs/keeper/Keeper.cpp (clickhouse-keeper): 7.6 s

Job report

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). external Author is not a member of the ClickHouse organization pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants