---
title: "Choosing the Right Join Algorithm"
description: "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."
url: "https://swe.quest/articles/choosing-the-right-join-algorithm-3a2fc89a0d23b80c"
canonical: "https://clickhouse.com/blog/clickhouse-fully-supports-joins-how-to-choose-the-right-algorithm-part5"
source: "ClickHouse"
published: "2023-06-27"
difficulty: "medium"
kind: "Research"
reading_minutes: 13
tags: ["query-engines","analytics","performance","sql"]
---

# Choosing the Right Join Algorithm

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-06-27, 13 min read, Research. Original: [https://clickhouse.com/blog/clickhouse-fully-supports-joins-how-to-choose-the-right-algorithm-part5](https://clickhouse.com/blog/clickhouse-fully-supports-joins-how-to-choose-the-right-algorithm-part5)

## Summary

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. Benchmarks on 100M- and 1B-row IMDB tables show direct and parallel hash joins are fastest but memory-hungry. Full sorting merge becomes competitive or faster with far less memory when the physical row order matches the join key, and partial merge is the slowest but leanest. Grace hash trades memory for speed via its bucket count. The post provides decision trees and recommends benchmarking with realistic data, since data volume, types and key distribution can flip the rankings.

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 join vs sort-merge join basics
- ClickHouse MergeTree tables ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, grace hash join, full sorting merge join, partial merge join, parallel hash join, direct join, join\_algorithm

## 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 Joins Under the Hood - Full Sorting Merge Join, Partial Merge Join - MergingSortedTransform](https://swe.quest/articles/clickhouse-joins-under-the-hood-full-sorting-merge-join-partial-merge-join-1ae27b9bc393d8f0.md): ClickHouse · 2023-05-24 · Hard · 32 min read · Query engines, Analytics & OLAP, Databases, Performance engineering
  ClickHouse offers two external-sort-based join algorithms that are not memory bound.
- [ClickHouse Joins Under the Hood - Direct Join](https://swe.quest/articles/clickhouse-joins-under-the-hood-direct-join-4c5bfc57b28f012b.md): ClickHouse · 2023-06-07 · Medium · 15 min read · Query engines, Analytics & OLAP, Performance engineering, SQL
  ClickHouse's direct join is its fastest join algorithm. It applies when the right-hand table sits on storage that supports low-latency key-value lookups: the Join engine, EmbeddedRocksDB or a Dictionary.
- [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 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.

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)
