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: introduce the new cost formula for MPPJoin #35642

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
12b548c
fixup
qw4990 Jun 7, 2022
011f649
fixup
qw4990 Jun 7, 2022
d1b5eef
fixup
qw4990 Jun 7, 2022
5d4aafc
fixup
qw4990 Jun 7, 2022
029dabb
fixup
qw4990 Jun 7, 2022
60582dc
fixup
qw4990 Jun 7, 2022
8b3f4ed
fixup
qw4990 Jun 7, 2022
bd3e9e0
fixup
qw4990 Jun 7, 2022
0f564d5
fixup
qw4990 Jun 7, 2022
692cbb0
fixup
qw4990 Jun 7, 2022
7d52a48
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 7, 2022
82b03d5
fixup
qw4990 Jun 7, 2022
1bf8ddb
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 7, 2022
597942f
fixup
qw4990 Jun 7, 2022
31e7aa5
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 8, 2022
5dad986
fixup
qw4990 Jun 8, 2022
bd77f76
fixup
qw4990 Jun 8, 2022
d5a03d2
fixup
qw4990 Jun 8, 2022
414d35f
fixup
qw4990 Jun 8, 2022
b5ee3e8
fixup
qw4990 Jun 8, 2022
7ba8016
fixup
qw4990 Jun 8, 2022
c35c9e1
fixup
qw4990 Jun 8, 2022
5483cb5
fixup
qw4990 Jun 8, 2022
e1177a7
fixup
qw4990 Jun 8, 2022
4c71ca1
fixup
qw4990 Jun 8, 2022
b3f1879
fixup
qw4990 Jun 8, 2022
4932fbe
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 8, 2022
4b9d1a3
fixup
qw4990 Jun 8, 2022
90714ce
fixup
qw4990 Jun 8, 2022
c079413
fixup
qw4990 Jun 8, 2022
a283a96
fixup
qw4990 Jun 8, 2022
3b0ce79
Merge branch 'master' into vars-for-cost-model-ver2
hawkingrei Jun 8, 2022
7bcb7ce
Merge branch 'master' into vars-for-cost-model-ver2
hawkingrei Jun 8, 2022
569f33a
Merge branch 'master' into vars-for-cost-model-ver2
qw4990 Jun 9, 2022
6241610
Merge branch 'master' into vars-for-cost-model-ver2
qw4990 Jun 9, 2022
e0bae89
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 9, 2022
fa4cda5
fixup
qw4990 Jun 9, 2022
2b6912c
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 9, 2022
2d04a37
fixup
qw4990 Jun 9, 2022
3923e1a
fixup
qw4990 Jun 9, 2022
3d369b9
fixup
qw4990 Jun 9, 2022
eceea6d
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 9, 2022
985bdfd
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 9, 2022
b112505
fixup
qw4990 Jun 9, 2022
f16227e
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 9, 2022
8b500b7
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 10, 2022
35d4467
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 10, 2022
f494c42
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 13, 2022
760e8ad
fixup
qw4990 Jun 13, 2022
29d7b8a
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 14, 2022
f555f36
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 14, 2022
365e0eb
fixup
qw4990 Jun 14, 2022
70adb94
fixup
qw4990 Jun 14, 2022
b4368cb
fixup
qw4990 Jun 14, 2022
c2a1f5f
fixup
qw4990 Jun 14, 2022
f96e4d2
fixup
qw4990 Jun 14, 2022
bc004bf
fixup
qw4990 Jun 14, 2022
1fe7c04
fixup
qw4990 Jun 14, 2022
3bd9cec
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 14, 2022
979901a
fixup
qw4990 Jun 14, 2022
4f5f810
fixup
qw4990 Jun 14, 2022
d51ceb2
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 14, 2022
467ea04
fixup
qw4990 Jun 14, 2022
827de8c
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 15, 2022
8e2bf80
fixup
qw4990 Jun 15, 2022
e19bdaa
fixup
qw4990 Jun 16, 2022
6405d51
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 16, 2022
7ddf124
fixup
qw4990 Jun 17, 2022
a859b1a
Merge remote-tracking branch 'upstream/master' into cost-model-2
qw4990 Jun 21, 2022
db61c94
fixup
qw4990 Jun 22, 2022
5d2a1a0
fixup
qw4990 Jun 22, 2022
3c1c812
fixup
qw4990 Jun 22, 2022
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
68 changes: 59 additions & 9 deletions planner/core/plan_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func hasCostFlag(costFlag, flag uint64) bool {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *basePhysicalPlan) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p.self, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
// just calculate the cost once and always reuse it
return p.planCost, nil
Expand All @@ -63,6 +64,7 @@ func (p *basePhysicalPlan) GetPlanCost(taskType property.TaskType, costFlag uint

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalSelection) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -119,6 +121,7 @@ func (p *PhysicalProjection) GetCost(count float64) float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalProjection) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -180,6 +183,7 @@ func (p *PhysicalIndexLookUpReader) GetCost(costFlag uint64) (cost float64) {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexLookUpReader) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -250,6 +254,7 @@ func (p *PhysicalIndexLookUpReader) estNumDoubleReadTasks(costFlag uint64) float

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexReader) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand All @@ -274,6 +279,7 @@ func (p *PhysicalIndexReader) GetPlanCost(taskType property.TaskType, costFlag u

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalTableReader) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -342,6 +348,7 @@ func (p *PhysicalTableReader) GetPlanCost(taskType property.TaskType, costFlag u

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexMergeReader) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -388,6 +395,7 @@ func (p *PhysicalIndexMergeReader) GetPlanCost(taskType property.TaskType, costF

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalTableScan) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -425,6 +433,7 @@ func (p *PhysicalTableScan) GetPlanCost(taskType property.TaskType, costFlag uin

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexScan) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -503,6 +512,7 @@ func (p *PhysicalIndexJoin) GetCost(outerCnt, innerCnt float64, outerCost, inner

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexJoin) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -584,6 +594,7 @@ func (p *PhysicalIndexHashJoin) GetCost(outerCnt, innerCnt, outerCost, innerCost

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexHashJoin) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -667,6 +678,7 @@ func (p *PhysicalIndexMergeJoin) GetCost(outerCnt, innerCnt, outerCost, innerCos

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalIndexMergeJoin) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -715,6 +727,7 @@ func (p *PhysicalApply) GetCost(lCount, rCount, lCost, rCost float64) float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalApply) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand All @@ -735,7 +748,7 @@ func (p *PhysicalApply) GetPlanCost(taskType property.TaskType, costFlag uint64)
}

