Skip to content

Commit

Permalink
statistics: add more test for tidb_merge_partition_stats_concurrency (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 6, 2023
1 parent 456628e commit 51c38df
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 404 deletions.
76 changes: 0 additions & 76 deletions pkg/executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,82 +1409,6 @@ func TestBatchGetforRangeandListPartitionTable(t *testing.T) {
tk.MustQuery(queryRange).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows())
}

func TestGlobalStatsAndSQLBinding(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create database test_global_stats")
tk.MustExec("use test_global_stats")
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'")
tk.MustExec("set tidb_cost_model_version=2")

// hash and range and list partition
tk.MustExec("create table thash(a int, b int, key(a)) partition by hash(a) partitions 4")
tk.MustExec(`create table trange(a int, b int, key(a)) partition by range(a) (
partition p0 values less than (200),
partition p1 values less than (400),
partition p2 values less than (600),
partition p3 values less than (800),
partition p4 values less than (1001))`)
tk.MustExec(`create table tlist (a int, b int, key(a)) partition by list (a) (
partition p0 values in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
partition p1 values in (10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
partition p2 values in (20, 21, 22, 23, 24, 25, 26, 27, 28, 29),
partition p3 values in (30, 31, 32, 33, 34, 35, 36, 37, 38, 39),
partition p4 values in (40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50))`)

// construct some special data distribution
vals := make([]string, 0, 1000)
listVals := make([]string, 0, 1000)
for i := 0; i < 1000; i++ {
if i < 10 {
// for hash and range partition, 1% of records are in [0, 100)
vals = append(vals, fmt.Sprintf("(%v, %v)", rand.Intn(100), rand.Intn(100)))
// for list partition, 1% of records are equal to 0
listVals = append(listVals, "(0, 0)")
} else {
vals = append(vals, fmt.Sprintf("(%v, %v)", 100+rand.Intn(900), 100+rand.Intn(900)))
listVals = append(listVals, fmt.Sprintf("(%v, %v)", 1+rand.Intn(50), 1+rand.Intn(50)))
}
}
tk.MustExec("insert into thash values " + strings.Join(vals, ","))
tk.MustExec("insert into trange values " + strings.Join(vals, ","))
tk.MustExec("insert into tlist values " + strings.Join(listVals, ","))

// before analyzing, the planner will choose TableScan to access the 1% of records
tk.MustHavePlan("select * from thash where a<100", "TableFullScan")
tk.MustHavePlan("select * from trange where a<100", "TableFullScan")
tk.MustHavePlan("select * from tlist where a<1", "TableFullScan")

tk.MustExec("analyze table thash")
tk.MustExec("analyze table trange")
tk.MustExec("analyze table tlist")

tk.MustHavePlan("select * from thash where a<100", "TableFullScan")
tk.MustHavePlan("select * from trange where a<100", "TableFullScan")
tk.MustHavePlan("select * from tlist where a<1", "TableFullScan")

// create SQL bindings
tk.MustExec("create session binding for select * from thash where a<100 using select * from thash ignore index(a) where a<100")
tk.MustExec("create session binding for select * from trange where a<100 using select * from trange ignore index(a) where a<100")
tk.MustExec("create session binding for select * from tlist where a<100 using select * from tlist ignore index(a) where a<100")

// use TableScan again since the Index(a) is ignored
tk.MustHavePlan("select * from thash where a<100", "TableFullScan")
tk.MustHavePlan("select * from trange where a<100", "TableFullScan")
tk.MustHavePlan("select * from tlist where a<1", "TableFullScan")

// drop SQL bindings
tk.MustExec("drop session binding for select * from thash where a<100")
tk.MustExec("drop session binding for select * from trange where a<100")
tk.MustExec("drop session binding for select * from tlist where a<100")

tk.MustHavePlan("select * from thash where a<100", "TableFullScan")
tk.MustHavePlan("select * from trange where a<100", "TableFullScan")
tk.MustHavePlan("select * from tlist where a<1", "TableFullScan")
}

func TestPartitionTableWithDifferentJoin(t *testing.T) {
failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune", `return(true)`)
defer failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune")
Expand Down
4 changes: 3 additions & 1 deletion pkg/statistics/handle/globalstats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ go_test(
name = "globalstats_test",
timeout = "short",
srcs = [
"globalstats_internal_test.go",
"globalstats_test.go",
"main_test.go",
"topn_bench_test.go",
"topn_test.go",
],
embed = [":globalstats"],
flaky = True,
shard_count = 23,
shard_count = 26,
deps = [
"//pkg/config",
"//pkg/domain",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/sessionctx/stmtctx",
Expand Down
Loading

0 comments on commit 51c38df

Please sign in to comment.