stats: set a min count for auto analyze (#5796)
This commit is contained in:
@ -236,8 +236,11 @@ const (
|
||||
StatsPrompt = "stats"
|
||||
)
|
||||
|
||||
// AutoAnalyzeMinCnt means if the count of table is less than this value, we needn't do auto analyze.
|
||||
var AutoAnalyzeMinCnt int64 = 1000
|
||||
|
||||
func needAnalyzeTable(tbl *Table, limit time.Duration) bool {
|
||||
if tbl.ModifyCount == 0 {
|
||||
if tbl.ModifyCount == 0 || tbl.Count < AutoAnalyzeMinCnt {
|
||||
return false
|
||||
}
|
||||
t := time.Unix(0, oracle.ExtractPhysical(tbl.Version)*int64(time.Millisecond))
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"github.com/pingcap/tidb/domain"
|
||||
"github.com/pingcap/tidb/kv"
|
||||
"github.com/pingcap/tidb/model"
|
||||
"github.com/pingcap/tidb/statistics"
|
||||
"github.com/pingcap/tidb/types"
|
||||
"github.com/pingcap/tidb/util/testkit"
|
||||
"github.com/pingcap/tidb/util/testleak"
|
||||
@ -269,6 +270,11 @@ func (s *testStatsUpdateSuite) TestAutoUpdate(c *C) {
|
||||
testKit.MustExec("use test")
|
||||
testKit.MustExec("create table t (a int)")
|
||||
|
||||
statistics.AutoAnalyzeMinCnt = 0
|
||||
defer func() {
|
||||
statistics.AutoAnalyzeMinCnt = 1000
|
||||
}()
|
||||
|
||||
do := s.do
|
||||
is := do.InfoSchema()
|
||||
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
|
||||
|
||||
Reference in New Issue
Block a user