---
title: "ClickHouse Joins Under the Hood - Hash Join, Parallel Hash Join, Grace Hash Join"
description: "ClickHouse implements three in-memory hash-table-based join algorithms within its parallel query pipeline."
url: "https://swe.quest/articles/clickhouse-joins-under-the-hood-hash-join-parallel-hash-join-grace-hash-join-eba0126b891cf1aa"
canonical: "https://clickhouse.com/blog/clickhouse-fully-supports-joins-hash-joins-part2"
source: "ClickHouse"
published: "2023-04-20"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 22
tags: ["query-engines","analytics","performance","sql"]
---

# ClickHouse Joins Under the Hood - Hash Join, Parallel Hash Join, Grace Hash Join

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-04-20, 22 min read, Deep dive. Original: [https://clickhouse.com/blog/clickhouse-fully-supports-joins-hash-joins-part2](https://clickhouse.com/blog/clickhouse-fully-supports-joins-hash-joins-part2)

## Summary

ClickHouse implements three in-memory hash-table-based join algorithms within its parallel query pipeline. The default hash join builds a single hash table from the right-hand table in one thread, so with a 100M-row table on the right it ran 5x slower and used 8.95 GiB versus 716 MiB with the small table on the right. Parallel hash join splits right-side rows into max\_threads buckets and fills that many hash tables concurrently, roughly halving runtime at more than double the memory. Grace hash join spills buckets to disk to stay within memory limits without requiring sorting, and the post uses EXPLAIN pipeline graphs and query\_log statistics to show each algorithm's behavior.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- SQL joins ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- hash tables
- ClickHouse basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, hash join, parallel hash join, grace hash join, max\_threads, EXPLAIN pipeline

## Related posts

- [Choosing the Right Join Algorithm](https://swe.quest/articles/choosing-the-right-join-algorithm-3a2fc89a0d23b80c.md): ClickHouse · 2023-06-27 · Medium · 13 min read · Query engines, Analytics & OLAP, Performance engineering, SQL
  ClickHouse offers six join algorithms (direct, hash, parallel hash, grace hash, full sorting merge, partial merge), and the right choice depends on speed, memory and supported join types.
- [How ClickHouse became fast at joins](https://swe.quest/articles/how-clickhouse-became-fast-at-joins-68de042e0ff6c22e.md): ClickHouse · 2026-06-03 · Hard · 15 min read · Query engines, Analytics & OLAP, Performance engineering, SQL
  ClickHouse became 26× faster on the join-heavy TPC-H SF100 workload between 22.4 and 26.4.
- [ClickHouse Release 25.1](https://swe.quest/articles/clickhouse-release-25-1-dbd3d08d261fe532.md): ClickHouse · 2025-02-07 · Medium · 15 min read · Query engines, Analytics & OLAP, Performance engineering, Concurrency
  ClickHouse 25.1 speeds up the default parallel hash join by building N two-level hash tables whose 256 buckets are filled by threads in a non-overlapping way, then merging them in constant time into one shared table.
- [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.
- [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)
