ClickHouse JOIN algorithms in 26.11: parallel_hash is just hash now, and the planner picks the rest

In ClickHouse 26.11 parallel_hash is an alias of hash: one join that builds in parallel from 100,000 estimated rows and spills at 50% of memory. What's left to tune.

Most ClickHouse JOIN guides, from ClickHouse’s own 2023 series on join algorithms to tutorials written this year, teach the same routine: put the small table on the right, pick parallel_hash for speed, grace_hash or partial_merge when memory is tight, and full_sorting_merge when both tables are sorted by the join key. Through 2025 and 2026 ClickHouse moved almost every one of those decisions into the query planner. The latest step came in 26.11 (released 2026-11-24): parallel_hash is now an obsolete alias of hash. There is one hash join. It builds its hash table on many threads once the right side is estimated at 100,000 rows or more, and it spills to disk once the build side passes 50% of available memory. Neither behaviour depends on the algorithm name you list.

This is day 13 of the ClickHouse series. It explains what the planner decides for you in 26.11, the thresholds it uses, and the few cases where setting join_algorithm by hand still helps. Setting it by hand can also switch some of the new planning off. Everything here comes from the source at tag v26.11.1.2942-stable (mainly Settings.cpp, PlannerJoins.cpp, optimizeJoin.cpp, TableJoin.cpp), the 26.11 changelog, and measurements that ClickHouse developers published in their pull requests. Nothing was benchmarked for this post.

The short answer

Decision Who makes it in 26.11 Setting and default Since
Build side planner, by estimated rows query_plan_join_swap_table = 'auto' 24.12
Join order planner, dynamic programming query_plan_optimize_join_order_algorithm = 'dpsub,greedy' 26.11
Hash or sort-merge planner, by cost (sorted inputs) query_plan_join_order_use_interesting_orders = 1 26.11
Parallel build planner, from the right-side estimate parallel_hash_join_threshold = 100000 26.11
Spill to disk runtime, at a share of memory max_bytes_ratio_before_external_join = 0.5 26.5
Runtime filter on probe side runtime enable_join_runtime_filters = 1 26.2
Inequality-only ON ie_join last in default join_algorithm 26.8

The “since” column is when the default took effect: the 100,000-row threshold dates from 25.5 but governed only parallel_hash until 26.11, and dpsub became the default join-order algorithm in 26.11 (reordering of up to 10 tables has been on by default since 25.12).

The default join_algorithm is now direct,hash,ie_join. It has changed three times in two years, according to the setting’s own history in Settings.cpp:

