planner/core: disable new join reorder when DP is enabled#67079
planner/core: disable new join reorder when DP is enabled#67079ti-chi-bot[bot] merged 2 commits intopingcap:masterfrom
Conversation
Signed-off-by: guo-shaoge <shaoge1994@163.com>
|
Review Complete (Fresh Run) Findings: 0 issues ✅ Code looks good - no P0/P1/P2 issues found in this review cycle. ℹ️ Learn more details on Pantheon AI. |
📝 WalkthroughWalkthroughAdded a threshold check to JoinReOrderSolver: the direct call to joinorder.Optimize now requires both TiDBOptEnableAdvancedJoinReorder and TiDBOptJoinReorderThreshold <= 0; otherwise the optimizer falls back to the recursive optimization path. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
Mini256
left a comment
There was a problem hiding this comment.
Code Review Complete
I've completed a thorough review of this PR. Here are my findings:
Summary
The code change is logically correct from a correctness standpoint. However, there are several important issues that should be addressed:
P1 Issues (High Priority)
-
Missing Documentation (pkg/planner/core/rule_join_reorder.go:291)
- The condition change lacks explanation of why advanced join reorder is incompatible with DP algorithm
- The relationship between
TiDBOptEnableAdvancedJoinReorderandTiDBOptJoinReorderThresholdis non-obvious - Suggestion: Add inline comment explaining: "Only use advanced join reorder when DP is disabled (threshold=0). When threshold>0, DP may be used for small join groups, which conflicts with the advanced join reorder framework."
-
Missing Test Coverage
- This PR changes core optimization behavior but includes no tests
- Critical scenarios to test:
- Setting threshold > 0 should disable advanced join reorder
- Default behavior (threshold=0) should continue using advanced join reorder
- Various combinations of both variables should produce expected algorithm selection
- Without tests, this behavior could regress unnoticed
-
Logic Clarity Concern
- When
TiDBOptJoinReorderThreshold > 0, advanced join reorder is completely disabled - However, the old code path may still use DP for small groups (where
joinGroupNum <= threshold) - While this appears intentional, it should be documented to avoid confusion
- When
P2 Issues (Process/Quality)
-
Incomplete PR Description
- PR body has template placeholders: "Issue Number: close #xxx"
- Missing: problem summary, implementation details, test plan
- This violates TiDB contribution guidelines and makes review difficult
- Please fill in: linked issue, problem description, solution explanation, and test plan
-
Code Style - Minor
TiDBOptJoinReorderThreshold <= 0could be== 0since the variable is unsigned (MinValue: 0)- Current form works but
== 0would be more explicit
Verdict
✅ Correctness: The code change is correct and safe from a logic perspective
🤖 Review powered by Pantheon AI
|
✅ Review Complete I've completed a thorough code review of this PR. Here's the summary: Findings
P1 Issues (Must Address Before Merge)
P2 Issues (Process)
RecommendationThe code change itself is correct, but please add tests and documentation before merging. 🤖 Detailed review posted above |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #67079 +/- ##
================================================
- Coverage 77.6914% 77.4401% -0.2513%
================================================
Files 2016 1936 -80
Lines 551900 538705 -13195
================================================
- Hits 428779 417174 -11605
- Misses 121375 121505 +130
+ Partials 1746 26 -1720
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| // Optimize implements the base.LogicalOptRule.<0th> interface. | ||
| func (s *JoinReOrderSolver) Optimize(_ context.Context, p base.LogicalPlan) (base.LogicalPlan, bool, error) { | ||
| if p.SCtx().GetSessionVars().TiDBOptEnableAdvancedJoinReorder { | ||
| if p.SCtx().GetSessionVars().TiDBOptEnableAdvancedJoinReorder && p.SCtx().GetSessionVars().TiDBOptJoinReorderThreshold <= 0 { |
There was a problem hiding this comment.
[P1] Missing Documentation
Why: The condition change lacks explanation of why advanced join reorder is incompatible with DP algorithm. The relationship between TiDBOptEnableAdvancedJoinReorder and TiDBOptJoinReorderThreshold is non-obvious.
Evidence: The added condition TiDBOptJoinReorderThreshold <= 0 at line 291 determines when to use advanced join reorder, but there's no comment explaining that this prevents conflicts with DP algorithm when threshold > 0.
Recommendation: Add inline comment: "Only use advanced join reorder when DP is disabled (threshold=0). When threshold>0, DP may be used for small join groups, which conflicts with the advanced join reorder framework."
|
|
||
| // Optimize implements the base.LogicalOptRule.<0th> interface. | ||
| func (s *JoinReOrderSolver) Optimize(_ context.Context, p base.LogicalPlan) (base.LogicalPlan, bool, error) { | ||
| if p.SCtx().GetSessionVars().TiDBOptEnableAdvancedJoinReorder { |
winoros
left a comment
There was a problem hiding this comment.
The corresponding changed test in
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fixdb, winoros The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What problem does this PR solve?
Issue Number: close #67073
Problem Summary:
The original join order of tpch q9 is like:
((nation supplier) (part lineitem)) partsupp orders, which is generated by DP.After #66349, the join order became:
(((nation suppolier) lineitem) part) partsupp orders, because #66349 enable the new join reorder impl by default, which only support greedy algorithm for now. And the development of DP in the new join reorder impl is still undergoing.But in our benchbot env, DP is used explicitly by setting
tidb_opt_join_reorder_thresholdas 60(DP is disabled by default, you have to set this variable greater than zero then you can use DP), so we have to respect that value for now. And after DP is supported in the new join reorder impl, I'll revert this pr.What changed and how does it work?
Check List
Tests
setup tidb cluster with 2 tiflash with tpch-50G dataset.
before this pr:
(nation supplier) lineitem partthis pr(setting
tidb_opt_join_reorder_thresholdas 64):(nation supplier) (part lineitem)Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit