Error Code 403: INVALID_JOIN_ON_EXPRESSION
This error occurs when ClickHouse cannot parse or process the JOIN ON conditions in your query. The error indicates that the JOIN expression violates ClickHouse's rules for join conditions, particularly when dealing with complex expressions, OR clauses, NULL conditions, or non-equi joins.
Error Message Format:
or
When you'll see it
-
OR conditions not in disjunctive normal form (DNF):
t1.a = t2.a AND (t1.b = t2.b OR t1.c = t2.c)- OR not at top level(t1.a = t2.a AND t1.b = t2.b) OR (t1.a = t2.a AND t1.c = t2.c)✅ - Proper DNF
-
JOIN conditions with only NULL checks:
(t1.id IS NULL) AND (t2.id IS NULL)- No equality condition- Missing join keys between tables
-
Non-equi joins without experimental setting:
t1.a > t2.bwithoutallow_experimental_join_condition = 1
-
Incompatible settings combination:
- Using
allow_experimental_join_condition = 1withjoin_use_nulls = 1(fixed in recent versions)
- Using
-
Complex OR conditions with filters:
t1.id = t2.id OR t1.val = 'constant'- Second part has no join key
Potential causes
-
OR conditions nested within AND - ClickHouse requires OR at the top level (disjunctive normal form)
-
Missing join keys in OR branches - Each OR branch must contain at least one equality condition between tables:
-
Non-equi join conditions without proper setup - Inequality conditions (
<,>,!=) require:allow_experimental_join_condition = 1settinghashorgrace_hashjoin algorithm- Cannot be used with
join_use_nulls = 1
-
Power BI/Tableau generated queries - BI tools often generate JOIN conditions with NULL handling that ClickHouse doesn't support in the old query analyzer
-
Multiple JOIN with column ambiguity - In multi-table JOINs, columns may be referenced with wrong table qualifiers
Quick fixes
1. Rewrite OR conditions to disjunctive normal form (DNF):
2. For NULL-safe joins, use isNotDistinctFrom or COALESCE:
3. Enable experimental analyzer for better OR/NULL support:
4. For non-equi joins (inequality conditions):
Important: Do NOT use join_use_nulls = 1 with non-equi joins - these settings are incompatible.
5. Simplify complex filter conditions:
Important notes
-
Disjunctive Normal Form (DNF) requirement: OR operators must be at the top level of the JOIN condition. Each OR branch should contain complete join conditions.
-
Join key requirement: Each branch of an OR condition must include at least one equality condition between the joined tables.
-
Experimental analyzer: The new query analyzer (
allow_experimental_analyzer = 1) has better support for complex JOIN conditions, including NULL handling. It may become default in future versions. -
Performance considerations:
- Each OR branch creates a separate hash table, increasing memory usage linearly
- Using
COALESCEfor NULL matching is ~5x faster than OR with NULL checks - Power BI bidirectional filters generate complex OR conditions that may not work
-
BI tool compatibility: Tools like Power BI, Tableau, and Looker may generate incompatible JOIN syntax. Solutions:
- Use import mode instead of DirectQuery
- Enable
allow_experimental_analyzer = 1at cluster level - Use ODBC direct queries with custom SQL
- Create views with compatible JOIN syntax