Repository navigation
Cherry pick #132507 to 26.10: Do not use mixed-type equivalence classes as DPsub merge keys - #132694
Merged
robot-ch-test-poll merged 6 commits intoNov 25, 2026
Merged
Conversation
`spanningClasses` returned every equivalence class with columns on both
sides of a join, including classes whose columns have different types.
`buildPhysicalPlan` then added a secondary merge key from such a class
(e.g. `Date` = `DateTime('Asia/Tokyo')`), which is not implied by the query
because equality of different types is not transitive, and
`cleanupJoinPredicates` dropped the query's own predicate as redundant.
The join returned too few rows.
Restrict `spanningClasses` to single-type classes, like `mergeKeyClasses`,
so the plan and the cost in `mergeJoinCost` and `isShardedMerge` agree.
Closes: #130142
Related: #128519
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the previous commit `spanningClasses` returns only single-type
classes, so `mergeJoinCost` no longer saw a written key of columns of
different types, such as `a.x = b.y` with `Date` and `DateTime('UTC')`.
The plan still joins on it, so both inputs sorted only by the merge key
are sorted again, but the cost charged nothing for it and a merge join
won over a hash join.
`joinKeyClasses` gives all keys of the merge: the synthesized single-type
ones and the classes of the written predicates. `mergeJoinCost` and
`isShardedMerge` use it. A mixed-type key is joined on a cast column after
the other keys, so no input counts as sorted by all keys. The per-class
single-type flags become the bit mask `single_type_classes`.
Related: #132507 (comment)
Closes: #130142
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… types `probeReadFraction` intersects the `minmax` ranges of the columns of the merge key class. For a class of columns of different types they are in different units, such as days of a `Date` and seconds of a `DateTime`, so the overlap came out near 0 and a hash join was charged almost no probe work. Return 1.0 (unknown) for such a class. Related: #132507 Related: #130142 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since 9bf7d55 any key of columns of different types made `mergeJoinCost` charge sorting within the groups of the merge key. A widening cast such as `UInt32` to `UInt64` keeps the input order, so for inputs sorted by both keys the merge needs no sorting, and the cost made a hash join win that is slower. `castsKeepOrder` checks, as the sort step does, that the cast of each column to the common type of the join is monotonic and increasing on the whole type (`Date` to `DateTime` is not). The classes whose written equalities all pass are in `ordered_classes`, and `mergeJoinCost` counts an input as sorted on them. `buildPhysicalPlan` places the written equalities of such a key at its position in the input order instead of synthesizing a key, so the plan follows the cost. Related: #132507 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-keys Do not use mixed-type equivalence classes as DPsub merge keys
Contributor
|
Dear @fkastrati, this cherry-pick PR has not been updated for 3d0h7m20s. Please resolve the conflicts to backport #132507, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity. |
…ck/26.10/132507 # Conflicts: # src/Processors/QueryPlan/Optimizations/joinOrderDPSub.cpp
fkastrati
force-pushed
the
backport/26.10/132507
branch
from
November 25, 2026 02:26
f242c09 to
d3fa8f1
Compare
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 #132507
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