Skip to content

Commit

Permalink
test: add TestAnalyzeTableWithTiDBPersistAnalyzeOptionsEnabled
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Jun 26, 2024
1 parent 00c5685 commit d4b15f6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/statistics/handle/usage/predicate_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,46 @@ func TestAnalyzeTableWithPredicateColumns(t *testing.T) {
testkit.Rows("t analyze table all columns with 256 buckets, 100 topn, 1 samplerate"),
)
}

func TestAnalyzeTableWithTiDBPersistAnalyzeOptionsEnabled(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)

// Check tidb_persist_analyze_options first.
tk.MustQuery("select @@tidb_persist_analyze_options").Check(testkit.Rows("1"))

// Create table and select data with predicate.
tk.MustExec("use test")
tk.MustExec("create table t (a int, b int, c int)")
tk.MustExec("insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3)")
tk.MustQuery("select * from t where a > 1").Check(testkit.Rows("2 2 2", "3 3 3"))

// Dump the statistics usage.
h := dom.StatsHandle()
err := h.DumpColStatsUsageToKV()
require.NoError(t, err)

// Analyze table with specified columns.
tk.MustExec("analyze table t columns a, b")
tk.MustQuery("select table_name, job_info from mysql.analyze_jobs order by id desc limit 1").Check(
testkit.Rows("t analyze table columns a, b with 256 buckets, 100 topn, 1 samplerate"),
)

// Analyze again, it should use the same options.
tk.MustExec("analyze table t")
tk.MustQuery("select table_name, job_info from mysql.analyze_jobs order by id desc limit 1").Check(
testkit.Rows("t analyze table columns a, b with 256 buckets, 100 topn, 1 samplerate"),
)

// Analyze table with ALL syntax.
tk.MustExec("analyze table t all columns")
tk.MustQuery("select table_name, job_info from mysql.analyze_jobs order by id desc limit 1").Check(
testkit.Rows("t analyze table all columns with 256 buckets, 100 topn, 1 samplerate"),
)

// Analyze again, it should use the same options.
tk.MustExec("analyze table t")
tk.MustQuery("select table_name, job_info from mysql.analyze_jobs order by id desc limit 1").Check(
testkit.Rows("t analyze table all columns with 256 buckets, 100 topn, 1 samplerate"),
)
}

0 comments on commit d4b15f6

Please sign in to comment.