// GetCost computes cost of merge join operator itself.
func (p *PhysicalMergeJoin) GetCost(lCnt, rCnt float64) float64 {
func (p *PhysicalMergeJoin) GetCost(lCnt, rCnt float64, costFlag uint64) float64 {
outerCnt := lCnt
innerCnt := rCnt
innerKeys := p.RightJoinKeys
Expand Down Expand Up @@ -766,6 +779,9 @@ func (p *PhysicalMergeJoin) GetCost(lCnt, rCnt float64) float64 {
numPairs = 0
}
}
if hasCostFlag(costFlag, CostFlagUseTrueCardinality) {
numPairs = getOperatorActRows(p)
}
sessVars := p.ctx.GetSessionVars()
probeCost := numPairs * sessVars.GetCPUFactor()
// Cost of evaluating outer filters.
Expand All @@ -784,6 +800,7 @@ func (p *PhysicalMergeJoin) GetCost(lCnt, rCnt float64) float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalMergeJoin) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand All @@ -795,13 +812,13 @@ func (p *PhysicalMergeJoin) GetPlanCost(taskType property.TaskType, costFlag uin
}
p.planCost += childCost
}
p.planCost += p.GetCost(getCardinality(p.children[0], costFlag), getCardinality(p.children[1], costFlag))
p.planCost += p.GetCost(getCardinality(p.children[0], costFlag), getCardinality(p.children[1], costFlag), costFlag)
p.planCostInit = true
return p.planCost, nil
}

