stats: set a min count for auto analyze (#5796)

This commit is contained in:
Han Fei
2018-02-06 18:23:48 +08:00
committed by GitHub
parent 8578ad2a95
commit b5d078b41b
2 changed files with 10 additions and 1 deletions

View File

@ -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))

View File

@ -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"))