-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner: introduce new cost formula for MPPAggs #35436
Merged
ti-chi-bot
merged 7 commits into
pingcap:master
from
qw4990:master-cost-model-2-mpp-agg
Jun 21, 2022
+29
−6
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7713e37
fixup
qw4990 e3ae955
fixup
qw4990 b4c3861
fixup
qw4990 f40eb02
Merge branch 'master' into master-cost-model-2-mpp-agg
qw4990 fab56ea
fixup
qw4990 2fcf7a1
Merge branch 'master' into master-cost-model-2-mpp-agg
qw4990 7988c12
Merge branch 'master' into master-cost-model-2-mpp-agg
qw4990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,7 +312,12 @@ func (p *PhysicalTableReader) GetPlanCost(taskType property.TaskType, costFlag u | |
concurrency = float64(p.ctx.GetSessionVars().DistSQLScanConcurrency()) | ||
rowSize = getTblStats(p.tablePlan).GetAvgRowSize(p.ctx, p.tablePlan.Schema().Columns, false, false) | ||
seekCost = estimateNetSeekCost(p.tablePlan) | ||
childCost, err := p.tablePlan.GetPlanCost(property.CopSingleReadTaskType, costFlag) | ||
tType := property.MppTaskType | ||
if p.ctx.GetSessionVars().CostModelVersion == modelVer1 { | ||
// regard the underlying tasks as cop-task on modelVer1 for compatibility | ||
tType = property.CopSingleReadTaskType | ||
} | ||
childCost, err := p.tablePlan.GetPlanCost(tType, costFlag) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
@@ -326,7 +331,8 @@ func (p *PhysicalTableReader) GetPlanCost(taskType property.TaskType, costFlag u | |
// consider concurrency | ||
p.planCost /= concurrency | ||
// consider tidb_enforce_mpp | ||
if isMPP && p.ctx.GetSessionVars().IsMPPEnforced() { | ||
if isMPP && p.ctx.GetSessionVars().IsMPPEnforced() && | ||
!hasCostFlag(costFlag, CostFlagRecalculate) { // show the real cost in explain-statements | ||
p.planCost /= 1000000000 | ||
} | ||
} | ||
|
@@ -892,12 +898,19 @@ func (p *PhysicalHashJoin) GetPlanCost(taskType property.TaskType, costFlag uint | |
} | ||
|
||
// GetCost computes cost of stream aggregation considering CPU/memory. | ||
func (p *PhysicalStreamAgg) GetCost(inputRows float64, isRoot bool, costFlag uint64) float64 { | ||
func (p *PhysicalStreamAgg) GetCost(inputRows float64, isRoot, isMPP bool, costFlag uint64) float64 { | ||
aggFuncFactor := p.getAggFuncCostFactor(false) | ||
var cpuCost float64 | ||
sessVars := p.ctx.GetSessionVars() | ||
if isRoot { | ||
cpuCost = inputRows * sessVars.GetCPUFactor() * aggFuncFactor | ||
} else if isMPP { | ||
if p.ctx.GetSessionVars().CostModelVersion == modelVer2 { | ||
// use the dedicated CPU factor for TiFlash on modelVer2 | ||
cpuCost = inputRows * sessVars.GetTiFlashCPUFactor() * aggFuncFactor | ||
} else { | ||
cpuCost = inputRows * sessVars.GetCopCPUFactor() * aggFuncFactor | ||
} | ||
} else { | ||
cpuCost = inputRows * sessVars.GetCopCPUFactor() * aggFuncFactor | ||
} | ||
|
@@ -916,7 +929,7 @@ func (p *PhysicalStreamAgg) GetPlanCost(taskType property.TaskType, costFlag uin | |
return 0, err | ||
} | ||
p.planCost = childCost | ||
p.planCost += p.GetCost(getCardinality(p.children[0], costFlag), taskType == property.RootTaskType, costFlag) | ||
p.planCost += p.GetCost(getCardinality(p.children[0], costFlag), taskType == property.RootTaskType, taskType == property.MppTaskType, costFlag) | ||
p.planCostInit = true | ||
return p.planCost, nil | ||
} | ||
|
@@ -936,6 +949,13 @@ func (p *PhysicalHashAgg) GetCost(inputRows float64, isRoot, isMPP bool, costFla | |
// Cost of additional goroutines. | ||
cpuCost += (con + 1) * sessVars.GetConcurrencyFactor() | ||
} | ||
} else if isMPP { | ||
if p.ctx.GetSessionVars().CostModelVersion == modelVer2 { | ||
// use the dedicated CPU factor for TiFlash on modelVer2 | ||
cpuCost = inputRows * sessVars.GetTiFlashCPUFactor() * aggFuncFactor | ||
} else { | ||
cpuCost = inputRows * sessVars.GetCopCPUFactor() * aggFuncFactor | ||
} | ||
} else { | ||
cpuCost = inputRows * sessVars.GetCopCPUFactor() * aggFuncFactor | ||
} | ||
|
@@ -1144,6 +1164,9 @@ func (p *PhysicalExchangeReceiver) GetPlanCost(taskType property.TaskType, costF | |
} | ||
|
||
func getOperatorActRows(operator PhysicalPlan) float64 { | ||
if operator == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be nil in some update-statements. |
||
return 0 | ||
} | ||
runtimeInfo := operator.SCtx().GetSessionVars().StmtCtx.RuntimeStatsColl | ||
id := operator.ID() | ||
actRows := 0.0 | ||
|
This file contains 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
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.
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.
Will this make a different plan when we use
explain
or not?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.
Yes, but I think it's expected. Currently, if we enable
enforce_mpp
, all plan costs will be zero, which is weird.