Repository navigation
Cherry pick #119001 to 26.8: Restore selected right join key from left under join_use_nulls - #120384
Merged
robot-ch-test-poll3 merged 12 commits intoSep 16, 2026
Merged
Conversation
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
# Conflicts: # src/Processors/QueryPlan/JoinStepLogical.cpp
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 #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-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.
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:
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