From 0d563f1e2d785d25cc812adae6e6c95514ba5f3d Mon Sep 17 00:00:00 2001 From: Haibin Xie Date: Thu, 27 Jun 2019 13:51:16 +0800 Subject: [PATCH] stats: fix unstable test (#10953) --- bindinfo/bind_test.go | 2 +- ddl/db_integration_test.go | 2 +- ddl/db_test.go | 2 +- ddl/serial_test.go | 2 +- ddl/table_split_test.go | 2 +- domain/domain.go | 7 +- executor/analyze_test.go | 4 +- executor/executor_test.go | 8 +- executor/seqtest/seq_executor_test.go | 2 +- executor/simple_test.go | 4 +- executor/update_test.go | 2 +- infoschema/tables_test.go | 18 ++-- planner/core/cbo_test.go | 14 +-- privilege/privileges/cache_test.go | 4 +- privilege/privileges/privileges_test.go | 2 +- server/statistics_handler_test.go | 2 +- server/tidb_test.go | 2 +- session/isolation_test.go | 2 +- session/pessimistic_test.go | 2 +- session/session_test.go | 4 +- session/tidb.go | 5 + statistics/cmsketch_test.go | 2 +- statistics/handle/ddl_test.go | 18 ++-- statistics/handle/dump_test.go | 8 +- statistics/handle/handle_test.go | 22 ++--- statistics/handle/update_test.go | 122 ++++++++++++------------ statistics/sample_test.go | 6 +- statistics/selectivity_test.go | 18 ++-- statistics/statistics_test.go | 10 +- types/const_test.go | 2 +- util/admin/admin_integration_test.go | 2 +- util/kvencoder/kv_encoder_test.go | 2 +- util/ranger/ranger_test.go | 2 +- 33 files changed, 159 insertions(+), 147 deletions(-) diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index 34afcc296808a..bc012e6e7db5b 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -73,7 +73,7 @@ func (s *testSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index f7fbf9a24b0b2..6312bb6354fa1 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -78,7 +78,7 @@ func setupIntegrationSuite(s *testIntegrationSuite, c *C) { ) c.Assert(err, IsNil) session.SetSchemaLease(s.lease) - session.SetStatsLease(0) + session.DisableStats4Test() s.dom, err = session.BootstrapSession(s.store) c.Assert(err, IsNil) diff --git a/ddl/db_test.go b/ddl/db_test.go index 1d3cb29ad77cf..95d4bf2e9c651 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -93,7 +93,7 @@ func setUpSuite(s *testDBSuite, c *C) { s.lease = 100 * time.Millisecond session.SetSchemaLease(s.lease) - session.SetStatsLease(0) + session.DisableStats4Test() s.schemaName = "test_db" s.autoIDStep = autoid.GetStep() ddl.WaitTimeWhenErrorOccured = 0 diff --git a/ddl/serial_test.go b/ddl/serial_test.go index 2c5c697d966b5..e01252a46d281 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -48,7 +48,7 @@ type testSerialSuite struct { func (s *testSerialSuite) SetUpSuite(c *C) { session.SetSchemaLease(200 * time.Millisecond) - session.SetStatsLease(0) + session.DisableStats4Test() ddl.WaitTimeWhenErrorOccured = 1 * time.Microsecond var err error diff --git a/ddl/table_split_test.go b/ddl/table_split_test.go index afb33d5b4044f..da4a1f96c83de 100644 --- a/ddl/table_split_test.go +++ b/ddl/table_split_test.go @@ -38,7 +38,7 @@ func (s *testDDLTableSplitSuite) TestTableSplit(c *C) { c.Assert(err, IsNil) defer store.Close() session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() atomic.StoreUint32(&ddl.EnableSplitTableRegion, 1) dom, err := session.BootstrapSession(store) c.Assert(err, IsNil) diff --git a/domain/domain.go b/domain/domain.go index 900b63df807dc..533e7ab84fa1e 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -888,8 +888,11 @@ func (do *Domain) UpdateTableStatsLoop(ctx sessionctx.Context) error { statsHandle := handle.NewHandle(ctx, do.statsLease) atomic.StorePointer(&do.statsHandle, unsafe.Pointer(statsHandle)) do.ddl.RegisterEventCh(statsHandle.DDLEventCh()) - do.wg.Add(1) - go do.loadStatsWorker() + // Negative stats lease indicates that it is in test, it does not need update. + if do.statsLease >= 0 { + do.wg.Add(1) + go do.loadStatsWorker() + } if do.statsLease <= 0 { return nil } diff --git a/executor/analyze_test.go b/executor/analyze_test.go index d07debd9b9f87..0d641ef9c9774 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -163,7 +163,7 @@ func (s *testSuite1) TestAnalyzeFastSample(c *C) { ) c.Assert(err, IsNil) var dom *domain.Domain - session.SetStatsLease(0) + session.DisableStats4Test() session.SetSchemaLease(0) dom, err = session.BootstrapSession(store) c.Assert(err, IsNil) @@ -234,7 +234,7 @@ func (s *testSuite1) TestFastAnalyze(c *C) { ) c.Assert(err, IsNil) var dom *domain.Domain - session.SetStatsLease(0) + session.DisableStats4Test() session.SetSchemaLease(0) dom, err = session.BootstrapSession(store) c.Assert(err, IsNil) diff --git a/executor/executor_test.go b/executor/executor_test.go index 8c37742e7c1c0..b02fbadbabbbd 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -123,7 +123,7 @@ func (s *testSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) @@ -3727,7 +3727,7 @@ func (s *testSuite2) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) @@ -3778,7 +3778,7 @@ func (s *testSuite3) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) @@ -3829,7 +3829,7 @@ func (s *testSuite4) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index be074db360822..e6925ce3b121d 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -91,7 +91,7 @@ func (s *seqTestSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) diff --git a/executor/simple_test.go b/executor/simple_test.go index 649814b6dce46..7997b060b74e0 100644 --- a/executor/simple_test.go +++ b/executor/simple_test.go @@ -412,7 +412,7 @@ func (s *testSuite3) TestDropStats(c *C) { c.Assert(statsTbl.Pseudo, IsFalse) testKit.MustExec("drop stats t") - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl = h.GetTableStats(tableInfo) c.Assert(statsTbl.Pseudo, IsTrue) @@ -422,7 +422,7 @@ func (s *testSuite3) TestDropStats(c *C) { h.SetLease(1) testKit.MustExec("drop stats t") - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl = h.GetTableStats(tableInfo) c.Assert(statsTbl.Pseudo, IsTrue) h.SetLease(0) diff --git a/executor/update_test.go b/executor/update_test.go index cc51e8dc02f08..e91a95dbba96c 100644 --- a/executor/update_test.go +++ b/executor/update_test.go @@ -52,7 +52,7 @@ func (s *testUpdateSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index b1eb4ea902046..d51bc45f818c7 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -48,7 +48,7 @@ func (s *testTableSuite) SetUpSuite(c *C) { var err error s.store, err = mockstore.NewMockTikvStore() c.Assert(err, IsNil) - session.SetStatsLease(0) + session.DisableStats4Test() s.dom, err = session.BootstrapSession(s.store) c.Assert(err, IsNil) } @@ -140,23 +140,23 @@ func (s *testTableSuite) TestDataForTableStatsField(c *C) { tk.MustQuery("select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t'").Check( testkit.Rows("0 0 0 0")) tk.MustExec(`insert into t(c, d, e) values(1, 2, "c"), (2, 3, "d"), (3, 4, "e")`) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) tk.MustQuery("select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t'").Check( testkit.Rows("3 17 51 3")) tk.MustExec(`insert into t(c, d, e) values(4, 5, "f")`) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) tk.MustQuery("select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t'").Check( testkit.Rows("4 17 68 4")) tk.MustExec("delete from t where c >= 3") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) tk.MustQuery("select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t'").Check( testkit.Rows("2 17 34 2")) tk.MustExec("delete from t where c=3") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) tk.MustQuery("select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t'").Check( testkit.Rows("2 17 34 2")) } diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index 890aabdc84247..33b06eefa4881 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -106,7 +106,7 @@ func (s *testAnalyzeSuite) TestCBOWithoutAnalyze(c *C) { c.Assert(h.HandleDDLEvent(<-h.DDLEventCh()), IsNil) testKit.MustExec("insert into t1 values (1), (2), (3), (4), (5), (6)") testKit.MustExec("insert into t2 values (1), (2), (3), (4), (5), (6)") - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(dom.InfoSchema()), IsNil) testKit.MustQuery("explain select * from t1, t2 where t1.a = t2.a").Check(testkit.Rows( "HashLeftJoin_8 7.49 root inner join, inner:TableReader_15, equal:[eq(test.t1.a, test.t2.a)]", @@ -196,7 +196,7 @@ func (s *testAnalyzeSuite) TestTableDual(c *C) { testKit.MustExec("insert into t values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)") c.Assert(h.HandleDDLEvent(<-h.DDLEventCh()), IsNil) - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(dom.InfoSchema()), IsNil) testKit.MustQuery(`explain select * from t where 1 = 0`).Check(testkit.Rows( @@ -226,12 +226,12 @@ func (s *testAnalyzeSuite) TestEstimation(c *C) { testKit.MustExec("insert into t select * from t") h := dom.StatsHandle() h.HandleDDLEvent(<-h.DDLEventCh()) - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) testKit.MustExec("analyze table t") for i := 1; i <= 8; i++ { testKit.MustExec("delete from t where a = ?", i) } - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(dom.InfoSchema()), IsNil) testKit.MustQuery("explain select count(*) from t group by a").Check(testkit.Rows( "HashAgg_9 2.00 root group by:col_1, funcs:count(col_0)", @@ -568,12 +568,12 @@ func (s *testAnalyzeSuite) TestOutdatedAnalyze(c *C) { } h := dom.StatsHandle() h.HandleDDLEvent(<-h.DDLEventCh()) - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) testKit.MustExec("analyze table t") testKit.MustExec("insert into t select * from t") testKit.MustExec("insert into t select * from t") testKit.MustExec("insert into t select * from t") - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(dom.InfoSchema()), IsNil) statistics.RatioOfPseudoEstimate.Store(10.0) testKit.MustQuery("explain select * from t where a <= 5 and b <= 5").Check(testkit.Rows( @@ -753,7 +753,7 @@ func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) { } session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() dom, err := session.BootstrapSession(store) if err != nil { diff --git a/privilege/privileges/cache_test.go b/privilege/privileges/cache_test.go index 6a3ffbdfa9fc1..b89d4c85f5e28 100644 --- a/privilege/privileges/cache_test.go +++ b/privilege/privileges/cache_test.go @@ -35,7 +35,7 @@ type testCacheSuite struct { func (s *testCacheSuite) SetUpSuite(c *C) { store, err := mockstore.NewMockTikvStore() session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() c.Assert(err, IsNil) s.domain, err = session.BootstrapSession(store) c.Assert(err, IsNil) @@ -276,7 +276,7 @@ func (s *testCacheSuite) TestAbnormalMySQLTable(c *C) { c.Assert(err, IsNil) defer store.Close() session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() dom, err := session.BootstrapSession(store) c.Assert(err, IsNil) diff --git a/privilege/privileges/privileges_test.go b/privilege/privileges/privileges_test.go index b75dbeeac589c..383b52d515a02 100644 --- a/privilege/privileges/privileges_test.go +++ b/privilege/privileges/privileges_test.go @@ -658,7 +658,7 @@ func mustExec(c *C, se session.Session, sql string) { func newStore(c *C, dbPath string) (*domain.Domain, kv.Storage) { store, err := mockstore.NewMockTikvStore() session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() c.Assert(err, IsNil) dom, err := session.BootstrapSession(store) c.Assert(err, IsNil) diff --git a/server/statistics_handler_test.go b/server/statistics_handler_test.go index 00c58581958b5..41fa67f6461c0 100644 --- a/server/statistics_handler_test.go +++ b/server/statistics_handler_test.go @@ -47,7 +47,7 @@ func (ds *testDumpStatsSuite) startServer(c *C) { var err error ds.store, err = mockstore.NewMockTikvStore(mockstore.WithMVCCStore(mvccStore)) c.Assert(err, IsNil) - session.SetStatsLease(0) + session.DisableStats4Test() ds.domain, err = session.BootstrapSession(ds.store) c.Assert(err, IsNil) ds.domain.SetStatsUpdating(true) diff --git a/server/tidb_test.go b/server/tidb_test.go index c8a538e481044..fb22dcb77b9b9 100644 --- a/server/tidb_test.go +++ b/server/tidb_test.go @@ -53,7 +53,7 @@ func (ts *TidbTestSuite) SetUpSuite(c *C) { metrics.RegisterMetrics() var err error ts.store, err = mockstore.NewMockTikvStore() - session.SetStatsLease(0) + session.DisableStats4Test() c.Assert(err, IsNil) ts.domain, err = session.BootstrapSession(ts.store) c.Assert(err, IsNil) diff --git a/session/isolation_test.go b/session/isolation_test.go index 630daa5dbc177..4e9f57e220a69 100644 --- a/session/isolation_test.go +++ b/session/isolation_test.go @@ -47,7 +47,7 @@ func (s *testIsolationSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() s.dom, err = session.BootstrapSession(s.store) c.Assert(err, IsNil) diff --git a/session/pessimistic_test.go b/session/pessimistic_test.go index 30cd2146075e8..5b8417f4fb8ba 100644 --- a/session/pessimistic_test.go +++ b/session/pessimistic_test.go @@ -57,7 +57,7 @@ func (s *testPessimisticSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() s.dom, err = session.BootstrapSession(s.store) c.Assert(err, IsNil) } diff --git a/session/session_test.go b/session/session_test.go index b2f05bee9158b..e5ffb7cc54243 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -72,7 +72,7 @@ func (s *testSessionSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() s.dom, err = session.BootstrapSession(s.store) c.Assert(err, IsNil) } @@ -1703,7 +1703,7 @@ func (s *testSchemaSuite) SetUpSuite(c *C) { s.store = store s.lease = 20 * time.Millisecond session.SetSchemaLease(s.lease) - session.SetStatsLease(0) + session.DisableStats4Test() dom, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) s.dom = dom diff --git a/session/tidb.go b/session/tidb.go index 06c069ea1f927..284a9b9430ccd 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -128,6 +128,11 @@ func SetStatsLease(lease time.Duration) { statsLease = lease } +// DisableStats4Test disables the stats for tests. +func DisableStats4Test() { + statsLease = -1 +} + // Parse parses a query string to raw ast.StmtNode. func Parse(ctx sessionctx.Context, src string) ([]ast.StmtNode, error) { logutil.BgLogger().Debug("compiling", zap.String("source", src)) diff --git a/statistics/cmsketch_test.go b/statistics/cmsketch_test.go index ac04e01429b6b..0c6508f4524a5 100644 --- a/statistics/cmsketch_test.go +++ b/statistics/cmsketch_test.go @@ -240,7 +240,7 @@ func (s *testStatisticsSuite) TestMergeCMSketch4IncrementalAnalyze(c *C) { for key, val := range rMap { lMap[key] += val } - lSketch.MergeCMSketch4IncrementalAnalyze(rSketch) + c.Assert(lSketch.MergeCMSketch4IncrementalAnalyze(rSketch), IsNil) avg, err = averageAbsoluteError(lSketch, lMap) c.Assert(err, IsNil) c.Check(avg, LessEqual, t.avgError) diff --git a/statistics/handle/ddl_test.go b/statistics/handle/ddl_test.go index 769a7093bb59d..a85d40e154bef 100644 --- a/statistics/handle/ddl_test.go +++ b/statistics/handle/ddl_test.go @@ -68,7 +68,7 @@ func (s *testStatsSuite) TestDDLTable(c *C) { h := do.StatsHandle() err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl := h.GetTableStats(tableInfo) c.Assert(statsTbl.Pseudo, IsFalse) @@ -79,7 +79,7 @@ func (s *testStatsSuite) TestDDLTable(c *C) { tableInfo = tbl.Meta() err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl = h.GetTableStats(tableInfo) c.Assert(statsTbl.Pseudo, IsFalse) @@ -90,7 +90,7 @@ func (s *testStatsSuite) TestDDLTable(c *C) { tableInfo = tbl.Meta() err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl = h.GetTableStats(tableInfo) c.Assert(statsTbl.Pseudo, IsFalse) } @@ -111,7 +111,7 @@ func (s *testStatsSuite) TestDDLHistogram(c *C) { err := h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) is := do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tableInfo := tbl.Meta() @@ -124,7 +124,7 @@ func (s *testStatsSuite) TestDDLHistogram(c *C) { err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) is = do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tableInfo = tbl.Meta() @@ -142,7 +142,7 @@ func (s *testStatsSuite) TestDDLHistogram(c *C) { err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) is = do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tableInfo = tbl.Meta() @@ -154,7 +154,7 @@ func (s *testStatsSuite) TestDDLHistogram(c *C) { err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) is = do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tableInfo = tbl.Meta() @@ -191,7 +191,7 @@ PARTITION BY RANGE ( a ) ( h := do.StatsHandle() err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) pi := tableInfo.GetPartitionInfo() for _, def := range pi.Definitions { statsTbl := h.GetPartitionStats(tableInfo, def.ID) @@ -204,7 +204,7 @@ PARTITION BY RANGE ( a ) ( err = h.HandleDDLEvent(<-h.DDLEventCh()) c.Assert(err, IsNil) is = do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tableInfo = tbl.Meta() diff --git a/statistics/handle/dump_test.go b/statistics/handle/dump_test.go index 72fa7d3a6b7c0..628652c6ae7ca 100644 --- a/statistics/handle/dump_test.go +++ b/statistics/handle/dump_test.go @@ -35,8 +35,8 @@ func (s *testStatsSuite) TestConversion(c *C) { tk.MustExec("insert into t(a,b) values (1, 1),(3, 1),(5, 10)") is := s.do.InfoSchema() h := s.do.StatsHandle() - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) tableInfo, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) @@ -73,7 +73,7 @@ PARTITION BY RANGE ( a ) ( tk.MustExec("analyze table t") is := s.do.InfoSchema() h := s.do.StatsHandle() - h.Update(is) + c.Assert(h.Update(is), IsNil) table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) @@ -131,7 +131,7 @@ func (s *testStatsSuite) TestDumpCMSketchWithTopN(c *C) { c.Assert(err, IsNil) tableInfo := tbl.Meta() h := s.do.StatsHandle() - h.Update(is) + c.Assert(h.Update(is), IsNil) // Insert 30 fake data fakeData := make([][]byte, 0, 30) diff --git a/statistics/handle/handle_test.go b/statistics/handle/handle_test.go index 2c3aebfb00687..1d53e53ed2e16 100644 --- a/statistics/handle/handle_test.go +++ b/statistics/handle/handle_test.go @@ -246,7 +246,7 @@ func (s *testStatsSuite) TestVersion(c *C) { unit := oracle.ComposeTS(1, 0) testKit.MustExec("update mysql.stats_meta set version = ? where table_id = ?", 2*unit, tableInfo1.ID) - h.Update(is) + c.Assert(h.Update(is), IsNil) c.Assert(h.LastUpdateVersion(), Equals, 2*unit) statsTbl1 := h.GetTableStats(tableInfo1) c.Assert(statsTbl1.Pseudo, IsFalse) @@ -259,7 +259,7 @@ func (s *testStatsSuite) TestVersion(c *C) { tableInfo2 := tbl2.Meta() // A smaller version write, and we can still read it. testKit.MustExec("update mysql.stats_meta set version = ? where table_id = ?", unit, tableInfo2.ID) - h.Update(is) + c.Assert(h.Update(is), IsNil) c.Assert(h.LastUpdateVersion(), Equals, 2*unit) statsTbl2 := h.GetTableStats(tableInfo2) c.Assert(statsTbl2.Pseudo, IsFalse) @@ -268,7 +268,7 @@ func (s *testStatsSuite) TestVersion(c *C) { testKit.MustExec("analyze table t1") offset := 3 * unit testKit.MustExec("update mysql.stats_meta set version = ? where table_id = ?", offset+4, tableInfo1.ID) - h.Update(is) + c.Assert(h.Update(is), IsNil) c.Assert(h.LastUpdateVersion(), Equals, offset+uint64(4)) statsTbl1 = h.GetTableStats(tableInfo1) c.Assert(statsTbl1.Count, Equals, int64(1)) @@ -277,7 +277,7 @@ func (s *testStatsSuite) TestVersion(c *C) { testKit.MustExec("analyze table t2") // A smaller version write, and we can still read it. testKit.MustExec("update mysql.stats_meta set version = ? where table_id = ?", offset+3, tableInfo2.ID) - h.Update(is) + c.Assert(h.Update(is), IsNil) c.Assert(h.LastUpdateVersion(), Equals, offset+uint64(4)) statsTbl2 = h.GetTableStats(tableInfo2) c.Assert(statsTbl2.Count, Equals, int64(1)) @@ -286,7 +286,7 @@ func (s *testStatsSuite) TestVersion(c *C) { testKit.MustExec("analyze table t2") // A smaller version write, and we cannot read it. Because at this time, lastThree Version is 4. testKit.MustExec("update mysql.stats_meta set version = 1 where table_id = ?", tableInfo2.ID) - h.Update(is) + c.Assert(h.Update(is), IsNil) c.Assert(h.LastUpdateVersion(), Equals, offset+uint64(4)) statsTbl2 = h.GetTableStats(tableInfo2) c.Assert(statsTbl2.Count, Equals, int64(1)) @@ -295,13 +295,13 @@ func (s *testStatsSuite) TestVersion(c *C) { testKit.MustExec("alter table t2 add column c3 int") testKit.MustExec("analyze table t2") // load it with old schema. - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl2 = h.GetTableStats(tableInfo2) c.Assert(statsTbl2.Pseudo, IsFalse) c.Assert(statsTbl2.Columns[int64(3)], IsNil) // Next time DDL updated. is = do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl2 = h.GetTableStats(tableInfo2) c.Assert(statsTbl2.Pseudo, IsFalse) // We can read it without analyze again! Thanks for PrevLastVersion. @@ -330,7 +330,7 @@ func (s *testStatsSuite) TestLoadHist(c *C) { for i := 0; i < rowCount; i++ { testKit.MustExec("insert into t values('bb','sdfga')") } - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) h.Update(do.InfoSchema()) newStatsTbl := h.GetTableStats(tableInfo) // The stats table is updated. @@ -356,7 +356,7 @@ func (s *testStatsSuite) TestLoadHist(c *C) { tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tableInfo = tbl.Meta() - h.Update(is) + c.Assert(h.Update(is), IsNil) newStatsTbl2 := h.GetTableStats(tableInfo) c.Assert(newStatsTbl2 == newStatsTbl, IsFalse) // The histograms is not updated. @@ -431,13 +431,13 @@ func (s *testStatsSuite) TestLoadStats(c *C) { c.Assert(hg.Len(), Greater, 0) } -func newStoreWithBootstrap(statsLease time.Duration) (kv.Storage, *domain.Domain, error) { +func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) { store, err := mockstore.NewMockTikvStore() if err != nil { return nil, nil, errors.Trace(err) } session.SetSchemaLease(0) - session.SetStatsLease(statsLease) + session.DisableStats4Test() domain.RunAutoAnalyze = false do, err := session.BootstrapSession(store) do.SetStatsUpdating(true) diff --git a/statistics/handle/update_test.go b/statistics/handle/update_test.go index c4fcc16387837..b15b8f47a5788 100644 --- a/statistics/handle/update_test.go +++ b/statistics/handle/update_test.go @@ -52,7 +52,7 @@ func (s *testStatsSuite) SetUpSuite(c *C) { // Add the hook here to avoid data race. s.registerHook() var err error - s.store, s.do, err = newStoreWithBootstrap(0) + s.store, s.do, err = newStoreWithBootstrap() c.Assert(err, IsNil) } @@ -95,8 +95,8 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) { h.HandleDDLEvent(<-h.DDLEventCh()) h.HandleDDLEvent(<-h.DDLEventCh()) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 := h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1)) @@ -111,8 +111,8 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) { for i := 0; i < rowCount1; i++ { testKit.MustExec("insert into t1 values(1, 2)") } - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1*2)) @@ -126,8 +126,8 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) { testKit.MustExec("insert into t1 values(1, 2)") } testKit.MustExec("commit") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1*3)) @@ -142,8 +142,8 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) { testKit.MustExec("update t2 set c2 = c1") } testKit.MustExec("commit") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1*3)) stats2 = h.GetTableStats(tableInfo2) @@ -152,8 +152,8 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) { testKit.MustExec("begin") testKit.MustExec("delete from t1") testKit.MustExec("commit") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(0)) @@ -174,19 +174,19 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) { testKit.MustExec("insert into t1 values (1,2)") } h.DumpStatsDeltaToKV(handle.DumpDelta) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1)) // not dumped testKit.MustExec("insert into t1 values (1,2)") h.DumpStatsDeltaToKV(handle.DumpDelta) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1)) h.FlushStats() - h.Update(is) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1+1)) } @@ -206,8 +206,8 @@ func (s *testStatsSuite) TestRollback(c *C) { tableInfo := tbl.Meta() h := s.do.StatsHandle() h.HandleDDLEvent(<-h.DDLEventCh()) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats := h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(0)) @@ -241,8 +241,8 @@ func (s *testStatsSuite) TestMultiSession(c *C) { h.HandleDDLEvent(<-h.DDLEventCh()) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 := h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1)) @@ -261,8 +261,8 @@ func (s *testStatsSuite) TestMultiSession(c *C) { testKit.Se.Close() testKit2.Se.Close() - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1*2)) // The session in testKit is already Closed, set it to nil will create a new session. @@ -290,29 +290,29 @@ func (s *testStatsSuite) TestTxnWithFailure(c *C) { for i := 0; i < rowCount1; i++ { testKit.MustExec("insert into t1 values(?, 2)", i) } - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 := h.GetTableStats(tableInfo1) // have not commit c.Assert(stats1.Count, Equals, int64(0)) testKit.MustExec("commit") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1)) _, err = testKit.Exec("insert into t1 values(0, 2)") c.Assert(err, NotNil) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1)) testKit.MustExec("insert into t1 values(-1, 2)") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) stats1 = h.GetTableStats(tableInfo1) c.Assert(stats1.Count, Equals, int64(rowCount1+1)) } @@ -388,16 +388,16 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) { h := do.StatsHandle() h.HandleDDLEvent(<-h.DDLEventCh()) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats := h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(0)) _, err = testKit.Exec("insert into t values ('ss')") c.Assert(err, IsNil) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) h.HandleAutoAnalyze(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats = h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(1)) c.Assert(stats.ModifyCount, Equals, int64(0)) @@ -415,7 +415,7 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) { c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(is), IsNil) h.HandleAutoAnalyze(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats = h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(2)) c.Assert(stats.ModifyCount, Equals, int64(1)) @@ -425,17 +425,17 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) { c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(is), IsNil) h.HandleAutoAnalyze(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats = h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(3)) c.Assert(stats.ModifyCount, Equals, int64(0)) _, err = testKit.Exec("insert into t values ('eee')") c.Assert(err, IsNil) - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) h.HandleAutoAnalyze(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats = h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(4)) // Modify count is non-zero means that we do not analyze the table. @@ -454,7 +454,7 @@ func (s *testStatsSuite) TestAutoUpdate(c *C) { c.Assert(err, IsNil) tableInfo = tbl.Meta() h.HandleAutoAnalyze(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) stats = h.GetTableStats(tableInfo) c.Assert(stats.Count, Equals, int64(4)) c.Assert(stats.ModifyCount, Equals, int64(0)) @@ -487,13 +487,13 @@ func (s *testStatsSuite) TestAutoUpdatePartition(c *C) { pi := tableInfo.GetPartitionInfo() h := do.StatsHandle() - h.Update(is) + c.Assert(h.Update(is), IsNil) stats := h.GetPartitionStats(tableInfo, pi.Definitions[0].ID) c.Assert(stats.Count, Equals, int64(0)) testKit.MustExec("insert into t values (1)") - h.DumpStatsDeltaToKV(handle.DumpAll) - h.Update(is) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) + c.Assert(h.Update(is), IsNil) h.HandleAutoAnalyze(is) stats = h.GetPartitionStats(tableInfo, pi.Definitions[0].ID) c.Assert(stats.Count, Equals, int64(1)) @@ -513,12 +513,12 @@ func (s *testStatsSuite) TestTableAnalyzed(c *C) { tableInfo := tbl.Meta() h := s.do.StatsHandle() - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl := h.GetTableStats(tableInfo) c.Assert(handle.TableAnalyzed(statsTbl), IsFalse) testKit.MustExec("analyze table t") - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl = h.GetTableStats(tableInfo) c.Assert(handle.TableAnalyzed(statsTbl), IsTrue) @@ -529,7 +529,7 @@ func (s *testStatsSuite) TestTableAnalyzed(c *C) { defer func() { h.SetLease(oriLease) }() - h.Update(is) + c.Assert(h.Update(is), IsNil) statsTbl = h.GetTableStats(tableInfo) c.Assert(handle.TableAnalyzed(statsTbl), IsTrue) } @@ -539,7 +539,7 @@ func (s *testStatsSuite) TestUpdateErrorRate(c *C) { h := s.do.StatsHandle() is := s.do.InfoSchema() h.SetLease(0) - h.Update(is) + c.Assert(h.Update(is), IsNil) oriProbability := statistics.FeedbackProbability defer func() { @@ -563,7 +563,7 @@ func (s *testStatsSuite) TestUpdateErrorRate(c *C) { testKit.MustExec("insert into t values (12, 3)") c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) is = s.do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) @@ -580,7 +580,7 @@ func (s *testStatsSuite) TestUpdateErrorRate(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(is), IsNil) h.UpdateErrorRate(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl = h.GetTableStats(tblInfo) // The error rate of this column is not larger than MaxErrorRate now. @@ -592,14 +592,14 @@ func (s *testStatsSuite) TestUpdateErrorRate(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(is), IsNil) h.UpdateErrorRate(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl = h.GetTableStats(tblInfo) c.Assert(tbl.Indices[bID].NotAccurate(), IsFalse) c.Assert(tbl.Indices[bID].QueryTotal, Equals, int64(1)) testKit.MustExec("analyze table t") c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl = h.GetTableStats(tblInfo) c.Assert(tbl.Indices[bID].QueryTotal, Equals, int64(0)) } @@ -609,7 +609,7 @@ func (s *testStatsSuite) TestUpdatePartitionErrorRate(c *C) { h := s.do.StatsHandle() is := s.do.InfoSchema() h.SetLease(0) - h.Update(is) + c.Assert(h.Update(is), IsNil) oriProbability := statistics.FeedbackProbability defer func() { @@ -634,7 +634,7 @@ func (s *testStatsSuite) TestUpdatePartitionErrorRate(c *C) { testKit.MustExec("insert into t values (12)") c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) is = s.do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) @@ -651,7 +651,7 @@ func (s *testStatsSuite) TestUpdatePartitionErrorRate(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(is), IsNil) h.UpdateErrorRate(is) - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl = h.GetPartitionStats(tblInfo, pid) // The error rate of this column is not larger than MaxErrorRate now. @@ -773,7 +773,7 @@ func (s *testStatsSuite) TestQueryFeedback(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(s.do.InfoSchema()), IsNil) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) tblInfo := table.Meta() tbl := h.GetTableStats(tblInfo) if t.idxCols == 0 { @@ -785,7 +785,7 @@ func (s *testStatsSuite) TestQueryFeedback(c *C) { // Feedback from limit executor may not be accurate. testKit.MustQuery("select * from t where t.a <= 5 limit 1") - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) feedback := h.GetQueryFeedback() c.Assert(len(feedback), Equals, 0) @@ -793,7 +793,7 @@ func (s *testStatsSuite) TestQueryFeedback(c *C) { statistics.MaxNumberOfRanges = 0 for _, t := range tests { testKit.MustQuery(t.sql) - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) feedback := h.GetQueryFeedback() c.Assert(len(feedback), Equals, 0) } @@ -803,7 +803,7 @@ func (s *testStatsSuite) TestQueryFeedback(c *C) { statistics.MaxNumberOfRanges = oriNumber for _, t := range tests { testKit.MustQuery(t.sql) - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) feedback := h.GetQueryFeedback() c.Assert(len(feedback), Equals, 0) } @@ -896,7 +896,7 @@ func (s *testStatsSuite) TestQueryFeedbackForPartition(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(s.do.InfoSchema()), IsNil) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl := h.GetPartitionStats(tblInfo, pid) if t.idxCols == 0 { c.Assert(tbl.Columns[tblInfo.Columns[0].ID].ToString(0), Equals, tests[i].hist) @@ -1282,7 +1282,7 @@ func (s *testStatsSuite) TestIndexQueryFeedback(c *C) { } c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) is := s.do.InfoSchema() - h.Update(is) + c.Assert(h.Update(is), IsNil) table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) tblInfo := table.Meta() @@ -1448,7 +1448,7 @@ func (s *testStatsSuite) TestAbnormalIndexFeedback(c *C) { c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(s.do.InfoSchema()), IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) tbl := h.GetTableStats(tblInfo) c.Assert(tbl.Columns[t.rangeID].ToString(0), Equals, tests[i].hist) val, err := codec.EncodeKey(testKit.Se.GetSessionVars().StmtCtx, nil, types.NewIntDatum(1)) @@ -1519,7 +1519,7 @@ func (s *testStatsSuite) TestFeedbackRanges(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(s.do.InfoSchema()), IsNil) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) tblInfo := table.Meta() tbl := h.GetTableStats(tblInfo) c.Assert(tbl.Columns[t.colID].ToString(0), Equals, tests[i].hist) @@ -1601,7 +1601,7 @@ func (s *testStatsSuite) TestUnsignedFeedbackRanges(c *C) { c.Assert(h.DumpStatsFeedbackToKV(), IsNil) c.Assert(h.HandleUpdateStats(s.do.InfoSchema()), IsNil) c.Assert(err, IsNil) - h.Update(is) + c.Assert(h.Update(is), IsNil) tblInfo := table.Meta() tbl := h.GetTableStats(tblInfo) c.Assert(tbl.Columns[1].ToString(0), Equals, tests[i].hist) diff --git a/statistics/sample_test.go b/statistics/sample_test.go index dfc7b59df597b..cf07ec799a957 100644 --- a/statistics/sample_test.go +++ b/statistics/sample_test.go @@ -66,7 +66,7 @@ func (s *testSampleSuite) TestCollectColumnStats(c *C) { CMSketchWidth: 2048, CMSketchDepth: 8, } - s.rs.Close() + c.Assert(s.rs.Close(), IsNil) collectors, pkBuilder, err := builder.CollectColumnStats() c.Assert(err, IsNil) c.Assert(collectors[0].NullCount+collectors[0].Count, Equals, int64(s.count)) @@ -87,7 +87,7 @@ func (s *testSampleSuite) TestMergeSampleCollector(c *C) { CMSketchWidth: 2048, CMSketchDepth: 8, } - s.rs.Close() + c.Assert(s.rs.Close(), IsNil) sc := &stmtctx.StatementContext{TimeZone: time.Local} collectors, pkBuilder, err := builder.CollectColumnStats() c.Assert(err, IsNil) @@ -113,7 +113,7 @@ func (s *testSampleSuite) TestCollectorProtoConversion(c *C) { CMSketchWidth: 2048, CMSketchDepth: 8, } - s.rs.Close() + c.Assert(s.rs.Close(), IsNil) collectors, pkBuilder, err := builder.CollectColumnStats() c.Assert(err, IsNil) c.Assert(pkBuilder, IsNil) diff --git a/statistics/selectivity_test.go b/statistics/selectivity_test.go index ad0918a85ba8c..a6912a41b02f3 100644 --- a/statistics/selectivity_test.go +++ b/statistics/selectivity_test.go @@ -60,13 +60,13 @@ func (s *testStatsSuite) SetUpSuite(c *C) { // Add the hook here to avoid data race. s.registerHook() var err error - s.store, s.do, err = newStoreWithBootstrap(0) + s.store, s.do, err = newStoreWithBootstrap() c.Assert(err, IsNil) } func (s *testStatsSuite) TearDownSuite(c *C) { s.do.Close() - s.store.Close() + c.Assert(s.store.Close(), IsNil) testleak.AfterTest(c)() } @@ -115,13 +115,13 @@ func (h *logHook) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.Chec return ce } -func newStoreWithBootstrap(statsLease time.Duration) (kv.Storage, *domain.Domain, error) { +func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) { store, err := mockstore.NewMockTikvStore() if err != nil { return nil, nil, errors.Trace(err) } session.SetSchemaLease(0) - session.SetStatsLease(statsLease) + session.DisableStats4Test() domain.RunAutoAnalyze = false do, err := session.BootstrapSession(store) do.SetStatsUpdating(true) @@ -209,7 +209,8 @@ func (s *testStatsSuite) prepareSelectivity(testKit *testkit.TestKit, c *C) *sta statsTbl := mockStatsTable(tbl, 540) // Set the value of columns' histogram. - colValues, _ := s.generateIntDatum(1, 54) + colValues, err := s.generateIntDatum(1, 54) + c.Assert(err, IsNil) for i := 1; i <= 5; i++ { statsTbl.Columns[int64(i)] = &statistics.Column{Histogram: *mockStatsHistogram(int64(i), colValues, 10, types.NewFieldType(mysql.TypeLonglong)), Info: tbl.Columns[i-1]} } @@ -355,12 +356,12 @@ func (s *testStatsSuite) TestEstimationForUnknownValues(c *C) { testKit.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i, i)) } h := s.do.StatsHandle() - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) testKit.MustExec("analyze table t") for i := 0; i < 10; i++ { testKit.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i+10, i+10)) } - h.DumpStatsDeltaToKV(handle.DumpAll) + c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(s.do.InfoSchema()), IsNil) table, err := s.do.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) @@ -459,7 +460,8 @@ func BenchmarkSelectivity(b *testing.B) { p, err := plannercore.BuildLogicalPlan(ctx, stmts[0], is) c.Assert(err, IsNil, Commentf("error %v, for building plan, expr %s", err, exprs)) - file, _ := os.Create("cpu.profile") + file, err := os.Create("cpu.profile") + c.Assert(err, IsNil) defer file.Close() pprof.StartCPUProfile(file) diff --git a/statistics/statistics_test.go b/statistics/statistics_test.go index 0386804f3774e..009ae8064da92 100644 --- a/statistics/statistics_test.go +++ b/statistics/statistics_test.go @@ -238,7 +238,8 @@ func (s *testStatisticsSuite) TestBuild(c *C) { bucketCount := int64(256) ctx := mock.NewContext() sc := ctx.GetSessionVars().StmtCtx - sketch, _, _ := buildFMSketch(sc, s.rc.(*recordSet).data, 1000) + sketch, _, err := buildFMSketch(sc, s.rc.(*recordSet).data, 1000) + c.Assert(err, IsNil) collector := &SampleCollector{ Count: int64(s.count), @@ -277,7 +278,7 @@ func (s *testStatisticsSuite) TestBuild(c *C) { MaxSampleSize: 1000, MaxFMSketchSize: 1000, } - s.pk.Close() + c.Assert(s.pk.Close(), IsNil) collectors, _, err := builder.CollectColumnStats() c.Assert(err, IsNil) c.Assert(len(collectors), Equals, 1) @@ -336,7 +337,7 @@ func (s *testStatisticsSuite) TestBuild(c *C) { func (s *testStatisticsSuite) TestHistogramProtoConversion(c *C) { ctx := mock.NewContext() - s.rc.Close() + c.Assert(s.rc.Close(), IsNil) tblCount, col, _, err := buildIndex(ctx, 256, 1, sqlexec.RecordSet(s.rc)) c.Check(err, IsNil) c.Check(int(tblCount), Equals, 100000) @@ -441,7 +442,8 @@ func (s *testStatisticsSuite) TestColumnRange(c *C) { bucketCount := int64(256) ctx := mock.NewContext() sc := ctx.GetSessionVars().StmtCtx - sketch, _, _ := buildFMSketch(sc, s.rc.(*recordSet).data, 1000) + sketch, _, err := buildFMSketch(sc, s.rc.(*recordSet).data, 1000) + c.Assert(err, IsNil) collector := &SampleCollector{ Count: int64(s.count), diff --git a/types/const_test.go b/types/const_test.go index 3f6573f733785..b9a2c64fb37c8 100644 --- a/types/const_test.go +++ b/types/const_test.go @@ -56,7 +56,7 @@ func (s *testMySQLConstSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() } var err error s.dom, err = session.BootstrapSession(s.store) diff --git a/util/admin/admin_integration_test.go b/util/admin/admin_integration_test.go index e2ec3ba6e659c..c6a226e01f4da 100644 --- a/util/admin/admin_integration_test.go +++ b/util/admin/admin_integration_test.go @@ -43,7 +43,7 @@ func (s *testAdminSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) s.store = store session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() d, err := session.BootstrapSession(s.store) c.Assert(err, IsNil) d.SetStatsUpdating(true) diff --git a/util/kvencoder/kv_encoder_test.go b/util/kvencoder/kv_encoder_test.go index aae6797c90952..1aa044dc28eea 100644 --- a/util/kvencoder/kv_encoder_test.go +++ b/util/kvencoder/kv_encoder_test.go @@ -49,7 +49,7 @@ func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) { return nil, nil, errors.Trace(err) } session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() dom, err := session.BootstrapSession(store) return store, dom, errors.Trace(err) } diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index 27153d60dfc83..47a05cb9efb94 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -59,7 +59,7 @@ func newDomainStoreWithBootstrap(c *C) (*domain.Domain, kv.Storage, error) { ) c.Assert(err, IsNil) session.SetSchemaLease(0) - session.SetStatsLease(0) + session.DisableStats4Test() if err != nil { return nil, nil, errors.Trace(err) }