---
title: "Parallelizing ClickHouse aggregation merge for fixed hash map"
description: "ClickHouse 25.11 parallelizes the merge phase for GROUP BY on 8- and 16-bit keys, which use an array-backed FixedHashMap."
url: "https://swe.quest/articles/parallelizing-clickhouse-aggregation-merge-for-fixed-hash-map-9fc83cd0ed214dc7"
canonical: "https://clickhouse.com/blog/parallelizing-fixed-hashmap-aggregation-merge-in-clickhouse"
source: "ClickHouse"
published: "2025-12-16"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 6
tags: ["query-engines","performance","concurrency","memory-management","c-cpp"]
---

# Parallelizing ClickHouse aggregation merge for fixed hash map

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2025-12-16, 6 min read, Deep dive. Original: [https://clickhouse.com/blog/parallelizing-fixed-hashmap-aggregation-merge-in-clickhouse](https://clickhouse.com/blog/parallelizing-fixed-hashmap-aggregation-merge-in-clickhouse)

## Summary

ClickHouse 25.11 parallelizes the merge phase for GROUP BY on 8- and 16-bit keys, which use an array-backed FixedHashMap. Before this, these aggregations could not use the bucket-wise parallel merge available to two-level hash tables, so a UInt16 key query ran in 62.8s versus 8.5s for the same query cast to UInt64. The fix has merge threads work in place on disjoint key subsets instead of converting to a two-level table. Along the way: contiguous range segmentation balanced poorly, a shared non-thread-safe Arena caused memory corruption and needed one Arena per thread, and a fixed 3ms regression on trivial aggregates was solved by computing the min/max populated index before the parallel merge.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)

## Prerequisites

- hash table internals ([easy posts on Data structures](https://swe.quest/tags/data-structures.md?difficulty=easy))
- GROUP BY aggregation execution
- multithreading and race conditions ([easy posts on Concurrency](https://swe.quest/tags/concurrency.md?difficulty=easy))
- arena allocators ([easy posts on Memory management](https://swe.quest/tags/memory-management.md?difficulty=easy))

## Keywords

ClickHouse, FixedHashMap, DB::Arena, two-level hash table, flame graphs

## Related posts

- [ClickHouse Joins Under the Hood - Hash Join, Parallel Hash Join, Grace Hash Join](https://swe.quest/articles/clickhouse-joins-under-the-hood-hash-join-parallel-hash-join-grace-hash-join-eba0126b891cf1aa.md): ClickHouse · 2023-04-20 · Medium · 22 min read · Query engines, Analytics & OLAP, Performance engineering, SQL
  ClickHouse implements three in-memory hash-table-based join algorithms within its parallel query pipeline.
- [ClickHouse Release 25.11](https://swe.quest/articles/clickhouse-release-25-11-bcf7d5c39dac13b0.md): ClickHouse · 2025-12-05 · Medium · 14 min read · Analytics & OLAP, Query engines, Performance engineering, Concurrency
  ClickHouse 25.11 ships 24 features, 27 performance optimizations and 97 bug fixes.
- [Hash tables in ClickHouse and C++ Zero-cost Abstractions](https://swe.quest/articles/hash-tables-in-clickhouse-and-c-zero-cost-abstractions-bd1cf29e2582e0a8.md): ClickHouse · 2023-05-16 · Hard · 19 min read · Data structures, C & C++, Performance engineering, Query engines, Analytics & OLAP
  ClickHouse implements GROUP BY and JOIN with a family of open-addressing hash tables generated from a common zero-cost C++ framework, specialized by key type and workload.
- [ClickHouse Release 22.12](https://swe.quest/articles/clickhouse-release-22-12-b9fac2d701130c5e.md): ClickHouse · 2022-12-19 · Medium · 8 min read · Query engines, Analytics & OLAP, Databases, Identity & auth
  ClickHouse 22.12 adds a grace hash join algorithm that partitions both join sides into hash buckets spilled to disk, dynamically increasing the bucket count when the in-memory hash table exceeds max\_bytes\_in\_join, so large joins run with bounded memory.
- [How we scaled raw GROUP BY to 100 B+ rows in under a second](https://swe.quest/articles/how-we-scaled-raw-group-by-to-100-b-rows-in-under-a-second-c36aee54a6541514.md): ClickHouse · 2025-09-29 · Medium · 23 min read · Query engines, Analytics & OLAP, Performance engineering, Distributed databases, Scaling
  ClickHouse Cloud's parallel replicas feature spreads a single GROUP BY query across every core of every node in a service, with no pre-aggregation or data reshuffling.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
