planner: Set minimum cost to avoid parent multiplication cost discrepancies (#56387)
ref pingcap/tidb#55126
This commit is contained in:
@ -419,8 +419,8 @@
|
||||
" 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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -428,8 +428,8 @@
|
||||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -445,8 +445,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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -454,8 +454,8 @@
|
||||
"Plan": [
|
||||
" TableReader root ",
|
||||
" └─ExchangeSender cop[tiflash] ",
|
||||
" └─Selection cop[tiflash] gt(test.t1.a, ?), gt(test.t1.c, ?), 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, ?), gt(test.t1.c, ?), 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"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@ -820,7 +820,7 @@ func scanCostVer2(option *optimizetrace.PlanCostOption, rows, rowSize float64, s
|
||||
}
|
||||
return costusage.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) })
|
||||
}
|
||||
|
||||
@ -874,7 +874,7 @@ func orderCostVer2(option *optimizetrace.PlanCostOption, rows, n float64, byItem
|
||||
rows*float64(numFuncs)*cpuFactor.Value,
|
||||
func() string { return fmt.Sprintf("exprCPU(%v*%v*%v)", rows, numFuncs, cpuFactor) })
|
||||
orderCost := costusage.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 costusage.SumCostVer2(exprCost, orderCost)
|
||||
}
|
||||
|
||||
@ -179,11 +179,11 @@ func (p *PhysicalIndexJoin) Attach2Task(tasks ...base.Task) base.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.GetAvgRowSizeDataInDiskByRows(stats.HistColl, cols)
|
||||
size = max(cardinality.GetAvgRowSizeDataInDiskByRows(stats.HistColl, cols), 0)
|
||||
} else {
|
||||
// Estimate using just the type info.
|
||||
for _, col := range cols {
|
||||
size += float64(chunk.EstimateTypeWidth(col.GetStaticType()))
|
||||
size += max(float64(chunk.EstimateTypeWidth(col.GetStaticType())), 0)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@ -59,7 +59,7 @@ type CostVer2 struct {
|
||||
|
||||
// GetCost returns the cost value of the costVer2
|
||||
func (c *CostVer2) GetCost() float64 {
|
||||
return c.cost
|
||||
return max(c.cost, 0)
|
||||
}
|
||||
|
||||
// GetTrace returns the trace of current costVer2
|
||||
|
||||
Reference in New Issue
Block a user