From 2a104d152e9f194d462c5ce84831d7e7f8c1207f Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Tue, 31 Mar 2020 13:20:32 +0800 Subject: [PATCH 1/2] statistic: fix error when fast analyze on only indexes --- executor/analyze.go | 2 +- executor/analyze_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/executor/analyze.go b/executor/analyze.go index 52f79e79664c9..95a4f310eed1b 100755 --- a/executor/analyze.go +++ b/executor/analyze.go @@ -850,7 +850,7 @@ func (e *AnalyzeFastExec) updateCollectorSamples(sValue []byte, sKey kv.Key, sam for j, idxInfo := range e.idxsInfo { idxVals := make([]types.Datum, 0, len(idxInfo.Columns)) for _, idxCol := range idxInfo.Columns { - for _, colInfo := range e.colsInfo { + for _, colInfo := range e.tblInfo.Columns { if colInfo.Name == idxCol.Name { v, err := e.getValueByInfo(colInfo, values) if err != nil { diff --git a/executor/analyze_test.go b/executor/analyze_test.go index e874dd8ef766f..4f175b2760291 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -351,6 +351,16 @@ func (s *testFastAnalyze) TestFastAnalyze(c *C) { "test t2 a 0 1 2 1 18446744073709551615 18446744073709551615")) } +func (s *testSuite1) TestIssue15752(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t0") + tk.MustExec("CREATE TABLE t0(c0 INT)") + tk.MustExec("INSERT INTO t0 VALUES (0)") + tk.MustExec("set @@tidb_enable_fast_analyze=1") + tk.MustExec("ANALYZE TABLE t0 INDEX i0") +} + func (s *testSuite1) TestAnalyzeIncremental(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") From 44a7f1b686ebae94e74295696fb68cb7112f27f2 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Tue, 31 Mar 2020 13:32:50 +0800 Subject: [PATCH 2/2] fix test --- executor/analyze_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 4f175b2760291..211673d7b0583 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -357,6 +357,7 @@ func (s *testSuite1) TestIssue15752(c *C) { tk.MustExec("drop table if exists t0") tk.MustExec("CREATE TABLE t0(c0 INT)") tk.MustExec("INSERT INTO t0 VALUES (0)") + tk.MustExec("CREATE INDEX i0 ON t0(c0)") tk.MustExec("set @@tidb_enable_fast_analyze=1") tk.MustExec("ANALYZE TABLE t0 INDEX i0") }