Skip to content

Commit

Permalink
Revert "[Performance]: Point queries based on primary keys do not nee…
Browse files Browse the repository at this point in the history
…d complete stats calculation process (matrixorigin#13718) (matrixorigin#13752)

this pr cause tpcc performance regression. revert this pr

Approved by: @ouyuanning
  • Loading branch information
badboynt1 authored Dec 23, 2023
1 parent eb4795a commit e68cf30
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions pkg/sql/plan/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,16 +879,14 @@ func calcScanStats(node *plan.Node, builder *QueryBuilder) *plan.Stats {
if !needStats(node.TableDef) {
return DefaultStats()
}
//get statsInfoMap from statscache
s := getStatsInfoByTableID(node.TableDef.TblId, builder)
if s != nil && shouldReturnMinimalStats(node, s) {
return DefaultMinimalStats(s.TableCnt)
if shouldReturnMinimalStats(node) {
return DefaultMinimalStats()
}
if !builder.compCtx.Stats(node.ObjRef) {
return DefaultStats()
}
//get statsInfoMap from statscache again
s = getStatsInfoByTableID(node.TableDef.TblId, builder)
//get statsInfoMap from statscache
s := getStatsInfoByTableID(node.TableDef.TblId, builder)
if s == nil {
return DefaultStats()
}
Expand Down Expand Up @@ -917,37 +915,8 @@ func calcScanStats(node *plan.Node, builder *QueryBuilder) *plan.Stats {
return stats
}

func shouldReturnMinimalStats(node *plan.Node, s *StatsInfoMap) bool {
if node.NodeType != plan.Node_TABLE_SCAN {
return false
}
if len(node.FilterList) == 0 {
return false
}
if node.TableDef.Pkey == nil {
return false
}
if s.TableCnt < 10000 {
return false
}
equalCol := make([]int32, 0)
for _, expr := range node.FilterList {
equiCond, ok := expr.Expr.(*plan.Expr_F)
if !ok {
continue
}
if equiCond.F.Func.GetObjName() != "=" {
continue
}
leftcol, ok := equiCond.F.Args[0].Expr.(*plan.Expr_Col)
if !ok {
continue
}
if HasColExpr(equiCond.F.Args[1], -1) == -1 {
equalCol = append(equalCol, leftcol.Col.ColPos)
}
}
return containsAllPKs(equalCol, node.TableDef)
func shouldReturnMinimalStats(node *plan.Node) bool {
return false
}

func needStats(tableDef *TableDef) bool {
Expand Down Expand Up @@ -982,12 +951,12 @@ func DefaultStats() *plan.Stats {
return stats
}

func DefaultMinimalStats(tablecnt float64) *plan.Stats {
func DefaultMinimalStats() *plan.Stats {
stats := new(Stats)
stats.TableCnt = tablecnt
stats.Cost = 1
stats.Outcnt = 1
stats.Selectivity = 1 / tablecnt
stats.TableCnt = 100000
stats.Cost = 10
stats.Outcnt = 10
stats.Selectivity = 0.0001
stats.BlockNum = 1
return stats
}
Expand Down

0 comments on commit e68cf30

Please sign in to comment.