Skip to content
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: fix the wrong cost formula of MPPExchanger #35438

Merged
merged 8 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/tiflashtest/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestMppExecution(t *testing.T) {
require.NoError(t, err)
ts := txn.StartTS()
taskID := tk.Session().GetSessionVars().AllocMPPTaskID(ts)
require.Equal(t, int64(6), taskID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan changed.

require.Equal(t, int64(5), taskID)
tk.MustExec("commit")
taskID = tk.Session().GetSessionVars().AllocMPPTaskID(ts + 1)
require.Equal(t, int64(1), taskID)
Expand Down
6 changes: 3 additions & 3 deletions planner/core/plan_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,9 @@ func (p *PhysicalExchangeReceiver) GetPlanCost(taskType property.TaskType, costF
return 0, err
}
p.planCost = childCost
// accumulate net cost
// TODO: this formula is wrong since it doesn't consider tableRowSize, fix it later
p.planCost += getCardinality(p.children[0], costFlag) * p.ctx.GetSessionVars().GetNetworkFactor(nil)
// accumulate net cost: rows * row-size * net-factor
rowSize := getTblStats(p.children[0]).GetAvgRowSize(p.ctx, p.children[0].Schema().Columns, false, false)
p.planCost += getCardinality(p.children[0], costFlag) * rowSize * p.ctx.GetSessionVars().GetNetworkFactor(nil)
p.planCostInit = true
return p.planCost, nil
}
Expand Down
3 changes: 2 additions & 1 deletion planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,8 @@ func (t *mppTask) enforceExchangerImpl(prop *property.PhysicalProperty) *mppTask
sender.SetChildren(t.p)
receiver := PhysicalExchangeReceiver{}.Init(ctx, t.p.statsInfo())
receiver.SetChildren(sender)
cst := t.cst + t.count()*ctx.GetSessionVars().GetNetworkFactor(nil)
rowSize := getTblStats(sender.children[0]).GetAvgRowSize(sender.ctx, sender.children[0].Schema().Columns, false, false)
cst := t.cst + t.count()*rowSize*ctx.GetSessionVars().GetNetworkFactor(nil)
sender.cost = cst
receiver.cost = cst
return &mppTask{
Expand Down
Loading