Skip to content

Commit

Permalink
planner: update some UTs from cost model1 to model2 (#39138)
Browse files Browse the repository at this point in the history
ref #35240
  • Loading branch information
qw4990 authored Nov 15, 2022
1 parent 3765abb commit b03690a
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 323 deletions.
1 change: 1 addition & 0 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ func TestIssue28782(t *testing.T) {
func TestIssue29101(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set tidb_cost_model_version=1")
tk.MustExec(`set tidb_enable_prepared_plan_cache=1`)
tk.MustExec(`use test`)
tk.MustExec("set @@tidb_enable_collect_execution_info=0;")
Expand Down
2 changes: 1 addition & 1 deletion executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func TestSetVar(t *testing.T) {
tk.MustQuery("select @@tidb_max_auto_analyze_time").Check(testkit.Rows("0"))

// test variables for cost model ver2
tk.MustQuery("select @@tidb_cost_model_version").Check(testkit.Rows("1"))
tk.MustQuery("select @@tidb_cost_model_version").Check(testkit.Rows(fmt.Sprintf("%v", variable.DefTiDBCostModelVer)))
tk.MustExec("set tidb_cost_model_version=3")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect tidb_cost_model_version value: '3'"))
tk.MustExec("set tidb_cost_model_version=0")
Expand Down
11 changes: 7 additions & 4 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,7 @@ func TestViewHint(t *testing.T) {
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop view if exists v, v1")
tk.MustExec("drop table if exists t, t1, t2")
tk.MustExec("create table t(a int, b int);")
Expand Down Expand Up @@ -1363,6 +1364,7 @@ func TestViewHintScope(t *testing.T) {
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop view if exists v, v1")
tk.MustExec("drop table if exists t, t1, t2")
tk.MustExec("create table t(a int, b int);")
Expand Down Expand Up @@ -2620,6 +2622,7 @@ func TestSelectLimit(t *testing.T) {
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
tk.MustExec("insert into t values(1),(1),(2)")
Expand All @@ -2644,9 +2647,9 @@ func TestSelectLimit(t *testing.T) {
result = tk.MustQuery("select (select * from t limit 1) s") // limit write in subquery, has no effect.
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select * from t where t.a in (select * from t) limit 3") // select_limit will not effect subquery
result.Check(testkit.Rows("1", "1", "2"))
result.Sort().Check(testkit.Rows("1", "1", "2"))
result = tk.MustQuery("select * from (select * from t) s limit 3") // select_limit will not effect subquery
result.Check(testkit.Rows("1", "1", "2"))
result.Sort().Check(testkit.Rows("1", "1", "2"))

// test for union
result = tk.MustQuery("select * from t union all select * from t limit 2") // limit outside subquery
Expand Down Expand Up @@ -2674,14 +2677,14 @@ func TestSelectLimit(t *testing.T) {
result.Check(testkit.Rows("1"))
tk.MustExec("set @@session.sql_select_limit=default")
result = tk.MustQuery("select * from s")
result.Check(testkit.Rows("1", "1", "2"))
result.Sort().Check(testkit.Rows("1", "1", "2"))

// test for DML
tk.MustExec("set @@session.sql_select_limit=1")
tk.MustExec("create table b (a int)")
tk.MustExec("insert into b select * from t") // all values are inserted
result = tk.MustQuery("select * from b limit 3")
result.Check(testkit.Rows("1", "1", "2"))
result.Sort().Check(testkit.Rows("1", "1", "2"))
tk.MustExec("update b set a = 2 where a = 1") // all values are updated
result = tk.MustQuery("select * from b limit 3")
result.Check(testkit.Rows("2", "2", "2"))
Expand Down
2 changes: 2 additions & 0 deletions planner/core/partition_pruner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func TestListColumnsPartitionPruner(t *testing.T) {

// tk1 use to test partition table with index.
tk1 := testkit.NewTestKit(t, store)
tk1.MustExec("set tidb_cost_model_version=2")
tk1.MustExec("drop database if exists test_partition_1;")
tk1.MustExec(`set @@session.tidb_regard_null_as_point=false`)
tk1.MustExec("create database test_partition_1")
Expand All @@ -357,6 +358,7 @@ func TestListColumnsPartitionPruner(t *testing.T) {

// tk2 use to compare the result with normal table.
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("set tidb_cost_model_version=2")
tk2.MustExec("drop database if exists test_partition_2;")
tk2.MustExec(`set @@session.tidb_regard_null_as_point=false`)
tk2.MustExec("create database test_partition_2")
Expand Down
4 changes: 2 additions & 2 deletions planner/core/physical_plan_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestPhysicalOptimizeWithTraceEnabled(t *testing.T) {
tk.MustExec("use test")
tk.MustExec("create table t(a int primary key, b int, c int,d int,key ib (b),key ic (c))")
tk.MustExec("SET session tidb_enable_index_merge = ON;")
tk.MustExec("set tidb_cost_model_version=2")
testcases := []struct {
sql string
physicalList []string
Expand All @@ -62,7 +61,7 @@ func TestPhysicalOptimizeWithTraceEnabled(t *testing.T) {
"Limit_20",
"IndexReader_21",
"Limit_14",
"StreamAgg_10",
"HashAgg_9",
"Projection_8",
},
},
Expand Down Expand Up @@ -95,6 +94,7 @@ func TestPhysicalOptimizeWithTraceEnabled(t *testing.T) {
require.NoError(t, err)
sctx := core.MockContext()
sctx.GetSessionVars().StmtCtx.EnableOptimizeTrace = true
sctx.GetSessionVars().CostModelVersion = 2
builder, _ := core.NewPlanBuilder().Init(sctx, dom.InfoSchema(), &hint.BlockHintProcessor{})
domain.GetDomain(sctx).MockInfoCacheAndLoadInfoSchema(dom.InfoSchema())
plan, err := builder.Build(context.TODO(), stmt)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/plan_cost_detail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestPlanCostDetail(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=1")
tk.MustExec(`create table t (a int primary key, b int, c int, d int, k int, key b(b), key cd(c, d), unique key(k))`)
testcases := []struct {
sql string
Expand Down Expand Up @@ -139,6 +138,7 @@ func optimize(t *testing.T, sql string, p *parser.Parser, ctx sessionctx.Context
sctx := plannercore.MockContext()
sctx.GetSessionVars().StmtCtx.EnableOptimizeTrace = true
sctx.GetSessionVars().EnableNewCostInterface = true
sctx.GetSessionVars().CostModelVersion = 1
builder, _ := plannercore.NewPlanBuilder().Init(sctx, dom.InfoSchema(), &hint.BlockHintProcessor{})
domain.GetDomain(sctx).MockInfoCacheAndLoadInfoSchema(dom.InfoSchema())
plan, err := builder.Build(context.TODO(), stmt)
Expand Down
Loading

0 comments on commit b03690a

Please sign in to comment.