Repository navigation
Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary - #113534
Merged
Merged
Conversation
…for a dictionary
A mixed join condition is a cross-side non-equi residual in the `ON` clause, for example
`ON (t.key = d.key) AND (t.a * 10 < d.a)`. Only the hash family evaluates one: `HashJoin`
passes `TableJoin::getMixedJoinExpression` into `AddedColumns::additional_filter_expression`
and applies it while matching, resolving the right columns it needs by name against the
stored right blocks.
`buildPhysicalJoinImpl` drops the `join_use_nulls` conversion of the right columns from the
right-side expression when the right side is a prepared storage, because such a storage
delivers its columns already converted, and for a key-value storage it merges the conversion
back into the right-side DAG under the original column names. But `DirectKeyValueJoin`
declines a mixed condition, so a join onto a dictionary that carries one runs an ordinary
algorithm which reads the dictionary as a stream - and is handed a right side whose `a` is
`Nullable(UInt32)` under the very name the mixed condition declared as `UInt32`.
`buildAdditionalFilter` creates the column from the declared type and fills it with
`insertFrom` from the stored one, so a `ColumnUInt32` was filled from a `ColumnNullable`: an
aborted assertion under sanitizers, and arbitrary matching in a release build.
CREATE TABLE dsrc (key UInt64, a UInt32) ENGINE = Memory;
INSERT INTO dsrc VALUES (1, 100), (2, 20);
CREATE DICTIONARY dict (key UInt64, a UInt32) PRIMARY KEY key
SOURCE(CLICKHOUSE(TABLE 'dsrc')) LIFETIME(0) LAYOUT(FLAT());
CREATE TABLE t (key UInt64, a UInt32) ENGINE = Memory;
INSERT INTO t VALUES (1, 1), (2, 2), (3, 3);
SELECT count(), sum(d.a) FROM t LEFT ANY JOIN dict AS d
ON (t.key = d.key) AND (t.a * 10 < d.a)
SETTINGS allow_experimental_join_condition = 1, join_use_nulls = 1, join_algorithm = 'hash';
Only key 1 satisfies the residual, so the answer is `3, 100`; the release build returned
`3, 120`, having matched key 2 as well.
Keep the conversion in the right-side expression when a key-value storage carries a mixed
condition, so the join applies `join_use_nulls` itself exactly as it does for an ordinary
table and the mixed condition keeps the non-`Nullable` columns it was built on. `StorageJoin`
is unaffected: it rejects a mixed condition outright with `INCOMPATIBLE_TYPE_OF_JOIN`.
Also compare the type and not only the name when `HashJoin` resolves the right columns the
mixed condition needs, so a future divergence throws where both types are still known instead
of reading a column through a mismatched `IColumn` interface.
The shape has been reachable with an explicit `join_algorithm = 'hash'` for as long as the
mixed condition and the prepared-storage handling have coexisted. #112831 made
`DirectKeyValueJoin` decline a mixed condition, which put it on the default `join_algorithm`
path and into the new `04667_mixed_join_condition_algorithm_selection` test, and the assertion
started firing in most stress runs from 2026-08-04 (STID 2508-30f6 and 2508-2e0c, which differ
only by the concurrent-hash-join wrapper in the stack).
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=0f1b923e6247ef3d8409635a69738c7f3f02b84a&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_tsan%29
Related: #112831
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [d6bfa48] Summary: ✅
AI ReviewSummaryThis PR keeps mixed Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 31/37 (83.78%) · Uncovered code |
This was referenced Aug 6, 2026
1 task
1 task done
This was referenced Aug 6, 2026
Closed
This was referenced Aug 6, 2026
…-nullable # Conflicts: # src/Processors/QueryPlan/JoinStepLogical.cpp
This was referenced Aug 6, 2026
alexey-milovidov
added a commit
to ArtemovMichael/ClickHouse
that referenced
this pull request
Aug 9, 2026
Pull in the fix from ClickHouse#113534 for the unrelated `Stress test (amd_tsan)` failure (logical error in `IColumn::assertTypeEquality` from `buildAdditionalFilter`, ClickHouse#113931).
This was referenced Aug 10, 2026
This was referenced Aug 10, 2026
valerypetrov
added a commit
to valerypetrov/ClickHouse
that referenced
this pull request
Aug 10, 2026
The stress test (amd_tsan) failure was an unrelated, already-fixed JOIN bug (dictionary right side + join_use_nulls, see issue ClickHouse#113931, fixed by ClickHouse#113534 which merged into master after this branch's last push). Retriggering CI to pick up the fix.
robot-clickhouse
added a commit
that referenced
this pull request
Aug 13, 2026
Cherry pick #113534 to 26.7: Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary
robot-clickhouse
added a commit
that referenced
this pull request
Aug 13, 2026
…r mismatched column types for a dictionary
clickhouse-gh Bot
added a commit
that referenced
this pull request
Aug 14, 2026
Backport #113534 to 26.7: Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #112831
A mixed join condition is a cross-side non-equi residual in the
ONclause, for exampleON (t.key = d.key) AND (t.a * 10 < d.a). Only the hash family evaluates one:HashJoinpassesTableJoin::getMixedJoinExpressionintoAddedColumns::additional_filter_expressionand applies it while matching, resolving the right columns it needs by name against the stored right blocks.buildPhysicalJoinImpldrops thejoin_use_nullsconversion of the right columns from the right-side expression when the right side is a prepared storage, because such a storage delivers its columns already converted, and for a key-value storage it merges the conversion back into the right-side DAG under the original column names. ButDirectKeyValueJoindeclines a mixed condition, so a join onto a dictionary that carries one runs an ordinary algorithm which reads the dictionary as a stream - and is handed a right side whoseaisNullable(UInt32)under the very name the mixed condition declared asUInt32.buildAdditionalFiltercreates the column from the declared type and fills it withinsertFromfrom the stored one, so aColumnUInt32was filled from aColumnNullable.Only key 1 satisfies the residual, so the answer is
3, 100. A release build returned3, 120, having matched key 2 as well; a sanitizer build aborted on theIColumn::insertFromtype assertion.The fix keeps the conversion in the right-side expression when a key-value storage carries a mixed condition, so the join applies
join_use_nullsitself exactly as it does for an ordinary table and the mixed condition keeps the non-Nullablecolumns it was built on.StorageJoinis unaffected - it rejects a mixed condition outright withINCOMPATIBLE_TYPE_OF_JOIN.HashJoinnow also compares the type and not only the name when it resolves those columns, so a future divergence throws where both types are still known instead of reading a column through a mismatchedIColumninterface.The shape has been reachable with an explicit
join_algorithm = 'hash'for as long as the mixed condition and the prepared-storage handling have coexisted. #112831 madeDirectKeyValueJoindecline a mixed condition, which put it on the defaultjoin_algorithmpath and into the new04667_mixed_join_condition_algorithm_selectiontest, so the assertion started firing in most stress runs from 2026-08-04 - STID2508-30f6and2508-2e0c, which differ only by the concurrent-hash-join wrapper in the stack. No tracking issue was open for either STID.CI report the fix was written from: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=0f1b923e6247ef3d8409635a69738c7f3f02b84a&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_tsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong results and, in a build with assertions enabled, an aborted assertion for a
JOINonto a dictionary whoseONclause has a non-equi condition over both tables, such asON (t.key = d.key) AND (t.a * 10 < d.a), whenjoin_use_nullsis enabled. The condition was evaluated over a column read through a mismatched type, so rows could match arbitrarily.Version info
26.7.4.35