fix: don't report equi-key equivalence for PiecewiseMergeJoin range joins - #24361
Open
viirya wants to merge 2 commits into
Open
fix: don't report equi-key equivalence for PiecewiseMergeJoin range joins#24361viirya wants to merge 2 commits into
viirya wants to merge 2 commits into
Conversation
…oins `PiecewiseMergeJoinExec::compute_properties` passed the join's `on` pair to `join_equivalence_properties` as an equijoin key. For an INNER join that registers `left_on == right_on` as an output equivalence — but PWMJ's `on` is a range predicate (`l < r`), not equality, so the equivalence is false. It let the optimizer treat a sort on the left key as also sorting the right key and drop a required `ORDER BY`, returning wrongly ordered rows. A range join adds no column equivalences, so pass no `on` pairs. Existing pwmj.slt plans/results updated to the now-correct (fully sorted) output; adds a regression test. Closes apache#24360. Co-authored-by: Claude Code
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24361 +/- ##
==========================================
- Coverage 81.19% 81.18% -0.01%
==========================================
Files 1110 1110
Lines 388616 388614 -2
Branches 388616 388614 -2
==========================================
- Hits 315534 315512 -22
- Misses 54500 54515 +15
- Partials 18582 18587 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…nce-fix # Conflicts: # datafusion/sqllogictest/test_files/pwmj.slt
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.
Which issue does this PR close?
Rationale for this change
PiecewiseMergeJoinExec::compute_propertiespassed the join'sonpair tojoin_equivalence_propertiesas if it were an equijoin key. For anINNERjoin that registersleft_on == right_onas an output equivalence — but PWMJ'sonis a range predicate (l.v < r.v), not equality, so the equivalence is false. It let the optimizer treat a sort on the left key as also sorting the right key and drop a requiredORDER BY, returning wrongly ordered rows.The plans differ: PWMJ sorts only on
l.v(SortExec: expr=[v@0 ASC]); NLJ sorts on both ([v@0 ASC, v@1 ASC]).What changes are included in this PR?
compute_propertiesno longer passes the rangeonpair tojoin_equivalence_properties(a range join adds no column equivalences). The now-unusedjoin_onparameter is dropped.pwmj.sltplans/results updated to the corrected (fully sorted) output — they previously encoded the wrong ordering — and a regression test is added.Are these changes tested?
Yes.
pwmj.slt(INNERl.v < r.v,WHERE l.v = 2,ORDER BY r.v) asserting the correctly ordered result.pwmj.sltcases that asserted the wrong ordering / a single-column sort plan are updated to the correct values (verified againstNestedLoopJoin).piecewiseunit tests andjoins.sltstill pass. OnlyINNERis affected.Are there any user-facing changes?
INNERrange joins viaPiecewiseMergeJoin(behindenable_piecewise_merge_join, default off) no longer drop a required sort, matchingNestedLoopJoin. No API changes.