Skip to content

Commit

Permalink
fix unstable test
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelice committed Aug 5, 2021
1 parent 019fab3 commit 15db71e
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions statistics/handle/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,11 @@ func (s *testStatsSuite) prepareForGlobalStatsWithOpts(c *C, tk *testkit.TestKit
}

// nolint:unused
func (s *testStatsSuite) checkForGlobalStatsWithOpts(c *C, tk *testkit.TestKit, p string, topn, buckets int) {
func (s *testStatsSuite) checkForGlobalStatsWithOpts(c *C, tk *testkit.TestKit, t string, p string, topn, buckets int) {
delta := buckets/2 + 1
for _, isIdx := range []int{0, 1} {
c.Assert(len(tk.MustQuery(fmt.Sprintf("show stats_topn where partition_name='%v' and is_index=%v", p, isIdx)).Rows()), Equals, topn)
numBuckets := len(tk.MustQuery(fmt.Sprintf("show stats_buckets where partition_name='%v' and is_index=%v", p, isIdx)).Rows())
c.Assert(len(tk.MustQuery(fmt.Sprintf("show stats_topn where table_name='%v' and partition_name='%v' and is_index=%v", t, p, isIdx)).Rows()), Equals, topn)
numBuckets := len(tk.MustQuery(fmt.Sprintf("show stats_buckets where table_name='%v' and partition_name='%v' and is_index=%v", t, p, isIdx)).Rows())
// since the hist-building algorithm doesn't stipulate the final bucket number to be equal to the expected number exactly,
// we have to check the results by a range here.
c.Assert(numBuckets >= buckets-delta, IsTrue)
Expand Down Expand Up @@ -942,9 +942,9 @@ func (s *testStatsSuite) TestAnalyzeGlobalStatsWithOpts(c *C) {
sql := fmt.Sprintf("analyze table test_gstats_opt with %v topn, %v buckets", ca.topn, ca.buckets)
if !ca.err {
tk.MustExec(sql)
s.checkForGlobalStatsWithOpts(c, tk, "global", ca.topn, ca.buckets)
s.checkForGlobalStatsWithOpts(c, tk, "p0", ca.topn, ca.buckets)
s.checkForGlobalStatsWithOpts(c, tk, "p1", ca.topn, ca.buckets)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt", "global", ca.topn, ca.buckets)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt", "p0", ca.topn, ca.buckets)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt", "p1", ca.topn, ca.buckets)
} else {
err := tk.ExecToErr(sql)
c.Assert(err, NotNil)
Expand All @@ -961,25 +961,25 @@ func (s *testStatsSuite) TestAnalyzeGlobalStatsWithOpts2(c *C) {
s.prepareForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "test_gstats_opt2")

tk.MustExec("analyze table test_gstats_opt2 with 20 topn, 50 buckets, 1000 samples")
s.checkForGlobalStatsWithOpts(c, tk, "global", 2, 50)
s.checkForGlobalStatsWithOpts(c, tk, "p0", 1, 50)
s.checkForGlobalStatsWithOpts(c, tk, "p1", 1, 50)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "global", 2, 50)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p0", 1, 50)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p1", 1, 50)

// analyze a partition to let its options be different with others'
tk.MustExec("analyze table test_gstats_opt2 partition p0 with 10 topn, 20 buckets")
s.checkForGlobalStatsWithOpts(c, tk, "global", 10, 20) // use new options
s.checkForGlobalStatsWithOpts(c, tk, "p0", 10, 20)
s.checkForGlobalStatsWithOpts(c, tk, "p1", 1, 50)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "global", 10, 20) // use new options
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p0", 10, 20)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p1", 1, 50)

tk.MustExec("analyze table test_gstats_opt2 partition p1 with 100 topn, 200 buckets")
s.checkForGlobalStatsWithOpts(c, tk, "global", 100, 200)
s.checkForGlobalStatsWithOpts(c, tk, "p0", 10, 20)
s.checkForGlobalStatsWithOpts(c, tk, "p1", 100, 200)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "global", 100, 200)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p0", 10, 20)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p1", 100, 200)

tk.MustExec("analyze table test_gstats_opt2 partition p0 with 20 topn") // change back to 20 topn
s.checkForGlobalStatsWithOpts(c, tk, "global", 20, 256)
s.checkForGlobalStatsWithOpts(c, tk, "p0", 20, 256)
s.checkForGlobalStatsWithOpts(c, tk, "p1", 100, 200)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "global", 20, 256)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p0", 20, 256)
s.checkForGlobalStatsWithOpts(c, tk, "test_gstats_opt2", "p1", 100, 200)
}

func (s *testStatsSuite) TestGlobalStatsHealthy(c *C) {
Expand Down

0 comments on commit 15db71e

Please sign in to comment.