// GetCost computes cost of hash join operator itself.
func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64) float64 {
func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64, isMPP bool, costFlag uint64) float64 {
buildCnt, probeCnt := lCnt, rCnt
build := p.children[0]
// Taking the right as the inner for right join or using the outer to build a hash table.
Expand All @@ -815,7 +832,13 @@ func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64) float64 {
rowSize := getAvgRowSize(build.statsInfo(), build.Schema())
spill := oomUseTmpStorage && memQuota > 0 && rowSize*buildCnt > float64(memQuota) && p.storeTp != kv.TiFlash
// Cost of building hash table.
cpuCost := buildCnt * sessVars.GetCPUFactor()
var cpuFactor float64
if !isMPP {
cpuFactor = sessVars.GetCPUFactor()
} else {
cpuFactor = sessVars.GetTiFlashCPUFactor()
}
cpuCost := buildCnt * cpuFactor
memoryCost := buildCnt * sessVars.GetMemoryFactor()
diskCost := buildCnt * sessVars.GetDiskFactor() * rowSize
// Number of matched row pairs regarding the equal join conditions.
Expand Down Expand Up @@ -845,16 +868,20 @@ func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64) float64 {
numPairs = 0
}
}

if hasCostFlag(costFlag, CostFlagUseTrueCardinality) {
numPairs = getOperatorActRows(p)
}
// Cost of querying hash table is cheap actually, so we just compute the cost of
// evaluating `OtherConditions` and joining row pairs.
probeCost := numPairs * sessVars.GetCPUFactor()
probeCost := numPairs * cpuFactor
probeDiskCost := numPairs * sessVars.GetDiskFactor() * rowSize
// Cost of evaluating outer filter.
if len(p.LeftConditions)+len(p.RightConditions) > 0 {
// Input outer count for the above compution should be adjusted by SelectionFactor.
probeCost *= SelectionFactor
probeDiskCost *= SelectionFactor
probeCost += probeCnt * sessVars.GetCPUFactor()
probeCost += probeCnt * cpuFactor
}
diskCost += probeDiskCost
probeCost /= float64(p.Concurrency)
Expand All @@ -864,9 +891,9 @@ func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64) float64 {
if p.UseOuterToBuild {
if spill {
// It runs in sequence when build data is on disk. See handleUnmatchedRowsFromHashTableInDisk
cpuCost += buildCnt * sessVars.GetCPUFactor()
cpuCost += buildCnt * cpuFactor
} else {
cpuCost += buildCnt * sessVars.GetCPUFactor() / float64(p.Concurrency)
cpuCost += buildCnt * cpuFactor / float64(p.Concurrency)
}
diskCost += buildCnt * sessVars.GetDiskFactor() * rowSize
}
Expand All @@ -881,6 +908,7 @@ func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64) float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalHashJoin) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand All @@ -892,7 +920,7 @@ func (p *PhysicalHashJoin) GetPlanCost(taskType property.TaskType, costFlag uint
}
p.planCost += childCost
}
p.planCost += p.GetCost(getCardinality(p.children[0], costFlag), getCardinality(p.children[1], costFlag))
p.planCost += p.GetCost(getCardinality(p.children[0], costFlag), getCardinality(p.children[1], costFlag), taskType == property.MppTaskType, costFlag)
p.planCostInit = true
return p.planCost, nil
}
Expand Down Expand Up @@ -921,6 +949,7 @@ func (p *PhysicalStreamAgg) GetCost(inputRows float64, isRoot, isMPP bool, costF

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalStreamAgg) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -968,6 +997,7 @@ func (p *PhysicalHashAgg) GetCost(inputRows float64, isRoot, isMPP bool, costFla

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalHashAgg) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -1015,6 +1045,7 @@ func (p *PhysicalSort) GetCost(count float64, schema *expression.Schema) float64

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalSort) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -1053,6 +1084,7 @@ func (p *PhysicalTopN) GetCost(count float64, isRoot bool) float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalTopN) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -1090,6 +1122,7 @@ func (p *BatchPointGetPlan) GetCost() float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *BatchPointGetPlan) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -1120,6 +1153,7 @@ func (p *PointGetPlan) GetCost() float64 {

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PointGetPlan) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand All @@ -1130,6 +1164,7 @@ func (p *PointGetPlan) GetPlanCost(taskType property.TaskType, costFlag uint64)

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalUnionAll) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand All @@ -1148,6 +1183,7 @@ func (p *PhysicalUnionAll) GetPlanCost(taskType property.TaskType, costFlag uint

// GetPlanCost calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalExchangeReceiver) GetPlanCost(taskType property.TaskType, costFlag uint64) (float64, error) {
defer updateEstRows(p, costFlag)
if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) {
return p.planCost, nil
}
Expand Down Expand Up @@ -1180,6 +1216,20 @@ func getOperatorActRows(operator PhysicalPlan) float64 {
return actRows
}

