Skip to content

Commit

Permalink
statistics/handle: fix some unstable test cases (#31371)
Browse files Browse the repository at this point in the history
close #30822
  • Loading branch information
tiancaiamao authored Jan 13, 2022
1 parent aabd4e0 commit c6d7ba3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion statistics/handle/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func (s *testStatsSuite) TestInitStats(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 1")
testKit.MustExec("create table t(a int, b int, c int, primary key(a), key idx(b))")
testKit.MustExec("insert into t values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,7,8)")
testKit.MustExec("analyze table t")
Expand Down Expand Up @@ -798,6 +799,7 @@ func (s *testStatsSuite) TestShowGlobalStats(c *C) {
defer cleanEnv(c, s.store, s.do)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_analyze_version = 0")
tk.MustExec("drop table if exists t")
tk.MustExec("set @@tidb_partition_prune_mode = 'static'")
tk.MustExec("create table t (a int, key(a)) partition by hash(a) partitions 2")
Expand Down Expand Up @@ -945,7 +947,7 @@ func (s *testSerialStatsSuite) checkForGlobalStatsWithOpts(c *C, tk *testkit.Tes
}
}

func (s *testSerialStatsSuite) TestAnalyzeGlobalStatsWithOpts(c *C) {
func (s *testSerialStatsSuite) TestAnalyzeGlobalStatsWithOpts1(c *C) {
if israce.RaceEnabled {
c.Skip("exhaustive types test, skip race test")
}
Expand Down Expand Up @@ -2502,6 +2504,7 @@ func (s *testStatsSuite) TestIndexFMSketch(c *C) {
defer cleanEnv(c, s.store, s.do)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_analyze_version = 1")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, c int, index ia(a), index ibc(b, c)) partition by hash(a) partitions 3")
tk.MustExec("insert into t values (1, 1, 1)")
Expand Down Expand Up @@ -2932,6 +2935,7 @@ func (s *testSerialStatsSuite) TestFastAnalyzeColumnHistWithNullValue(c *C) {
testKit.MustExec("drop table if exists t")
testKit.MustExec("create table t (a int)")
testKit.MustExec("insert into t values (1), (2), (3), (4), (NULL)")
testKit.MustExec("set @@session.tidb_analyze_version = 1")
testKit.MustExec("set @@tidb_enable_fast_analyze=1")
defer testKit.MustExec("set @@tidb_enable_fast_analyze=0")
testKit.MustExec("analyze table t with 0 topn, 2 buckets")
Expand Down
11 changes: 10 additions & 1 deletion statistics/handle/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (s *testStatsSuite) TestSingleSessionInsert(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 1")
testKit.MustExec("create table t1 (c1 int, c2 int)")
testKit.MustExec("create table t2 (c1 int, c2 int)")

Expand Down Expand Up @@ -776,6 +777,7 @@ func (s *testStatsSuite) TestUpdateErrorRate(c *C) {

testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec("create table t (a bigint(64), b bigint(64), primary key(a), index idx(b))")
err := h.HandleDDLEvent(<-h.DDLEventCh())
c.Assert(err, IsNil)
Expand Down Expand Up @@ -956,6 +958,7 @@ func (s *testStatsSuite) TestQueryFeedback(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec("create table t (a bigint(64), b bigint(64), primary key(a), index idx(b))")
testKit.MustExec("insert into t values (1,2),(2,2),(4,5)")
testKit.MustExec("analyze table t with 0 topn")
Expand Down Expand Up @@ -1074,6 +1077,7 @@ func (s *testStatsSuite) TestQueryFeedbackForPartition(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`)
testKit.MustExec(`create table t (a bigint(64), b bigint(64), primary key(a), index idx(b))
partition by range (a) (
Expand Down Expand Up @@ -1208,6 +1212,7 @@ func (s *testStatsSuite) TestUpdateStatsByLocalFeedback(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`)
testKit.MustExec("create table t (a bigint(64), b bigint(64), primary key(a), index idx(b))")
testKit.MustExec("insert into t values (1,2),(2,2),(4,5)")
Expand Down Expand Up @@ -1268,6 +1273,7 @@ func (s *testStatsSuite) TestUpdatePartitionStatsByLocalFeedback(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`)
testKit.MustExec("create table t (a bigint(64), b bigint(64), primary key(a)) partition by range (a) (partition p0 values less than (6))")
testKit.MustExec("insert into t values (1,2),(2,2),(4,5)")
Expand All @@ -1290,7 +1296,7 @@ func (s *testStatsSuite) TestUpdatePartitionStatsByLocalFeedback(c *C) {
table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
c.Assert(err, IsNil)

testKit.MustQuery("select * from t where a > 1")
testKit.MustQuery("select * from t where a > 1").Check(testkit.Rows("2 2", "3 5", "4 5"))

h.UpdateStatsByLocalFeedback(s.do.InfoSchema())

Expand Down Expand Up @@ -1744,6 +1750,7 @@ func (s *testStatsSuite) TestIndexQueryFeedback4TopN(c *C) {
handle.MinLogErrorRate.Store(0)

testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec("create table t (a bigint(64), index idx(a))")
for i := 0; i < 20; i++ {
testKit.MustExec(`insert into t values (1)`)
Expand All @@ -1752,6 +1759,7 @@ func (s *testStatsSuite) TestIndexQueryFeedback4TopN(c *C) {
err := h.HandleDDLEvent(<-h.DDLEventCh())
c.Assert(err, IsNil)
c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil)
testKit.MustExec("set @@session.tidb_analyze_version = 1")
testKit.MustExec("set @@tidb_enable_fast_analyze = 1")
testKit.MustExec("analyze table t with 3 buckets")
for i := 0; i < 20; i++ {
Expand Down Expand Up @@ -1946,6 +1954,7 @@ func (s *testStatsSuite) TestUnsignedFeedbackRanges(c *C) {
handle.MinLogErrorRate.Store(0)

testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_analyze_version = 0")
testKit.MustExec("create table t (a tinyint unsigned, primary key(a))")
testKit.MustExec("create table t1 (a bigint unsigned, primary key(a))")
for i := 0; i < 20; i++ {
Expand Down

0 comments on commit c6d7ba3

Please sign in to comment.