Skip to content

Cherry pick #113534 to 26.7: Fix a mixed JOIN ON condition evaluated over mismatched column types for a dictionary - #114423

Merged
robot-clickhouse merged 5 commits into
backport/26.7/113534from
cherrypick/26.7/113534
Aug 13, 2026
Merged

robot-clickhouse merged 5 commits into
backport/26.7/113534from
cherrypick/26.7/113534

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

robot-clickhouse and others added 4 commits August 5, 2026 17:16
…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
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 12, 2026
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]>
@robot-clickhouse
robot-clickhouse merged commit 4cda1aa into backport/26.7/113534 Aug 13, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.7/113534 branch August 13, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants