Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: remove the lower bound of auto analyze ratio (#13995) #14015

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
return "", err
}
return v, nil
case TiDBAutoAnalyzeRatio:
v, err := strconv.ParseFloat(value, 64)
if err != nil || v < 0 {
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
}
return value, nil
case TxnIsolation, TransactionIsolation:
upVal := strings.ToUpper(value)
_, exists := TxIsolationNames[upVal]
Expand Down
11 changes: 2 additions & 9 deletions statistics/handle/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,9 @@ func NeedAnalyzeTable(tbl *statistics.Table, limit time.Duration, autoAnalyzeRat
return false, ""
}
// Tests if current time is within the time period.
return withinTimePeriod(start, end, now), fmt.Sprintf("too many modifications(%v/%v)", tbl.ModifyCount, tbl.Count)
return withinTimePeriod(start, end, now), fmt.Sprintf("too many modifications(%v/%v>%v)", tbl.ModifyCount, tbl.Count, autoAnalyzeRatio)
}

const (
minAutoAnalyzeRatio = 0.3
)

func (h *Handle) getAutoAnalyzeParameters() map[string]string {
sql := fmt.Sprintf("select variable_name, variable_value from mysql.global_variables where variable_name in ('%s', '%s', '%s')",
variable.TiDBAutoAnalyzeRatio, variable.TiDBAutoAnalyzeStartTime, variable.TiDBAutoAnalyzeEndTime)
Expand All @@ -675,10 +671,7 @@ func parseAutoAnalyzeRatio(ratio string) float64 {
if err != nil {
return variable.DefAutoAnalyzeRatio
}
if autoAnalyzeRatio > 0 {
autoAnalyzeRatio = math.Max(autoAnalyzeRatio, minAutoAnalyzeRatio)
}
return autoAnalyzeRatio
return math.Max(autoAnalyzeRatio, 0)
}

func parseAnalyzePeriod(start, end string) (time.Time, time.Time, error) {
Expand Down
22 changes: 11 additions & 11 deletions statistics/handle/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) {
testKit.MustExec("create table t (a varchar(20))")

handle.AutoAnalyzeMinCnt = 0
testKit.MustExec("set global tidb_auto_analyze_ratio = 0.6")
testKit.MustExec("set global tidb_auto_analyze_ratio = 0.2")
defer func() {
handle.AutoAnalyzeMinCnt = 1000
testKit.MustExec("set global tidb_auto_analyze_ratio = 0.0")
Expand All @@ -392,18 +392,18 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) {
stats := h.GetTableStats(tableInfo)
c.Assert(stats.Count, Equals, int64(0))

_, err = testKit.Exec("insert into t values ('ss')")
_, err = testKit.Exec("insert into t values ('ss'), ('ss'), ('ss'), ('ss'), ('ss')")
c.Assert(err, IsNil)
c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil)
c.Assert(h.Update(is), IsNil)
h.HandleAutoAnalyze(is)
c.Assert(h.Update(is), IsNil)
stats = h.GetTableStats(tableInfo)
c.Assert(stats.Count, Equals, int64(1))
c.Assert(stats.Count, Equals, int64(5))
c.Assert(stats.ModifyCount, Equals, int64(0))
for _, item := range stats.Columns {
// TotColSize = 2(length of 'ss') + 1(size of len byte).
c.Assert(item.TotColSize, Equals, int64(3))
// TotColSize = 5*(2(length of 'ss') + 1(size of len byte)).
c.Assert(item.TotColSize, Equals, int64(15))
break
}

Expand All @@ -417,7 +417,7 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) {
h.HandleAutoAnalyze(is)
c.Assert(h.Update(is), IsNil)
stats = h.GetTableStats(tableInfo)
c.Assert(stats.Count, Equals, int64(2))
c.Assert(stats.Count, Equals, int64(6))
c.Assert(stats.ModifyCount, Equals, int64(1))

_, err = testKit.Exec("insert into t values ('fff')")
Expand All @@ -427,7 +427,7 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) {
h.HandleAutoAnalyze(is)
c.Assert(h.Update(is), IsNil)
stats = h.GetTableStats(tableInfo)
c.Assert(stats.Count, Equals, int64(3))
c.Assert(stats.Count, Equals, int64(7))
c.Assert(stats.ModifyCount, Equals, int64(0))

_, err = testKit.Exec("insert into t values ('eee')")
Expand All @@ -437,12 +437,12 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) {
h.HandleAutoAnalyze(is)
c.Assert(h.Update(is), IsNil)
stats = h.GetTableStats(tableInfo)
c.Assert(stats.Count, Equals, int64(4))
c.Assert(stats.Count, Equals, int64(8))
// Modify count is non-zero means that we do not analyze the table.
c.Assert(stats.ModifyCount, Equals, int64(1))
for _, item := range stats.Columns {
// TotColSize = 6, because the table has not been analyzed, and insert statement will add 3(length of 'eee') to TotColSize.
c.Assert(item.TotColSize, Equals, int64(14))
// TotColSize = 26, because the table has not been analyzed, and insert statement will add 3(length of 'eee') to TotColSize.
c.Assert(item.TotColSize, Equals, int64(26))
break
}

Expand All @@ -456,7 +456,7 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) {
h.HandleAutoAnalyze(is)
c.Assert(h.Update(is), IsNil)
stats = h.GetTableStats(tableInfo)
c.Assert(stats.Count, Equals, int64(4))
c.Assert(stats.Count, Equals, int64(8))
c.Assert(stats.ModifyCount, Equals, int64(0))
hg, ok := stats.Indices[tableInfo.Indices[0].ID]
c.Assert(ok, IsTrue)
Expand Down