Repository navigation
Cherry pick #113534 to 26.7: Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary - #114423
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]>
…-nullable # Conflicts: # src/Processors/QueryPlan/JoinStepLogical.cpp
Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary
Resolve the conflict in `src/Processors/QueryPlan/JoinStepLogical.cpp`: take the PR's condition `if (build_mixed_join_expression)` while keeping the 26.7 body of the block, which has no `ie_join_residual_condition` variable. Co-Authored-By: Claude Fable 5 <[email protected]>
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.
Original pull-request #113534
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job