Skip to content

Commit

Permalink
test: add TestAnalyzeTableWithTiDBPersistAnalyzeOptionsEnabled
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Jun 26, 2024
1 parent 00c5685 commit b11f780
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 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,47 @@ 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"))
// Set tidb_analyze_column_options to PREDICATE.
tk.MustExec("set global tidb_analyze_column_options='PREDICATE'")
// 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 b11f780

Please sign in to comment.