Skip to content

Commit

Permalink
planner: Set minimum cost to avoid parent multiplication cost discrep…
Browse files Browse the repository at this point in the history
…ancies (#56387) (#56412)

ref #55126
  • Loading branch information
ti-chi-bot committed Sep 30, 2024
1 parent 02029fd commit cceec97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@
"Plan": [
" TableReader root ",
" └─ExchangeSender cop[tiflash] ",
" └─Selection cop[tiflash] gt(test.t1.a, ?)",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.b, ?), gt(test.t1.c, ?), keep order:false"
" └─Selection cop[tiflash] gt(test.t1.c, ?)",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.a, ?), gt(test.t1.b, ?), keep order:false"
]
},
{
Expand All @@ -443,8 +443,8 @@
"Plan": [
" TableReader root ",
" └─ExchangeSender cop[tiflash] ",
" └─Selection cop[tiflash] gt(test.t1.a, ?), or(lt(test.t1.a, ?), lt(test.t1.b, ?))",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.b, ?), keep order:false"
" └─Selection cop[tiflash] gt(test.t1.b, ?), or(lt(test.t1.a, ?), lt(test.t1.b, ?))",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.a, ?), keep order:false"
]
},
{
Expand All @@ -461,8 +461,8 @@
"Plan": [
" TableReader root ",
" └─ExchangeSender cop[tiflash] ",
" └─Selection cop[tiflash] gt(test.t1.b, ?), gt(test.t1.c, ?), or(gt(test.t1.a, ?), lt(test.t1.b, ?))",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.a, ?), keep order:false"
" └─Selection cop[tiflash] gt(test.t1.a, ?), gt(test.t1.c, ?), or(gt(test.t1.a, ?), lt(test.t1.b, ?))",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.b, ?), keep order:false"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/plan_cost_ver2.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func scanCostVer2(option *PlanCostOption, rows, rowSize float64, scanFactor cost
}
return newCostVer2(option, scanFactor,
// rows * log(row-size) * scanFactor, log2 from experiments
rows*math.Log2(rowSize)*scanFactor.Value,
rows*max(math.Log2(rowSize), 0)*scanFactor.Value,
func() string { return fmt.Sprintf("scan(%v*logrowsize(%v)*%v)", rows, rowSize, scanFactor) })
}

Expand Down Expand Up @@ -852,7 +852,7 @@ func orderCostVer2(option *PlanCostOption, rows, n float64, byItems []*util.ByIt
rows*float64(numFuncs)*cpuFactor.Value,
func() string { return fmt.Sprintf("exprCPU(%v*%v*%v)", rows, numFuncs, cpuFactor) })
orderCost := newCostVer2(option, cpuFactor,
rows*math.Log2(n)*cpuFactor.Value,
max(rows*math.Log2(n), 0)*cpuFactor.Value,
func() string { return fmt.Sprintf("orderCPU(%v*log(%v)*%v)", rows, n, cpuFactor) })
return sumCostVer2(exprCost, orderCost)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ func (p *PhysicalIndexJoin) attach2Task(tasks ...task) task {
// RowSize for cost model ver2 is simplified, always use this function to calculate row size.
func getAvgRowSize(stats *property.StatsInfo, cols []*expression.Column) (size float64) {
if stats.HistColl != nil {
size = cardinality.GetAvgRowSizeListInDisk(stats.HistColl, cols)
size = max(cardinality.GetAvgRowSizeListInDisk(stats.HistColl, cols), 0)
} else {
// Estimate using just the type info.
for _, col := range cols {
size += float64(chunk.EstimateTypeWidth(col.GetType()))
size += max(float64(chunk.EstimateTypeWidth(col.GetType())), 0)
}
}
return
Expand Down

0 comments on commit cceec97

Please sign in to comment.