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

test: fix unstable test TestAnalyzeGlobalStatsWithOpts2 #26921

Merged
Changes from all 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
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