Skip to content

Cherry pick #119001 to 26.6: Restore selected right join key from left under join_use_nulls - #120382

Merged
robot-ch-test-poll3 merged 13 commits into
backport/26.6/119001from
cherrypick/26.6/119001
Sep 16, 2026
Merged

robot-ch-test-poll3 merged 13 commits into
backport/26.6/119001from
cherrypick/26.6/119001

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #119001

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

vdimir and others added 11 commits September 8, 2026 18:55
With `join_use_nulls = 1`, a right join key selected from a LEFT or FULL JOIN
was wrapped as `toNullable(key)` in the right pre-join actions, so `HashJoin`
stored a full `Nullable` copy of the key next to the key itself. The hash join
already knows how to emit a required right key from the matched left key with
NULL for unmatched rows, so `JoinStepLogical` now hands the join the plain key
and asks for a `Nullable` result via `TableJoin::nullable_right_keys`.

The optimization applies to single-clause equi-joins resolved within the hash
family; merge joins emit the stored key as is and keep the previous plan.

Closes: #118738

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`MergeJoin` takes the types of the required right keys from
`TableJoin::getRequiredRightKeys`, so a key asked for as `Nullable` is filled
from the stored plain column by `copyRightRange` and gets NULL for an unmatched
left row. `JoinStepLogical` therefore restores the selected right key for
`partial_merge` and `auto` too, which is the configuration in the issue; only
`full_sorting_merge` keeps the previous plan.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The legacy join step cast the right key to `Nullable` before the join and
joined on that single column, which was both the key and the output. Do the
same in `JoinStepLogical`: when a right key input has a `toNullable` output
node, that node becomes the key (`preferNullableRightKey`), and an input that
only feeds a used expression is no longer passed to the join as a column of its
own. The right side then carries one column, restored from the left key by the
join as before, for every join algorithm.

This replaces the `TableJoin::nullable_right_keys` approach of the previous
commits, so the `TableJoin`, `MergeJoin` and `joinTotals` changes are reverted.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Where the hash join keeps keys only in its arena the Nullable wrapper is a
whole extra payload column; where it saves key columns too, the wrapper shares
the data and only the byte count toward the spill threshold doubles.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A 1-byte external join limit made the grace join rehash without bound under
some randomized settings; the spilling wrapper is exercised by any non-zero
limit. Pin query_plan_join_swap_table on the EXPLAIN checks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`LEFT ANY JOIN` with `partial_merge` picks one of the two duplicate `c`
rows on the right, and which one depends on the order of equal keys
after sorting the right blocks. On debug builds libc++ randomizes that
order, so the test returned `30` or `31` at random. The query only needs
to show that `r.k` is restored, so it no longer selects `r.w`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119001&sha=9d66cefd4318ef79b43c3df3ff4a80baaf2a13e9&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
#119001

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Parallel replicas add Union, MergingAggregated and ReadFromRemoteParallelReplicas
steps to the plan, and each prints a `Header: __table2.k` line that the EXPLAIN
filter in the test picks up.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119001&sha=b28fc1f57f38a633540c758daf1f272e73be91dc&name_0=PR
PR: #119001

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The merge of master brought the descriptor struct that replaced std::vector<std::pair<String, String>> for shared runtime filter descriptors, and preferNullableRightKey still used the old shape, failing Build (arm_tidy) and Fast test.
…ore-right-key

Restore selected right join key from left under join_use_nulls
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 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 labels Sep 16, 2026
vdimir and others added 2 commits September 16, 2026 12:36
# Conflicts:
#	src/Processors/QueryPlan/JoinStepLogical.cpp
…ng does not exist in 26.6

`EXPLAIN PLAN` in 26.6 already prints the legacy format, so the setting is not needed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@robot-ch-test-poll3
robot-ch-test-poll3 merged commit 85d9766 into backport/26.6/119001 Sep 16, 2026
1 check passed
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.6/119001 branch September 16, 2026 13:05
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-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.

5 participants