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) (#56411)

ref #55126
  • Loading branch information
ti-chi-bot authored Nov 12, 2024
1 parent a0fdddb commit 2709f89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions planner/core/casetest/testdata/plan_normalized_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,17 @@
" TableReader root ",
" └─ExchangeSender cop[tiflash] ",
" └─Projection cop[tiflash] test.t1.a",
" └─Selection cop[tiflash] gt(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, ?)",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.b, ?), keep order:false"
]
},
{
"SQL": "explain select * from t1 where a>1 and b>1 and c>1",
"Plan": [
" TableReader root ",
" └─ExchangeSender cop[tiflash] ",
" └─Selection cop[tiflash] gt(test.t1.b, ?)",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.a, ?), 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.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"
" └─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"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions planner/core/plan_cost_ver2.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,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*math.Max(math.Log2(rowSize), 0)*scanFactor.Value,
func() string { return fmt.Sprintf("scan(%v*logrowsize(%v)*%v)", rows, rowSize, scanFactor) })
}

Expand Down Expand Up @@ -1046,7 +1046,7 @@ func sumCostVer2(costs ...costVer2) (ret costVer2) {
return
}
for i, c := range costs {
ret.cost += c.cost
ret.cost += math.Max(c.cost, 0)
if c.trace != nil {
if i == 0 { // init
ret.trace = &costTrace{make(map[string]float64), ""}
Expand Down
4 changes: 2 additions & 2 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ func (p *PhysicalIndexJoin) attach2Task(tasks ...task) task {

func getAvgRowSize(stats *property.StatsInfo, cols []*expression.Column) (size float64) {
if stats.HistColl != nil {
size = stats.HistColl.GetAvgRowSizeListInDisk(cols)
size = math.Max(stats.HistColl.GetAvgRowSizeListInDisk(cols), 0)
} else {
// Estimate using just the type info.
for _, col := range cols {
size += float64(chunk.EstimateTypeWidth(col.GetType()))
size += math.Max(float64(chunk.EstimateTypeWidth(col.GetType())), 0)
}
}
return
Expand Down

0 comments on commit 2709f89

Please sign in to comment.