func updateEstRows(operator PhysicalPlan, costFlag uint64) {
if operator == nil {
return
}
if !hasCostFlag(costFlag, CostFlagUseTrueCardinality) {
return
}

actRows := getOperatorActRows(operator)
stats := operator.Stats()
newStats := &property.StatsInfo{RowCount: actRows}
*stats = *newStats
}

func getCardinality(operator PhysicalPlan, costFlag uint64) float64 {
if hasCostFlag(costFlag, CostFlagUseTrueCardinality) {
return getOperatorActRows(operator)
Expand Down
8 changes: 4 additions & 4 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (p *PhysicalHashJoin) attach2Task(tasks ...task) task {
p.SetChildren(lTask.plan(), rTask.plan())
task := &rootTask{
p: p,
cst: lTask.cost() + rTask.cost() + p.GetCost(lTask.count(), rTask.count()),
cst: lTask.cost() + rTask.cost() + p.GetCost(lTask.count(), rTask.count(), false, 0),
}
p.cost = task.cost()
return task
Expand Down Expand Up @@ -547,7 +547,7 @@ func (p *PhysicalHashJoin) attach2TaskForMpp(tasks ...task) task {
outerTask = rTask
}
task := &mppTask{
cst: lCost + rCost + p.GetCost(lTask.count(), rTask.count()),
cst: lCost + rCost + p.GetCost(lTask.count(), rTask.count(), false, 0),
p: p,
partTp: outerTask.partTp,
hashCols: outerTask.hashCols,
Expand Down Expand Up @@ -578,7 +578,7 @@ func (p *PhysicalHashJoin) attach2TaskForTiFlash(tasks ...task) task {
tblColHists: rTask.tblColHists,
indexPlanFinished: true,
tablePlan: p,
cst: lCost + rCost + p.GetCost(lTask.count(), rTask.count()),
cst: lCost + rCost + p.GetCost(lTask.count(), rTask.count(), false, 0),
}
p.cost = task.cst
return task
Expand All @@ -590,7 +590,7 @@ func (p *PhysicalMergeJoin) attach2Task(tasks ...task) task {
p.SetChildren(lTask.plan(), rTask.plan())
t := &rootTask{
p: p,
cst: lTask.cost() + rTask.cost() + p.GetCost(lTask.count(), rTask.count()),
cst: lTask.cost() + rTask.cost() + p.GetCost(lTask.count(), rTask.count(), 0),
}
p.cost = t.cost()
return t
Expand Down
4 changes: 2 additions & 2 deletions planner/implementation/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (impl *HashJoinImpl) CalcCost(outCount float64, children ...memo.Implementa
hashJoin := impl.plan.(*plannercore.PhysicalHashJoin)
// The children here are only used to calculate the cost.
hashJoin.SetChildren(children[0].GetPlan(), children[1].GetPlan())
selfCost := hashJoin.GetCost(children[0].GetPlan().StatsCount(), children[1].GetPlan().StatsCount())
selfCost := hashJoin.GetCost(children[0].GetPlan().StatsCount(), children[1].GetPlan().StatsCount(), false, 0)
impl.cost = selfCost + children[0].GetCost() + children[1].GetCost()
return impl.cost
}
Expand All @@ -56,7 +56,7 @@ func (impl *MergeJoinImpl) CalcCost(outCount float64, children ...memo.Implement
mergeJoin := impl.plan.(*plannercore.PhysicalMergeJoin)
// The children here are only used to calculate the cost.
mergeJoin.SetChildren(children[0].GetPlan(), children[1].GetPlan())
selfCost := mergeJoin.GetCost(children[0].GetPlan().StatsCount(), children[1].GetPlan().StatsCount())
selfCost := mergeJoin.GetCost(children[0].GetPlan().StatsCount(), children[1].GetPlan().StatsCount(), 0)
impl.cost = selfCost + children[0].GetCost() + children[1].GetCost()
return impl.cost
}
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ const (
DefOptNetworkFactorV2 = 4.0
DefOptScanFactorV2 = 100.0
DefOptDescScanFactorV2 = 150.0
DefOptTiFlashScanFactorV2 = 15.0
DefOptTiFlashScanFactorV2 = 5.0
DefOptSeekFactorV2 = 9500000.0
DefOptMemoryFactorV2 = 0.001
DefOptDiskFactorV2 = 1.5
Expand Down