-
Notifications
You must be signed in to change notification settings - Fork 6.1k
planner: add HasTiflash to avoid generating unnecessary mpp task | tidb-test=pr/2660 #65250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
planner: add HasTiflash to avoid generating unnecessary mpp task | tidb-test=pr/2660 #65250
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #65250 +/- ##
================================================
+ Coverage 77.7750% 78.8974% +1.1223%
================================================
Files 2001 1922 -79
Lines 545527 532954 -12573
================================================
- Hits 424284 420487 -3797
+ Misses 119581 111014 -8567
+ Partials 1662 1453 -209
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
4728a02 to
e3b9c98
Compare
|
/retest |
|
/retest |
|
/retest |
1 similar comment
|
/retest |
b114bb3 to
e949bd4
Compare
|
/retest |
78144ef to
9b4552a
Compare
|
/retest |
| return nil, err | ||
| } | ||
| tableInfo := tbl.Meta() | ||
| sessionVars.StmtCtx.HasTiflash = sessionVars.StmtCtx.HasTiflash || b.ctx.GetSessionVars().IsMPPAllowed() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to add this together in this pr.
Current physical optimization needs to generate the mpp task type first because we don't know whether its children can be converted to mpp plan.
If we want to do the pruning completely, we'll need to change the physical opt framework itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But under the current circumstances, most users actually won't have TiFlash replicas. So when building the data source, it can quickly determine whether it contains TiFlash based on the table metadata.
|
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 99 out of 99 changed files in this pull request and generated 4 comments.
| func (*TiKVSingleGather) PreparePossibleProperties(_ *expression.Schema, childrenProperties ...*base.PossiblePropertiesInfo) *base.PossiblePropertiesInfo { | ||
| return &base.PossiblePropertiesInfo{ | ||
| Order: childrenProperties[0].Order, | ||
| } | ||
| } |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TiKVSingleGather.PreparePossibleProperties drops HasTiflash from its child (it only forwards Order). This will make upstream GetHasTiFlash() calculations incorrectly become false after a gather, potentially preventing MPP/TiFlash plan generation. Consider propagating childrenProperties[0].HasTiflash as well.
| // UsedHypoTiFlashReplicas is to use wether this table will use HypoTiFlashReplicas | ||
| func UsedHypoTiFlashReplicas(ctx *variable.SessionVars, dbName ast.CIStr, tblInfo *model.TableInfo) bool { |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "wether" should be "whether".
| // SetHasTiFlashSetHasTiFlash sets whether the plan has tiflash replica. | ||
| SetHasTiFlash(hasTiFlash bool) | ||
|
|
||
| // GetHasTiFlash gets whether the plan has tiflash replica. | ||
| GetHasTiFlash() bool |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc comment has a duplicated word ("SetHasTiFlashSetHasTiFlash"). Consider renaming it to "SetHasTiFlash" for clarity.
| func (p *BaseLogicalPlan) PreparePossibleProperties(_ *expression.Schema, info ...*base.PossiblePropertiesInfo) *base.PossiblePropertiesInfo { | ||
| hasTiflash := true | ||
| for _, childInfo := range info { | ||
| hasTiflash = hasTiflash && childInfo.HasTiflash | ||
| } | ||
| p.hasTiflash = hasTiflash | ||
| return &base.PossiblePropertiesInfo{ | ||
| HasTiflash: p.hasTiflash, |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PreparePossibleProperties can panic when any childInfo is nil (childInfo.HasTiflash dereference). Also, returning nil here causes preparePossibleProperties() to propagate nil upwards, which can lead to nil dereferences in callers that access .Order/.HasTiflash. Consider treating nil child infos as HasTiflash=false and returning a non-nil PossiblePropertiesInfo (even when no order properties), so HasTiFlash can propagate safely through operators that rely on the base implementation.
a227ae2 to
a33dfae
Compare
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
a33dfae to
275cff6
Compare
|
@hawkingrei: 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. |
|
@hawkingrei: 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. |
What problem does this PR solve?
Issue Number: close #65335
Problem Summary:
What changed and how does it work?
checkCanPushDownToMPP will be called twice in the following code. The other problem is that if tables without tiflash replications are used in the query, we don't need to check the mpp task.
tidb/pkg/planner/core/operator/physicalop/physical_hash_agg.go
Lines 52 to 108 in 79ec3b6
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.