pkg/planner: preserve suffix order for MergeJoin with constant leading keys#68001
pkg/planner: preserve suffix order for MergeJoin with constant leading keys#68001qw4990 wants to merge 1 commit intopingcap:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughThe PR adds constant-column awareness to merge-join query planning. A new regression test validates the fix, while the core operator logic now recognizes that join keys proven constant via functional dependencies can be skipped during sort-order compatibility checking, enabling better query plans. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @qw4990. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/planner/core/operator/physicalop/physical_merge_join.go (1)
539-571: Helper logic looks correct; consider documenting the uniform-direction precondition.The scan is correct for the documented cases and correctly rejects when a non-constant, non-matching join key is encountered in the middle. A couple of small points worth noting:
- The function intentionally ignores
SortItem.Descand relies on the caller (tryToGetChildReqProp) having already enforcedprop.AllSameOrder()and constructedlProp/rPropwith the matchingdesc. This precondition is non-obvious from the signature alone; a brief note in the godoc would help future readers.- A related (optional) generalization: a leading sort item whose column is itself in
constantColscould also be skipped (order-by a fixed value is trivially satisfied). Not required here — the oldIsPrefixdidn't handle this either — but worth considering as a follow-up if similar patterns show up.📝 Proposed doc tweak
// isSortPropCompatibleWithJoinKeys checks whether the required order can be // satisfied by the join-key order when some leading join keys are fixed to a // single value. +// +// Precondition: all entries in sortItems share the same direction, and the +// caller has built the child required properties with that same direction. +// This function only checks column membership/order, not SortItem.Desc. // // Examples:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/planner/core/operator/physicalop/physical_merge_join.go` around lines 539 - 571, Update the godoc for isSortPropCompatibleWithJoinKeys to state the precondition that all SortItem directions are uniform (caller enforces prop.AllSameOrder()) and that the caller (e.g., tryToGetChildReqProp) constructs lProp/rProp with the matching Desc; explicitly note that this is why the function ignores SortItem.Desc. Optionally mention that a future generalization could skip leading sort items whose columns are in constantCols, but keep current behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/planner/core/operator/physicalop/physical_merge_join.go`:
- Around line 539-571: Update the godoc for isSortPropCompatibleWithJoinKeys to
state the precondition that all SortItem directions are uniform (caller enforces
prop.AllSameOrder()) and that the caller (e.g., tryToGetChildReqProp) constructs
lProp/rProp with the matching Desc; explicitly note that this is why the
function ignores SortItem.Desc. Optionally mention that a future generalization
could skip leading sort items whose columns are in constantCols, but keep
current behavior unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d3125383-03de-4b17-8803-074b1a0ebb94
📒 Files selected for processing (2)
pkg/planner/core/issuetest/planner_issue_test.gopkg/planner/core/operator/physicalop/physical_merge_join.go
|
@qw4990: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
@qw4990: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #68001 +/- ##
================================================
- Coverage 77.7969% 77.1104% -0.6866%
================================================
Files 1984 1969 -15
Lines 549983 552199 +2216
================================================
- Hits 427870 425803 -2067
- Misses 121193 126185 +4992
+ Partials 920 211 -709
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
What problem does this PR solve?
Issue Number: close #67755
Problem Summary: pkg/planner: preserve suffix order for MergeJoin with constant leading keys
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit
Bug Fixes
Tests