---
title: "Hash tables in ClickHouse and C++ Zero-cost Abstractions"
description: "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."
url: "https://swe.quest/articles/hash-tables-in-clickhouse-and-c-zero-cost-abstractions-bd1cf29e2582e0a8"
canonical: "https://clickhouse.com/blog/hash-tables-in-clickhouse-and-zero-cost-abstractions"
source: "ClickHouse"
published: "2023-05-16"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 19
tags: ["data-structures","c-cpp","performance","query-engines","analytics"]
---

# Hash tables in ClickHouse and C++ Zero-cost Abstractions

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-05-16, 19 min read, Deep dive. Original: [https://clickhouse.com/blog/hash-tables-in-clickhouse-and-zero-cost-abstractions](https://clickhouse.com/blog/hash-tables-in-clickhouse-and-zero-cost-abstractions)

## Summary

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. Key design choices are CRC-32C-based hashing instead of identity, cryptographic or FNV1a hashes, linear probing with power-of-two resizing and a 0.5 load factor, and a separately stored zero/null cell instead of user-supplied empty or tombstone keys. On real web-analytics data, ClickHouse's HashMap aggregated about 20M unique keys in 7.4s, versus 9.0s for Abseil, 10.1s for Google DenseMap and 44.8s for std::unordered\_map, with cache misses explaining the gap. Benchmarks should use real data distributions and real scenarios, not random numbers.

Written by swe.quest, not by the author.

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

## Topics

- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- C++ templates ([easy posts on C & C++](https://swe.quest/tags/c-cpp.md?difficulty=easy))
- hash table basics ([easy posts on Data structures](https://swe.quest/tags/data-structures.md?difficulty=easy))
- CPU cache hierarchy ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

ClickHouse, std::unordered\_map, Abseil, Google DenseMap, CRC-32C, SMHasher, libdivide

## Related posts

- [Parallelizing ClickHouse aggregation merge for fixed hash map](https://swe.quest/articles/parallelizing-clickhouse-aggregation-merge-for-fixed-hash-map-9fc83cd0ed214dc7.md): ClickHouse · 2025-12-16 · Hard · 6 min read · Query engines, Performance engineering, Concurrency, Memory management, C & C++
  ClickHouse 25.11 parallelizes the merge phase for GROUP BY on 8- and 16-bit keys, which use an array-backed FixedHashMap.
- [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 Cloud: Fast, Updatable Lookups with the Join Table Engine](https://swe.quest/articles/clickhouse-cloud-fast-updatable-lookups-with-the-join-table-engine-b50f6e80ec781fcd.md): ClickHouse · 2026-05-12 · Medium · 6 min read · Analytics & OLAP, Databases, SQL, Cloud platforms
  ClickHouse's Join table engine keeps a precomputed in-memory hash map for a fixed join strictness, type and key.
- [Join me if you can: ClickHouse vs. Databricks vs. Snowflake - Part 2](https://swe.quest/articles/join-me-if-you-can-clickhouse-vs-databricks-vs-snowflake-part-2-66aede87450dc5eb.md): ClickHouse · 2025-06-25 · Medium · 8 min read · Analytics & OLAP, Performance engineering, Query engines, SQL
  Replacing fact-to-dimension joins with in-memory dictionaries in ClickHouse Cloud sped up a 17-query join benchmark over 1.4 billion rows by 1.9–3.5× in total runtime, up to 6.6× on individual queries, and cut cost by up to 60%.
- [ClickHouse Release 24.11](https://swe.quest/articles/clickhouse-release-24-11-6fda281750a6cdc4.md): ClickHouse · 2024-12-06 · Medium · 6 min read · Analytics & OLAP, Query engines, SQL, Vector search, Performance engineering
  ClickHouse 24.11 makes parallel hash join the default join algorithm, building several hash tables concurrently for speed at the cost of more memory, and adds zero-copy block scattering between threads.

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)