Version Default join_algorithm Why
before 24.12 default (= direct,hash)
24.12 direct,parallel_hash,hash default deprecated, parallel_hash preferred
26.8 direct,parallel_hash,hash,ie_join inequality-only joins stop being a filtered CROSS JOIN
26.11 direct,hash,ie_join parallel_hash merged into hash (#115605)

If you have join_algorithm = 'parallel_hash' in a profile or in query settings, 26.11 still accepts it, reads it back as hash, and runs the same code either way.

What happens to an equi-JOIN in ClickHouse 26.11 with default settings1 Lookup?directright side is a Dictionary or key-value table,single key, INNER/LEFT: look rows up, no hash table2 Which side is built?query_plan_join_swap_table = autoALL joins: smaller estimate becomes the build side;join order by dpsub (26.11) for up to 10 tables3 Hash or merge?query_plan_join_order_use_interesting_ordersinputs already sorted on the key and a big build side:full_sorting_merge, chosen by cost (26.11)4 One thread or many?parallel_hash_join_threshold = 100,000estimated build rows below: one part, one thread;at or above, or no estimate: 256 buckets, max_threads5 Out of memory?max_bytes_ratio_before_external_join = 0.5build side passes 50% of available memory: spill,continue as grace hash (or partial merge if order is needed)Only an inequality-only ON goes to ie_join (26.8+). Setting join_algorithm by hand can switch steps 3 and 4 off.
Read from the 26.11 source: PlannerJoins.cpp, optimizeJoin.cpp, TableJoin.cpp and the defaults in Settings.cpp. Simplified: each step has more conditions than fit in a box.

Step 1: direct, only for key-value right sides

direct comes first in the default list, but in tryDirectJoin (PlannerJoins.cpp) it only applies when the right side is a storage that can look up rows by key (getStorageKeyValue()): a Dictionary, an EmbeddedRocksDB table and similar. There must be one equality key, no other ON conditions, and the join must be INNER ALL or LEFT (ANY, ALL, SEMI, ANTI). For an ordinary table the planner skips direct and moves on to hash. Having it in the list costs nothing.

Step 2: the small table no longer has to be on the right

A ClickHouse hash join loads one input into memory (the build side) and streams the other one past it (the probe side). For years that was always the right-hand table, so “smaller table on the right” was the most important JOIN rule. Since 24.12, query_plan_join_swap_table = 'auto' lets the planner pick. In optimizeJoin.cpp the rule is simple: when both inputs have a row estimate and the left one is smaller, the sides swap. The setting’s docs limit this to ALL strictness with JOIN ON. The code also skips USING joins (a fixme notes that swapping breaks them), and outer joins can only be flipped when the algorithm is a hash join.

With several tables, the join order is chosen as well. query_plan_optimize_join_order_limit reorders up to 10 tables by default (since 25.12). In 26.11 the default algorithm became dpsub, an exhaustive dynamic-programming search, with greedy as the fallback above 12 relations (#120110). The new CD-C conflict detector lets semi and anti joins take part too.

Estimates are where this can go wrong. The 26.11 changelog has several fixes to them: filters on constant UNION ALL columns no longer count as selective, which made the hash tables of TPC-DS q4, q11 and q74 7 to 16 times smaller (#128506). Bool filters without statistics are now estimated at half the rows instead of 1% (#125467). An ON a.id = b.id AND (b.x IS NULL OR …) condition no longer loses its equality key. One query in that issue went from 18.6 s to 0.04 s (#122526). If a join was slow on 26.10 because the big table ended up on the build side, check again on 26.11 before you rewrite it. EXPLAIN shows which side is built.

Step 3: full_sorting_merge, picked by cost

The classic advice was to set join_algorithm = 'full_sorting_merge' when both tables are sorted by the join key: the merge join then streams both inputs with very little memory. In 26.11 the planner does this on its own. With query_plan_join_order_use_interesting_orders (new and on by default, #128519), dpsub checks which MergeTree inputs can be read in join-key order and keeps a cheaper plan for each useful sort order. For each inner ALL equi-join it then chooses a hash join or full_sorting_merge by cost. A merge join keeps its sides, so the sorted order can carry on into the next join of a chain.

Its author published these numbers in issue #128518 (release build, 32 cores, synthetic data, setting off vs on):

Scenario Faster Peak memory
6-table chain on one key, 20M rows each 2.2× 10× less
Composite key (tenant_id, id), 50M × 50M 2.7× 15× less
TPC-H-like lineitem ⋈ orders ⋈ shipments, SF10 sizes 1.6× 4.8× less
events ⋈ users, 100M × 20M 1.15× 6.4× less
Wide build side, max_memory_usage = 2 GB failed before, 0.3 s now 263 MiB

Small build sides, unsorted tables and joins where the runtime filter prunes well stay on the hash join. The catch is in the PR text: the feature “applies to inner equi-joins with ALL strictness when join_algorithm has its default value”. If you set join_algorithm for a query, you turn this planning off for that query.

Step 4: one thread or many, decided at 100,000 rows

Before 26.11, hash and parallel_hash were two classes. PR #115605 describes the old behaviour: “a large hash stayed on one thread, and a small parallel_hash always ran parallel”. parallel_hash built N separate HashJoin objects, each with its own map, arena and blocks, and merged them at the end. In 26.11 there is one class. TableJoin::preferParallelHashLayout makes the choice for INNER, LEFT, RIGHT and FULL joins:

case HashJoinLayout::AUTO:
    return !rhs_size_estimation || *rhs_size_estimation >= parallel_hash_join_threshold;
  • Estimated right side below 100,000 rows: the hash table is one part, filled by one thread.
  • 100,000 rows or more, or no estimate at all: a two-level table with up to 256 buckets and per-slot locks, filled by up to max_threads threads.

“No estimate” covers more than you might think: ASOF joins never get one, a join with query_plan_optimize_join_order_limit = 0 gets none, and the old analyzer never had them. For repeated queries, collect_hash_table_stats_during_joins (on by default) remembers the right-side size of earlier runs and uses it as the estimate. To force a layout, there is a new setting, hash_join_layout = 'serial' | 'parallel', which the docs describe as meant for tests and debugging.

The serial layout keeps three optimizations that the parallel one doesn’t have, according to the PR: converting a key32/key64 map into a direct-addressed array after the build, building a runtime filter from that array, and a dictionary-aware map for a single LowCardinality key. So in 26.10 and earlier, forcing parallel_hash on a small dimension table could make a join slower, not faster. In 26.11 the name no longer matters.

There are two visible changes to plan for. A join built in parallel can return rows in a different order and pick a different right-side row for ANY joins, so add ORDER BY where you need a stable result. And system.query_log.used_join_algorithms now shows HASH for every hash join, so a dashboard that filters on PARALLEL_HASH finds nothing after the upgrade.

Step 5: spilling to disk is on by default

Since 26.5, max_bytes_ratio_before_external_join = 0.5: when the build side of a hash join grows past half of the memory available to the query (its docs say “to server/user/merges”, measured when execution starts), the join spills the right side to disk and continues as a grace hash join. It starts with grace_hash_join_initial_buckets = 1 and can split up to grace_hash_join_max_buckets = 1024. In 26.11, if the plan needs the left table’s row order (read in order through the join, for ORDER BY pk LIMIT n), it continues as a partial merge join instead, which keeps that order (#124873). In PlannerJoins.cpp this is a SpillingHashJoin wrapped around the normal HashJoin. It is only used when a temporary data path is configured and GraceHashJoin::isSupported accepts the join.

So you rarely need to pick grace_hash yourself. The setting’s docs now call explicit grace_hash “intended primarily for diagnostic use”. It partitions from the first block instead of trying memory first, and without a spill threshold it is skipped for the next algorithm in the list. There are three exceptions to keep in mind:

  • OR in ON cannot spill. “Multi-disjunct ON conditions (OR) stay on hash and can hit the memory limit with no spill” (setting docs). Rewrite such joins as a UNION ALL of single-key joins if they are big.
  • Size limits are hard caps since 26.10. max_rows_in_join and max_bytes_in_join used to trigger the spill. Now they fail the query (or apply join_overflow_mode) even for joins that can spill. legacy_join_size_limits_trigger_spilling brings back the old behaviour.
  • 26.11 hash tables can be bigger. In 26.10 the buckets of a large hash table switched to Robin Hood hashing at 2^16 cells and filled up to 0.9 instead of 0.5 before growing. 26.11 turns that off for joins (#128012). Joins with random keys get up to 1.8× faster, but “the hash table takes up to 1.75 times more memory”, and the PR notes that a join close to the 50% limit “spills to grace hash sooner”. enable_robin_hood_hash_for_joins = 1 turns it back on.

Memory per row: String keys got cheaper in 26.11

How much memory a hash join needs depends on the key type and on the right-side columns it has to carry. One case got much cheaper in 26.11: joins on a single String key. Before, every key was copied into an arena, and each hash cell held the copy’s address (8 bytes), its length (8), a saved hash (8) and the row reference. Now, with enable_packed_string_keys_in_hash_join on by default (#128972), each key takes 16 bytes inside the cell. A key of up to 15 bytes is stored as it is. A longer key is stored as its 128-bit SipHash with one bit used as a flag, so two different long keys whose other 127 bits agree would match as equal. The PR puts the chance at about n²/2^128 for n distinct long keys. Joins whose right side is estimated below 100,000 rows (min_rows_for_packed_string_keys_in_hash_join) keep exact keys.

Peak memory per right-table row, single String key (bytes)6–12 byte keys, 10M rowsexact keys (26.10): 67 B/row67 Bpacked keys (26.11): 40 B/row40 B (0.60×)35–41 byte keys, 10M rowsexact keys (26.10): 107 B/row107 Bpacked keys (26.11): 40 B/row40 B (0.38×)~500 byte keys, 200K rowsexact keys (26.10): 755 B/row755 Bpacked keys (26.11): 63 B/row63 B (0.08×)exact keys (before 26.11)16-byte packed keys (26.11 default)whole-query peak memory ÷ right rows; 1 thread; the left side is 1 row, so only the build side counts
Computed from the peak-memory table in PR #128972 (clickhouse local on a Graviton 4, measured by the PR author, not here): 640 → 384 MiB, 1,024 → 384 MiB and 144 → 12 MiB.

The same PR measured the time for 10 million right rows with every left row matching: 2,326 → 1,334 ms on one thread and 165 → 102 ms on 16 threads for short keys. With 16 threads, peak memory falls less (657 → 416 MiB for short keys) because the parallel layout has more buckets and arenas. In that test the right table had one String key and one UInt64 column, so the roughly 40 bytes per right row on 26.11 cover everything: the stored right-side block (the strings, their offsets and the UInt64), the 16-byte packed keys and the row references. Each extra column you select from the right side adds its own size per row on top.

When setting join_algorithm still helps, and when it hurts

The setting’s docs in 26.11 have a warning that most guides miss. Some algorithms change planning just by being in the list, “even as a lower-priority fallback that is not ultimately selected”:

  • Listing full_sorting_merge or parallel_full_sorting_merge makes join-key type inference stricter (a merge join can’t join String with Nullable(String)). That can change the result types of USING columns and can make a join into a Join-engine table fail with TYPE_MISMATCH.
  • Listing full_sorting_merge, parallel_full_sorting_merge, partial_merge, prefer_partial_merge, grace_hash or auto makes ORDER BY … LIMIT on the preserved side sort explicitly instead of reading in primary-key order. The result is the same, but the plan is less efficient.
  • Any non-default list also turns off the hash-versus-merge choice from step 3.

What’s left to tune by hand:

Situation What to do in 26.11
Joins of two big tables sorted on the join key nothing: the planner picks full_sorting_merge by cost; check EXPLAIN
Both inputs too big for memory, unsorted, many threads join_algorithm = 'parallel_full_sorting_merge': shards the merge join by key hash across max_threads, so memory stays low and all threads work
You know the build side won’t fit grace_hash skips the in-memory attempt; otherwise leave spilling to the 50% ratio
Wrong side is built (bad estimate) query_plan_join_swap_table = 'true'/'false' for that query, and add column statistics
Small join on one thread that should be parallel (or the reverse) hash_join_layout = 'parallel'/'serial', or lower parallel_hash_join_threshold
Lookups into a dictionary direct (already first in the default list)
Profiles that set parallel_hash remove it: it reads back as hash and changes nothing

Upgrading from 26.10: checklist

  1. Search your settings profiles and query code for parallel_hash. Removing it changes nothing, but a dashboard that filters used_join_algorithms on PARALLEL_HASH needs to look for HASH instead.
  2. Add ORDER BY wherever a join result’s row order, or which row an ANY join picks, matters. Small joins of hash that used to run on one thread may now build in parallel.
  3. Joins that ran close to the memory limit on 26.10 may spill earlier, because Robin Hood hashing is now off. Watch system.query_log for grace hash spills. To get the 26.10 memory behaviour back, set enable_robin_hood_hash_for_joins = 1.
  4. If you set join_algorithm = 'full_sorting_merge' globally, try the default list. The cost-based choice only works with the default.
  5. LOCAL right before JOIN is now parsed as a keyword, like GLOBAL. A query that used local as an implicit table alias (FROM t local JOIN …) fails until you write t AS local (#120222).

FAQ

What is the default join algorithm in ClickHouse? In 26.11 it is direct,hash,ie_join: dictionary-style lookups when the right side supports them, otherwise a hash join, and IEJoin only for ON conditions with nothing but inequalities. From 24.12 to 26.10 it was direct,parallel_hash,hash (with ie_join appended in 26.8).

Is parallel_hash faster than hash? In 26.11 they are the same code. Whether the hash table is built on several threads depends on parallel_hash_join_threshold (100,000 estimated right rows) and hash_join_layout, not on the name. In 26.10 and earlier, parallel_hash was a separate class that always ran in parallel, even when that was slower.

Should the smaller table be on the right in a ClickHouse JOIN? It doesn’t matter as much since 24.12: for ALL joins with ON, the planner swaps the sides when the left input is estimated smaller. It still matters for USING joins, for some outer joins with non-hash algorithms, and whenever the estimates are wrong.

When does a ClickHouse JOIN spill to disk? Since 26.5, by default, once the build side passes 50% of the available memory (max_bytes_ratio_before_external_join = 0.5), provided a temporary path is configured and the join has a single equality condition. Joins with OR in ON don’t spill.

When should I use grace_hash? Rarely, in 26.11. Every hash join already switches to grace hash when it crosses the spill threshold. Set grace_hash only when you know the build side won’t fit and want to skip the in-memory phase.

How much memory does a ClickHouse hash join use per row? It depends on the key and the columns you select from the right side. For a single String key and one UInt64 column on 26.11, the PR’s measurements come to about 40 bytes per right row in total, down from 67-107 bytes on 26.10. Each extra right-side column you select adds its own size per row.

Tomorrow, day 14: dictionary vs JOIN vs IN for lookups, and where direct fits.