---
title: "The new cost-based join optimizer with reordering support for non-inner joins"
description: "ClickHouse introduces a new cost-based join optimizer (CBO) based on DPsub, an exhaustive dynamic-programming algorithm that finds the cheapest join order for queries with up to 12 tables. The optimizer is enabled by default in the upcoming 26.10 release. Unlike the previous greedy optimizer that only reordered inner joins, the new optimizer supports reordering of LEFT, RIGHT, FULL outer joins, as well as SEMI and ANTI joins, using a conflict detector to ensure correctness. The conflict detector admits only reorderings that preserve the query result and finds every valid plan in the search space, with testing on over 90,000 join trees and 2.8 million candidate plans. Performance tests show significant speedups, for example TPC-H Q2 improved by 55% and TPC-DS Q73 by 45% compared to the greedy default."
---

# The new cost-based join optimizer with reordering support for non-inner joins

[Clickhouse](https://yomu.fyi/company/clickhouse) · Oct 28, 2026

**Type:** Announcement

## Summary

ClickHouse introduces a new cost-based join optimizer (CBO) based on DPsub, an exhaustive dynamic-programming algorithm that finds the cheapest join order for queries with up to 12 tables. The optimizer is enabled by default in the upcoming 26.10 release. Unlike the previous greedy optimizer that only reordered inner joins, the new optimizer supports reordering of LEFT, RIGHT, FULL outer joins, as well as SEMI and ANTI joins, using a conflict detector to ensure correctness. The conflict detector admits only reorderings that preserve the query result and finds every valid plan in the search space, with testing on over 90,000 join trees and 2.8 million candidate plans. Performance tests show significant speedups, for example TPC-H Q2 improved by 55% and TPC-DS Q73 by 45% compared to the greedy default.

## Context

ClickHouse’s earlier optimizer used a greedy algorithm that could not reorder non-inner joins, causing suboptimal plans. The new DPsub-based optimizer addresses this with exhaustive search and a conflict detector for correctness.

## Approach / What changed

DPsub algorithm enumerates all subsets of tables as bitmasks and finds the cheapest plan for each subset by combining best plans of two disjoint parts. A conflict detector based on join types, predicates, and set operations ensures only correct reorderings of non-inner joins are considered.

## Takeaways

- The new CBO uses DPsub, an exhaustive dynamic programming algorithm that represents subsets as bitmasks, enabling efficient enumeration of up to 12 tables with minimal CPU overhead.
- A conflict detector guarantees correctness by only allowing reorderings that preserve query semantics for outer, semi, and anti joins, proving both completeness and soundness.
- Significant performance gains are demonstrated: TPC-H Q2 runtime reduced by 55%, TPC-DS Q73 by 45%, and TPC-DS Q86 by 39% compared to the greedy default.

## FAQ

### How does the conflict detector ensure correctness?

The conflict detector uses a graph-based check that analyzes join types, predicates, and set operations to determine if reordering two joins preserves the query result. It admits only reorderings that are guaranteed to be semantically equivalent, and testing over 90,000 join trees found no invalid plans.

### What is the maximum number of tables the optimizer supports?

By default, the optimizer handles up to 12 tables. The query\_plan\_optimize\_join\_order\_limit setting can be raised to allow more, but the exhaustive search space grows exponentially (3^n splits), so practical limits are around 12 tables.

### How can I enable or disable this optimizer?

Set query\_plan\_optimize\_join\_order\_algorithm to 'dpsub,greedy' (default in 26.10) and query\_plan\_optimize\_join\_order\_conflict\_detector to 'c'. To disable, set algorithm to 'greedy' and conflict detector to an empty string per query.

**Tags:** [ClickHouse](https://yomu.fyi/topic/clickhouse), [Conflict Detector](https://yomu.fyi/topic/conflict-detector), [Join Reordering](https://yomu.fyi/topic/join-reordering)

- Source: [Clickhouse](https://clickhouse.com/blog/the-new-cost-based-join-optimizer-with-reordering-support-for-non-inner-joins)
- Source URL: https://clickhouse.com/blog/the-new-cost-based-join-optimizer-with-reordering-support-for-non-inner-joins
- Ingested by Yomu: 2026-10-28T15:00:11.093Z

[Read original post](https://clickhouse.com/blog/the-new-cost-based-join-optimizer-with-reordering-support-for-non-inner-joins)
