From 4c1f28b385ff111ad97624f738764fe92b59a19b Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Fri, 15 Sep 2023 13:16:39 +0800 Subject: [PATCH] tests: Use `tk.MustHavePlan` and `tk.MustNotHavePlan` instead of `tk.HasPlan` (#46947) close pingcap/tidb#46945 --- bindinfo/session_handle_test.go | 22 +- bindinfo/tests/bind_test.go | 38 +-- executor/batch_point_get_test.go | 8 +- executor/distsql_test.go | 6 +- executor/index_lookup_join_test.go | 2 +- executor/partition_table_test.go | 292 +++++++++--------- executor/point_get_test.go | 4 +- executor/sample_test.go | 2 +- executor/temporary_table_test.go | 10 +- .../index_merge_reader_test.go | 54 ++-- executor/test/tiflashtest/tiflash_test.go | 2 +- executor/union_scan_test.go | 19 +- planner/core/casetest/integration_test.go | 6 +- planner/core/indexmerge_intersection_test.go | 10 +- planner/core/integration_partition_test.go | 4 +- planner/core/integration_test.go | 22 +- planner/core/issuetest/planner_issue_test.go | 2 +- .../clustered_index_test.go | 6 +- .../sessionstates/session_states_test.go | 12 +- table/tables/cache_test.go | 2 - testkit/testkit.go | 21 +- .../sessiontest/session_fail_test.go | 2 +- tests/realtikvtest/txntest/txn_test.go | 2 +- 23 files changed, 267 insertions(+), 281 deletions(-) diff --git a/bindinfo/session_handle_test.go b/bindinfo/session_handle_test.go index ba7b72eab61d1..f90aae0afcac7 100644 --- a/bindinfo/session_handle_test.go +++ b/bindinfo/session_handle_test.go @@ -43,14 +43,14 @@ func TestGlobalAndSessionBindingBothExist(t *testing.T) { tk.MustExec("drop table if exists t2") tk.MustExec("create table t1(id int)") tk.MustExec("create table t2(id int)") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) - require.True(t, tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") + tk.MustHavePlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") // Test bindingUsage, which indicates how many times the binding is used. metrics.BindUsageCounter.Reset() - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin") pb := &dto.Metric{} err := metrics.BindUsageCounter.WithLabelValues(metrics.ScopeGlobal).Write(pb) require.NoError(t, err) @@ -58,30 +58,30 @@ func TestGlobalAndSessionBindingBothExist(t *testing.T) { // Test 'tidb_use_plan_baselines' tk.MustExec("set @@tidb_use_plan_baselines = 0") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") tk.MustExec("set @@tidb_use_plan_baselines = 1") // Test 'drop global binding' - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") // Test the case when global and session binding both exist // PART1 : session binding should totally cover global binding // use merge join as session binding here since the optimizer will choose hash join for this stmt in default tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_HJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") tk.MustExec("create binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin") // PART2 : the dropped session binding should continue to block the effect of global binding tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") tk.MustExec("drop binding for SELECT * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") } func TestSessionBinding(t *testing.T) { diff --git a/bindinfo/tests/bind_test.go b/bindinfo/tests/bind_test.go index 59c678a2b1b97..ac5e485fa8f9f 100644 --- a/bindinfo/tests/bind_test.go +++ b/bindinfo/tests/bind_test.go @@ -383,23 +383,23 @@ func TestExplain(t *testing.T) { tk.MustExec("create table t1(id int)") tk.MustExec("create table t2(id int)") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) - require.True(t, tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") + tk.MustHavePlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") // Add test for SetOprStmt tk.MustExec("create index index_id on t1(id)") - require.True(t, tk.HasPlan("SELECT * from t1 union SELECT * from t1", "IndexReader")) - require.True(t, tk.HasPlan("SELECT * from t1 use index(index_id) union SELECT * from t1", "IndexReader")) + tk.MustHavePlan("SELECT * from t1 union SELECT * from t1", "IndexReader") + tk.MustHavePlan("SELECT * from t1 use index(index_id) union SELECT * from t1", "IndexReader") tk.MustExec("create global binding for SELECT * from t1 union SELECT * from t1 using SELECT * from t1 use index(index_id) union SELECT * from t1") - require.True(t, tk.HasPlan("SELECT * from t1 union SELECT * from t1", "IndexReader")) + tk.MustHavePlan("SELECT * from t1 union SELECT * from t1", "IndexReader") tk.MustExec("drop global binding for SELECT * from t1 union SELECT * from t1") } @@ -433,8 +433,8 @@ func TestBindCTEMerge(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t1") tk.MustExec("create table t1(id int)") - require.True(t, tk.HasPlan("with cte as (select * from t1) select * from cte a, cte b", "CTEFullScan")) - require.False(t, tk.HasPlan("with cte as (select /*+ MERGE() */ * from t1) select * from cte a, cte b", "CTEFullScan")) + tk.MustHavePlan("with cte as (select * from t1) select * from cte a, cte b", "CTEFullScan") + tk.MustNotHavePlan("with cte as (select /*+ MERGE() */ * from t1) select * from cte a, cte b", "CTEFullScan") tk.MustExec(` create global binding for with cte as (select * from t1) select * from cte @@ -442,7 +442,7 @@ using with cte as (select /*+ MERGE() */ * from t1) select * from cte `) - require.False(t, tk.HasPlan("with cte as (select * from t1) select * from cte", "CTEFullScan")) + tk.MustNotHavePlan("with cte as (select * from t1) select * from cte", "CTEFullScan") } func TestBindNoDecorrelate(t *testing.T) { @@ -454,8 +454,8 @@ func TestBindNoDecorrelate(t *testing.T) { tk.MustExec("drop table if exists t2") tk.MustExec("create table t1(a int, b int)") tk.MustExec("create table t2(a int, b int)") - require.False(t, tk.HasPlan("select exists (select t2.b from t2 where t2.a = t1.b limit 2) from t1", "Apply")) - require.True(t, tk.HasPlan("select exists (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b limit 2) from t1", "Apply")) + tk.MustNotHavePlan("select exists (select t2.b from t2 where t2.a = t1.b limit 2) from t1", "Apply") + tk.MustHavePlan("select exists (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b limit 2) from t1", "Apply") tk.MustExec(` create global binding for @@ -464,7 +464,7 @@ using select exists (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b limit 2) from t1 `) - require.True(t, tk.HasPlan("select exists (select t2.b from t2 where t2.a = t1.b limit 2) from t1", "Apply")) + tk.MustHavePlan("select exists (select t2.b from t2 where t2.a = t1.b limit 2) from t1", "Apply") } // TestBindingSymbolList tests sql with "?, ?, ?, ?", fixes #13871 @@ -566,9 +566,9 @@ func TestDMLSQLBind(t *testing.T) { require.Equal(t, "t1:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0]) require.True(t, tk.MustUseIndex("delete from t1 where b = 1 and c > 1", "idx_c(c)")) - require.True(t, tk.HasPlan("delete t1, t2 from t1 inner join t2 on t1.b = t2.b", "HashJoin")) + tk.MustHavePlan("delete t1, t2 from t1 inner join t2 on t1.b = t2.b", "HashJoin") tk.MustExec("create global binding for delete t1, t2 from t1 inner join t2 on t1.b = t2.b using delete /*+ inl_join(t1) */ t1, t2 from t1 inner join t2 on t1.b = t2.b") - require.True(t, tk.HasPlan("delete t1, t2 from t1 inner join t2 on t1.b = t2.b", "IndexJoin")) + tk.MustHavePlan("delete t1, t2 from t1 inner join t2 on t1.b = t2.b", "IndexJoin") tk.MustExec("update t1 set a = 1 where b = 1 and c > 1") require.Equal(t, "t1:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0]) @@ -578,9 +578,9 @@ func TestDMLSQLBind(t *testing.T) { require.Equal(t, "t1:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0]) require.True(t, tk.MustUseIndex("update t1 set a = 1 where b = 1 and c > 1", "idx_c(c)")) - require.True(t, tk.HasPlan("update t1, t2 set t1.a = 1 where t1.b = t2.b", "HashJoin")) + tk.MustHavePlan("update t1, t2 set t1.a = 1 where t1.b = t2.b", "HashJoin") tk.MustExec("create global binding for update t1, t2 set t1.a = 1 where t1.b = t2.b using update /*+ inl_join(t1) */ t1, t2 set t1.a = 1 where t1.b = t2.b") - require.True(t, tk.HasPlan("update t1, t2 set t1.a = 1 where t1.b = t2.b", "IndexJoin")) + tk.MustHavePlan("update t1, t2 set t1.a = 1 where t1.b = t2.b", "IndexJoin") tk.MustExec("insert into t1 select * from t2 where t2.b = 2 and t2.c > 2") require.Equal(t, "t2:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0]) @@ -1154,14 +1154,14 @@ func TestSPMHitInfo(t *testing.T) { tk.MustExec("create table t1(id int)") tk.MustExec("create table t2(id int)") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin")) - require.True(t, tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin") + tk.MustHavePlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("0")) tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") - require.True(t, tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin")) + tk.MustHavePlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin") tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("1")) tk.MustExec("set binding disabled for SELECT * from t1,t2 where t1.id = t2.id") diff --git a/executor/batch_point_get_test.go b/executor/batch_point_get_test.go index 4b1eda8abe3d9..3309afd3be6b6 100644 --- a/executor/batch_point_get_test.go +++ b/executor/batch_point_get_test.go @@ -380,10 +380,10 @@ func TestBatchPointGetIssue46779(t *testing.T) { tk.MustExec("CREATE TABLE t1 (id int, c varchar(128), primary key (id)) PARTITION BY HASH (id) PARTITIONS 3;") tk.MustExec(`insert into t1 values (1, "a"), (11, "b"), (21, "c")`) query := "select * from t1 where id in (1, 1, 11)" - require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used + tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b")) query = "select * from t1 where id in (1, 11, 11, 21)" - require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used + tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b", "21 c")) tk.MustExec("drop table if exists t2") @@ -393,9 +393,9 @@ func TestBatchPointGetIssue46779(t *testing.T) { partition p2 values less than (30));`) tk.MustExec(`insert into t2 values (1, "a"), (11, "b"), (21, "c")`) query = "select * from t2 where id in (1, 1, 11)" - require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used + tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b")) - require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used + tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used query = "select * from t2 where id in (1, 11, 11, 21)" tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b", "21 c")) } diff --git a/executor/distsql_test.go b/executor/distsql_test.go index c00289ccb5c8d..ce02b2c1b3369 100644 --- a/executor/distsql_test.go +++ b/executor/distsql_test.go @@ -690,11 +690,11 @@ func TestIndexLookUpWithSelectForUpdateOnPartitionTable(t *testing.T) { tk.MustExec("use test") tk.MustExec("create table t(a int, b int, index k(b)) PARTITION BY HASH(a) partitions 4") tk.MustExec("insert into t(a, b) values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8)") - tk.HasPlan("select b from t use index(k) where b > 2 order by b limit 1 for update", "UnionScan") - tk.HasPlan("select b from t use index(k) where b > 2 order by b limit 1 for update", "IndexLookUp") + tk.MustHavePlan("select b from t use index(k) where b > 2 order by b limit 1 for update", "PartitionUnion") + tk.MustHavePlan("select b from t use index(k) where b > 2 order by b limit 1 for update", "IndexLookUp") tk.MustQuery("select b from t use index(k) where b > 2 order by b limit 1 for update").Check(testkit.Rows("3")) tk.MustExec("analyze table t") - tk.HasPlan("select b from t use index(k) where b > 2 order by b limit 1 for update", "IndexLookUp") + tk.MustHavePlan("select b from t use index(k) where b > 2 order by b limit 1 for update", "IndexLookUp") tk.MustQuery("select b from t use index(k) where b > 2 order by b limit 1 for update").Check(testkit.Rows("3")) } diff --git a/executor/index_lookup_join_test.go b/executor/index_lookup_join_test.go index 969fa9dee950f..8a72e796fd20e 100644 --- a/executor/index_lookup_join_test.go +++ b/executor/index_lookup_join_test.go @@ -192,7 +192,7 @@ func TestInapplicableIndexJoinHint(t *testing.T) { query := `select /*+ tidb_inlj(bb) */ aa.* from (select * from t1) as aa left join (select t2.a, t2.a*2 as a2 from t2) as bb on aa.a=bb.a;` - tk.HasPlan(query, "IndexJoin") + tk.MustHavePlan(query, "IndexJoin") } func TestIndexJoinOverflow(t *testing.T) { diff --git a/executor/partition_table_test.go b/executor/partition_table_test.go index c6b3608aedac6..18d7683b55327 100644 --- a/executor/partition_table_test.go +++ b/executor/partition_table_test.go @@ -206,30 +206,30 @@ func TestPointGetwithRangeAndListPartitionTable(t *testing.T) { // select a from t where a={x}; // the result is {x} x := rand.Intn(100) + 1 queryRange1 := fmt.Sprintf("select a from trange1 where a=%v", x) - require.True(t, tk.HasPlan(queryRange1, "Point_Get")) // check if PointGet is used + tk.MustHavePlan(queryRange1, "Point_Get") // check if PointGet is used tk.MustQuery(queryRange1).Check(testkit.Rows(fmt.Sprintf("%v", x))) queryRange2 := fmt.Sprintf("select a from trange1 where a=%v", x) - require.True(t, tk.HasPlan(queryRange2, "Point_Get")) // check if PointGet is used + tk.MustHavePlan(queryRange2, "Point_Get") // check if PointGet is used tk.MustQuery(queryRange2).Check(testkit.Rows(fmt.Sprintf("%v", x))) y := rand.Intn(12) + 1 queryList := fmt.Sprintf("select a from tlist where a=%v", y) - require.True(t, tk.HasPlan(queryList, "Point_Get")) // check if PointGet is used + tk.MustHavePlan(queryList, "Point_Get") // check if PointGet is used tk.MustQuery(queryList).Check(testkit.Rows(fmt.Sprintf("%v", y))) } // test table dual queryRange1 := "select a from trange1 where a=200" - require.True(t, tk.HasPlan(queryRange1, "TableDual")) // check if TableDual is used + tk.MustHavePlan(queryRange1, "TableDual") // check if TableDual is used tk.MustQuery(queryRange1).Check(testkit.Rows()) queryRange2 := "select a from trange2 where a=200" - require.True(t, tk.HasPlan(queryRange2, "TableDual")) // check if TableDual is used + tk.MustHavePlan(queryRange2, "TableDual") // check if TableDual is used tk.MustQuery(queryRange2).Check(testkit.Rows()) queryList := "select a from tlist where a=200" - require.True(t, tk.HasPlan(queryList, "TableDual")) // check if TableDual is used + tk.MustHavePlan(queryList, "TableDual") // check if TableDual is used tk.MustQuery(queryList).Check(testkit.Rows()) // test PointGet for one partition @@ -237,14 +237,14 @@ func TestPointGetwithRangeAndListPartitionTable(t *testing.T) { tk.MustExec("create table t(a int primary key, b int) PARTITION BY RANGE (a) (partition p0 values less than(1))") tk.MustExec("insert into t values (-1, 1), (-2, 1)") tk.MustExec("analyze table t") - require.True(t, tk.HasPlan(queryOnePartition, "Point_Get")) + tk.MustHavePlan(queryOnePartition, "Point_Get") tk.MustQuery(queryOnePartition).Check(testkit.Rows(fmt.Sprintf("%v", -1))) tk.MustExec("drop table t") tk.MustExec("create table t(a int primary key, b int) PARTITION BY list (a) (partition p0 values in (-1, -2))") tk.MustExec("insert into t values (-1, 1), (-2, 1)") tk.MustExec("analyze table t") - require.True(t, tk.HasPlan(queryOnePartition, "Point_Get")) + tk.MustHavePlan(queryOnePartition, "Point_Get") tk.MustQuery(queryOnePartition).Check(testkit.Rows(fmt.Sprintf("%v", -1))) } @@ -543,7 +543,7 @@ func TestOrderByAndLimit(t *testing.T) { y := rand.Intn(500) + 1 queryPartition := fmt.Sprintf("select * from trange use index(idx_a) where a > %v order by a, b limit %v;", x, y) queryRegular := fmt.Sprintf("select * from tregular use index(idx_a) where a > %v order by a, b limit %v;", x, y) - require.True(t, tk.HasPlan(queryPartition, "IndexLookUp")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition, "IndexLookUp") // check if IndexLookUp is used tk.MustQuery(queryPartition).Check(tk.MustQuery(queryRegular).Rows()) } @@ -568,17 +568,17 @@ func TestOrderByAndLimit(t *testing.T) { regularResult := tk.MustQuery(queryRegular).Sort().Rows() if len(regularResult) > 0 { - require.True(t, tk.HasPlan(queryRangePartitionWithLimitHint, "Limit")) - require.True(t, tk.HasPlan(queryRangePartitionWithLimitHint, "IndexLookUp")) - require.True(t, tk.HasPlan(queryHashPartitionWithLimitHint, "Limit")) - require.True(t, tk.HasPlan(queryHashPartitionWithLimitHint, "IndexLookUp")) - require.True(t, tk.HasPlan(queryListPartitionWithLimitHint, "Limit")) - require.True(t, tk.HasPlan(queryListPartitionWithLimitHint, "IndexLookUp")) + tk.MustHavePlan(queryRangePartitionWithLimitHint, "Limit") + tk.MustHavePlan(queryRangePartitionWithLimitHint, "IndexLookUp") + tk.MustHavePlan(queryHashPartitionWithLimitHint, "Limit") + tk.MustHavePlan(queryHashPartitionWithLimitHint, "IndexLookUp") + tk.MustHavePlan(queryListPartitionWithLimitHint, "Limit") + tk.MustHavePlan(queryListPartitionWithLimitHint, "IndexLookUp") } if i%2 != 0 { - require.False(t, tk.HasPlan(queryRangePartitionWithLimitHint, "TopN")) // fully pushed - require.False(t, tk.HasPlan(queryHashPartitionWithLimitHint, "TopN")) - require.False(t, tk.HasPlan(queryListPartitionWithLimitHint, "TopN")) + tk.MustNotHavePlan(queryRangePartitionWithLimitHint, "TopN") // fully pushed + tk.MustNotHavePlan(queryHashPartitionWithLimitHint, "TopN") + tk.MustNotHavePlan(queryListPartitionWithLimitHint, "TopN") } tk.MustQuery(queryRangePartitionWithLimitHint).Sort().Check(regularResult) tk.MustQuery(queryHashPartitionWithLimitHint).Sort().Check(regularResult) @@ -604,17 +604,17 @@ func TestOrderByAndLimit(t *testing.T) { regularResult := tk.MustQuery(queryRegular).Sort().Rows() if len(regularResult) > 0 { - require.True(t, tk.HasPlan(queryRangePartitionWithLimitHint, "Limit")) - require.True(t, tk.HasPlan(queryRangePartitionWithLimitHint, "IndexLookUp")) - require.True(t, tk.HasPlan(queryHashPartitionWithLimitHint, "Limit")) - require.True(t, tk.HasPlan(queryHashPartitionWithLimitHint, "IndexLookUp")) - require.True(t, tk.HasPlan(queryListPartitionWithLimitHint, "Limit")) - require.True(t, tk.HasPlan(queryListPartitionWithLimitHint, "IndexLookUp")) + tk.MustHavePlan(queryRangePartitionWithLimitHint, "Limit") + tk.MustHavePlan(queryRangePartitionWithLimitHint, "IndexLookUp") + tk.MustHavePlan(queryHashPartitionWithLimitHint, "Limit") + tk.MustHavePlan(queryHashPartitionWithLimitHint, "IndexLookUp") + tk.MustHavePlan(queryListPartitionWithLimitHint, "Limit") + tk.MustHavePlan(queryListPartitionWithLimitHint, "IndexLookUp") } if i%2 != 0 { - require.False(t, tk.HasPlan(queryRangePartitionWithLimitHint, "TopN")) // fully pushed - require.False(t, tk.HasPlan(queryHashPartitionWithLimitHint, "TopN")) - require.False(t, tk.HasPlan(queryListPartitionWithLimitHint, "TopN")) + tk.MustNotHavePlan(queryRangePartitionWithLimitHint, "TopN") // fully pushed + tk.MustNotHavePlan(queryHashPartitionWithLimitHint, "TopN") + tk.MustNotHavePlan(queryListPartitionWithLimitHint, "TopN") } tk.MustQuery(queryRangePartitionWithLimitHint).Sort().Check(regularResult) tk.MustQuery(queryHashPartitionWithLimitHint).Sort().Check(regularResult) @@ -631,7 +631,7 @@ func TestOrderByAndLimit(t *testing.T) { y := rand.Intn(500) + 1 queryPartition := fmt.Sprintf("select * from trange ignore index(idx_a, idx_ab) where a > %v order by a, b limit %v;", x, y) queryRegular := fmt.Sprintf("select * from tregular ignore index(idx_a, idx_ab) where a > %v order by a, b limit %v;", x, y) - require.True(t, tk.HasPlan(queryPartition, "TableReader")) // check if tableReader is used + tk.MustHavePlan(queryPartition, "TableReader") // check if tableReader is used tk.MustQuery(queryPartition).Check(tk.MustQuery(queryRegular).Rows()) } @@ -645,12 +645,12 @@ func TestOrderByAndLimit(t *testing.T) { queryHashPartition := fmt.Sprintf("select /*+ LIMIT_TO_COP() */ * from thash ignore index(idx_a, idx_ab) where a > %v order by a, b limit %v;", x, y) queryListPartition := fmt.Sprintf("select /*+ LIMIT_TO_COP() */ * from tlist ignore index(idx_a, idx_ab) where a > %v order by a, b limit %v;", x, y) queryRegular := fmt.Sprintf("select * from tregular ignore index(idx_a) where a > %v order by a, b limit %v;", x, y) - require.True(t, tk.HasPlan(queryRangePartition, "TableReader")) // check if tableReader is used - require.True(t, tk.HasPlan(queryHashPartition, "TableReader")) - require.True(t, tk.HasPlan(queryListPartition, "TableReader")) - require.False(t, tk.HasPlan(queryRangePartition, "Limit")) // check if order property is not pushed - require.False(t, tk.HasPlan(queryHashPartition, "Limit")) - require.False(t, tk.HasPlan(queryListPartition, "Limit")) + tk.MustHavePlan(queryRangePartition, "TableReader") // check if tableReader is used + tk.MustHavePlan(queryHashPartition, "TableReader") + tk.MustHavePlan(queryListPartition, "TableReader") + tk.MustNotHavePlan(queryRangePartition, "Limit") // check if order property is not pushed + tk.MustNotHavePlan(queryHashPartition, "Limit") + tk.MustNotHavePlan(queryListPartition, "Limit") regularResult := tk.MustQuery(queryRegular).Rows() tk.MustQuery(queryRangePartition).Check(regularResult) tk.MustQuery(queryHashPartition).Check(regularResult) @@ -662,15 +662,15 @@ func TestOrderByAndLimit(t *testing.T) { queryHashPartition = fmt.Sprintf("select /*+ LIMIT_TO_COP() */ a from thash_intpk use index(primary) where a > %v order by a limit %v", x, y) queryListPartition = fmt.Sprintf("select /*+ LIMIT_TO_COP() */ a from tlist_intpk use index(primary) where a > %v order by a limit %v", x, y) queryRegular = fmt.Sprintf("select a from tregular_intpk where a > %v order by a limit %v", x, y) - require.True(t, tk.HasPlan(queryRangePartition, "TableReader")) - require.True(t, tk.HasPlan(queryHashPartition, "TableReader")) - require.True(t, tk.HasPlan(queryListPartition, "TableReader")) - require.True(t, tk.HasPlan(queryRangePartition, "Limit")) // check if order property is pushed - require.False(t, tk.HasPlan(queryRangePartition, "TopN")) // and is fully pushed - require.True(t, tk.HasPlan(queryHashPartition, "Limit")) - require.False(t, tk.HasPlan(queryHashPartition, "TopN")) - require.True(t, tk.HasPlan(queryListPartition, "Limit")) - require.False(t, tk.HasPlan(queryListPartition, "TopN")) + tk.MustHavePlan(queryRangePartition, "TableReader") + tk.MustHavePlan(queryHashPartition, "TableReader") + tk.MustHavePlan(queryListPartition, "TableReader") + tk.MustHavePlan(queryRangePartition, "Limit") // check if order property is pushed + tk.MustNotHavePlan(queryRangePartition, "TopN") // and is fully pushed + tk.MustHavePlan(queryHashPartition, "Limit") + tk.MustNotHavePlan(queryHashPartition, "TopN") + tk.MustHavePlan(queryListPartition, "Limit") + tk.MustNotHavePlan(queryListPartition, "TopN") regularResult = tk.MustQuery(queryRegular).Rows() tk.MustQuery(queryRangePartition).Check(regularResult) tk.MustQuery(queryHashPartition).Check(regularResult) @@ -681,15 +681,15 @@ func TestOrderByAndLimit(t *testing.T) { queryHashPartition = fmt.Sprintf("select /*+ LIMIT_TO_COP() */ * from thash_clustered use index(primary) where a > %v order by a, b limit %v;", x, y) queryListPartition = fmt.Sprintf("select /*+ LIMIT_TO_COP() */ * from tlist_clustered use index(primary) where a > %v order by a, b limit %v;", x, y) queryRegular = fmt.Sprintf("select * from tregular_clustered where a > %v order by a, b limit %v;", x, y) - require.True(t, tk.HasPlan(queryRangePartition, "TableReader")) // check if tableReader is used - require.True(t, tk.HasPlan(queryHashPartition, "TableReader")) - require.True(t, tk.HasPlan(queryListPartition, "TableReader")) - require.True(t, tk.HasPlan(queryRangePartition, "Limit")) // check if order property is pushed - require.True(t, tk.HasPlan(queryHashPartition, "Limit")) - require.True(t, tk.HasPlan(queryListPartition, "Limit")) - require.False(t, tk.HasPlan(queryRangePartition, "TopN")) // could fully pushed for TableScan executor - require.False(t, tk.HasPlan(queryHashPartition, "TopN")) - require.False(t, tk.HasPlan(queryListPartition, "TopN")) + tk.MustHavePlan(queryRangePartition, "TableReader") // check if tableReader is used + tk.MustHavePlan(queryHashPartition, "TableReader") + tk.MustHavePlan(queryListPartition, "TableReader") + tk.MustHavePlan(queryRangePartition, "Limit") // check if order property is pushed + tk.MustHavePlan(queryHashPartition, "Limit") + tk.MustHavePlan(queryListPartition, "Limit") + tk.MustNotHavePlan(queryRangePartition, "TopN") // could fully pushed for TableScan executor + tk.MustNotHavePlan(queryHashPartition, "TopN") + tk.MustNotHavePlan(queryListPartition, "TopN") regularResult = tk.MustQuery(queryRegular).Rows() tk.MustQuery(queryRangePartition).Check(regularResult) tk.MustQuery(queryHashPartition).Check(regularResult) @@ -701,12 +701,12 @@ func TestOrderByAndLimit(t *testing.T) { // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") queryPartitionWithTiFlash = fmt.Sprintf("select /*+ read_from_storage(tiflash[trange_intpk]) */ /*+ LIMIT_TO_COP() */ * from trange_intpk where a > %v order by a limit %v", x, y) // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") queryPartitionWithTiFlash = fmt.Sprintf("select /*+ read_from_storage(tiflash[trange_clustered]) */ * from trange_clustered where a > %v order by a limit %v", x, y) // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) @@ -714,7 +714,7 @@ func TestOrderByAndLimit(t *testing.T) { // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash)) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") queryPartitionWithTiFlash = fmt.Sprintf("select /*+ read_from_storage(tiflash[thash_intpk]) */ * from thash_intpk where a > %v order by a limit %v", x, y) // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) @@ -722,7 +722,7 @@ func TestOrderByAndLimit(t *testing.T) { // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash)) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") queryPartitionWithTiFlash = fmt.Sprintf("select /*+ read_from_storage(tiflash[thash_clustered]) */ * from thash_clustered where a > %v order by a limit %v", x, y) // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) @@ -730,7 +730,7 @@ func TestOrderByAndLimit(t *testing.T) { // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash)) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") queryPartitionWithTiFlash = fmt.Sprintf("select /*+ read_from_storage(tiflash[tlist_intpk]) */ * from tlist_intpk where a > %v order by a limit %v", x, y) // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) @@ -738,7 +738,7 @@ func TestOrderByAndLimit(t *testing.T) { // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash)) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") queryPartitionWithTiFlash = fmt.Sprintf("select /*+ read_from_storage(tiflash[tlist_clustered]) */ * from tlist_clustered where a > %v order by a limit %v", x, y) // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) @@ -746,7 +746,7 @@ func TestOrderByAndLimit(t *testing.T) { // check if tiflash is used require.True(t, tk.HasTiFlashPlan(queryPartitionWithTiFlash)) // but order is not pushed - require.False(t, tk.HasPlan(queryPartitionWithTiFlash, "Limit"), fmt.Sprintf("%v", tk.MustQuery("explain "+queryPartitionWithTiFlash).Rows())) + tk.MustNotHavePlan(queryPartitionWithTiFlash, "Limit") tk.MustExec(" set @@tidb_allow_mpp=0;") tk.MustExec("set @@session.tidb_isolation_read_engines=\"tikv\"") } @@ -759,7 +759,7 @@ func TestOrderByAndLimit(t *testing.T) { y := rand.Intn(500) + 1 queryPartition := fmt.Sprintf("select a from trange use index(idx_a) where a > %v order by a limit %v;", x, y) queryRegular := fmt.Sprintf("select a from tregular use index(idx_a) where a > %v order by a limit %v;", x, y) - require.True(t, tk.HasPlan(queryPartition, "IndexReader")) // check if indexReader is used + tk.MustHavePlan(queryPartition, "IndexReader") // check if indexReader is used tk.MustQuery(queryPartition).Check(tk.MustQuery(queryRegular).Rows()) } @@ -772,12 +772,12 @@ func TestOrderByAndLimit(t *testing.T) { queryRangePartition := fmt.Sprintf("select /*+ LIMIT_TO_COP() */ a from trange use index(idx_a) where a > %v order by a limit %v;", x, y) queryHashPartition := fmt.Sprintf("select /*+ LIMIT_TO_COP() */ a from thash use index(idx_a) where a > %v order by a limit %v;", x, y) queryRegular := fmt.Sprintf("select a from tregular use index(idx_a) where a > %v order by a limit %v;", x, y) - require.True(t, tk.HasPlan(queryRangePartition, "IndexReader")) // check if indexReader is used - require.True(t, tk.HasPlan(queryHashPartition, "IndexReader")) - require.True(t, tk.HasPlan(queryRangePartition, "Limit")) // check if order property is pushed - require.True(t, tk.HasPlan(queryHashPartition, "Limit")) - require.False(t, tk.HasPlan(queryRangePartition, "TopN")) // fully pushed limit - require.False(t, tk.HasPlan(queryHashPartition, "TopN")) + tk.MustHavePlan(queryRangePartition, "IndexReader") // check if indexReader is used + tk.MustHavePlan(queryHashPartition, "IndexReader") + tk.MustHavePlan(queryRangePartition, "Limit") // check if order property is pushed + tk.MustHavePlan(queryHashPartition, "Limit") + tk.MustNotHavePlan(queryRangePartition, "TopN") // fully pushed limit + tk.MustNotHavePlan(queryHashPartition, "TopN") regularResult := tk.MustQuery(queryRegular).Rows() tk.MustQuery(queryRangePartition).Check(regularResult) tk.MustQuery(queryHashPartition).Check(regularResult) @@ -791,15 +791,15 @@ func TestOrderByAndLimit(t *testing.T) { queryHashPartition := fmt.Sprintf("select /*+ LIMIT_TO_COP() */ a from thash use index(idx_ab) where a = %v order by b limit %v;", x, y) queryListPartition := fmt.Sprintf("select /*+ LIMIT_TO_COP() */ a from tlist use index(idx_ab) where a = %v order by b limit %v;", x, y) queryRegular := fmt.Sprintf("select a from tregular use index(idx_ab) where a = %v order by b limit %v;", x, y) - require.True(t, tk.HasPlan(queryRangePartition, "IndexReader")) // check if indexReader is used - require.True(t, tk.HasPlan(queryHashPartition, "IndexReader")) - require.True(t, tk.HasPlan(queryListPartition, "IndexReader")) - require.True(t, tk.HasPlan(queryRangePartition, "Limit")) // check if order property is pushed - require.True(t, tk.HasPlan(queryHashPartition, "Limit")) - require.True(t, tk.HasPlan(queryListPartition, "Limit")) - require.False(t, tk.HasPlan(queryRangePartition, "TopN")) // fully pushed limit - require.False(t, tk.HasPlan(queryHashPartition, "TopN")) - require.False(t, tk.HasPlan(queryListPartition, "TopN")) + tk.MustHavePlan(queryRangePartition, "IndexReader") // check if indexReader is used + tk.MustHavePlan(queryHashPartition, "IndexReader") + tk.MustHavePlan(queryListPartition, "IndexReader") + tk.MustHavePlan(queryRangePartition, "Limit") // check if order property is pushed + tk.MustHavePlan(queryHashPartition, "Limit") + tk.MustHavePlan(queryListPartition, "Limit") + tk.MustNotHavePlan(queryRangePartition, "TopN") // fully pushed limit + tk.MustNotHavePlan(queryHashPartition, "TopN") + tk.MustNotHavePlan(queryListPartition, "TopN") regularResult := tk.MustQuery(queryRegular).Rows() tk.MustQuery(queryRangePartition).Check(regularResult) tk.MustQuery(queryHashPartition).Check(regularResult) @@ -813,7 +813,7 @@ func TestOrderByAndLimit(t *testing.T) { y := rand.Intn(500) + 1 queryHashPartition := fmt.Sprintf("select /*+ use_index_merge(thash) */ * from thash where a > 2 or b < 5 order by a, b limit %v;", y) queryRegular := fmt.Sprintf("select * from tregular where a > 2 or b < 5 order by a, b limit %v;", y) - require.True(t, tk.HasPlan(queryHashPartition, "IndexMerge")) // check if indexMerge is used + tk.MustHavePlan(queryHashPartition, "IndexMerge") // check if indexMerge is used tk.MustQuery(queryHashPartition).Check(tk.MustQuery(queryRegular).Rows()) } @@ -971,13 +971,13 @@ func TestBatchGetandPointGetwithHashPartition(t *testing.T) { x := rand.Intn(100) + 1 queryHash := fmt.Sprintf("select a from thash where a=%v", x) queryRegular := fmt.Sprintf("select a from tregular where a=%v", x) - require.True(t, tk.HasPlan(queryHash, "Point_Get")) // check if PointGet is used + tk.MustHavePlan(queryHash, "Point_Get") // check if PointGet is used tk.MustQuery(queryHash).Check(tk.MustQuery(queryRegular).Rows()) } // test empty PointGet queryHash := "select a from thash where a=200" - require.True(t, tk.HasPlan(queryHash, "Point_Get")) // check if PointGet is used + tk.MustHavePlan(queryHash, "Point_Get") // check if PointGet is used tk.MustQuery(queryHash).Check(testkit.Rows()) // test BatchGet @@ -992,7 +992,7 @@ func TestBatchGetandPointGetwithHashPartition(t *testing.T) { queryHash := fmt.Sprintf("select a from thash where a in (%v)", strings.Join(points, ",")) queryRegular := fmt.Sprintf("select a from tregular where a in (%v)", strings.Join(points, ",")) - require.True(t, tk.HasPlan(queryHash, "Point_Get")) // check if PointGet is used + tk.MustHavePlan(queryHash, "Point_Get") // check if PointGet is used tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) } } @@ -1361,11 +1361,11 @@ func TestBatchGetforRangeandListPartitionTable(t *testing.T) { queryRegular1 := fmt.Sprintf("select a from tregular1 where a in (%v)", strings.Join(points, ",")) queryHash := fmt.Sprintf("select a from thash where a in (%v)", strings.Join(points, ",")) - require.True(t, tk.HasPlan(queryHash, "Batch_Point_Get")) // check if BatchGet is used + tk.MustHavePlan(queryHash, "Batch_Point_Get") // check if BatchGet is used tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryRange := fmt.Sprintf("select a from trange where a in (%v)", strings.Join(points, ",")) - require.True(t, tk.HasPlan(queryRange, "Batch_Point_Get")) // check if BatchGet is used + tk.MustHavePlan(queryRange, "Batch_Point_Get") // check if BatchGet is used tk.MustQuery(queryRange).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) points = make([]string, 0, 10) @@ -1375,7 +1375,7 @@ func TestBatchGetforRangeandListPartitionTable(t *testing.T) { } queryRegular2 := fmt.Sprintf("select a from tregular2 where a in (%v)", strings.Join(points, ",")) queryList := fmt.Sprintf("select a from tlist where a in (%v)", strings.Join(points, ",")) - require.True(t, tk.HasPlan(queryList, "Batch_Point_Get")) // check if BatchGet is used + tk.MustHavePlan(queryList, "Batch_Point_Get") // check if BatchGet is used tk.MustQuery(queryList).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) } @@ -1405,7 +1405,7 @@ func TestBatchGetforRangeandListPartitionTable(t *testing.T) { } queryRegular := fmt.Sprintf("select a from tregular3 where a in (%v)", strings.Join(points, ",")) queryRange := fmt.Sprintf("select a from trange3 where a in (%v)", strings.Join(points, ",")) - require.True(t, tk.HasPlan(queryRange, "Batch_Point_Get")) // check if BatchGet is used + tk.MustHavePlan(queryRange, "Batch_Point_Get") // check if BatchGet is used tk.MustQuery(queryRange).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) } @@ -1453,17 +1453,17 @@ func TestGlobalStatsAndSQLBinding(t *testing.T) { tk.MustExec("insert into tlist values " + strings.Join(listVals, ",")) // before analyzing, the planner will choose TableScan to access the 1% of records - require.True(t, tk.HasPlan("select * from thash where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from trange where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from tlist where a<1", "TableFullScan")) + 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") - require.True(t, tk.HasPlan("select * from thash where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from trange where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from tlist where a<1", "TableFullScan")) + 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") @@ -1471,18 +1471,18 @@ func TestGlobalStatsAndSQLBinding(t *testing.T) { 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 - require.True(t, tk.HasPlan("select * from thash where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from trange where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from tlist where a<1", "TableFullScan")) + 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") - require.True(t, tk.HasPlan("select * from thash where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from trange where a<100", "TableFullScan")) - require.True(t, tk.HasPlan("select * from tlist where a<1", "TableFullScan")) + 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) { @@ -1532,78 +1532,78 @@ func TestPartitionTableWithDifferentJoin(t *testing.T) { // hash_join range partition and hash partition queryHash := fmt.Sprintf("select /*+ hash_join(trange, thash) */ * from trange, thash where trange.b=thash.b and thash.a = %v and trange.a > %v;", x1, x2) queryRegular := fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.b=tregular1.b and tregular1.a = %v and tregular2.a > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ hash_join(trange, thash) */ * from trange, thash where trange.a=thash.a and thash.a > %v;", x1) queryRegular = fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a=tregular1.a and tregular1.a > %v;", x1) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ hash_join(trange, thash) */ * from trange, thash where trange.a=thash.a and trange.b = thash.b and thash.a > %v;", x1) queryRegular = fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a=tregular1.a and tregular1.b = tregular2.b and tregular1.a > %v;", x1) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ hash_join(trange, thash) */ * from trange, thash where trange.a=thash.a and thash.a = %v;", x1) queryRegular = fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a=tregular1.a and tregular1.a = %v;", x1) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) // group 2 // hash_join range partition and regular table queryHash = fmt.Sprintf("select /*+ hash_join(trange, tregular1) */ * from trange, tregular1 where trange.a = tregular1.a and trange.a >= %v and tregular1.a > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a = tregular1.a and tregular2.a >= %v and tregular1.a > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ hash_join(trange, tregular1) */ * from trange, tregular1 where trange.a = tregular1.a and trange.a in (%v, %v, %v);", x1, x2, x3) queryRegular = fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a = tregular1.a and tregular2.a in (%v, %v, %v);", x1, x2, x3) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ hash_join(trange, tregular1) */ * from trange, tregular1 where trange.a = tregular1.a and tregular1.a >= %v;", x1) queryRegular = fmt.Sprintf("select /*+ hash_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a = tregular1.a and tregular1.a >= %v;", x1) - require.True(t, tk.HasPlan(queryHash, "HashJoin")) + tk.MustHavePlan(queryHash, "HashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) // group 3 // merge_join range partition and hash partition queryHash = fmt.Sprintf("select /*+ merge_join(trange, thash) */ * from trange, thash where trange.b=thash.b and thash.a = %v and trange.a > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.b=tregular1.b and tregular1.a = %v and tregular2.a > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ merge_join(trange, thash) */ * from trange, thash where trange.a=thash.a and thash.a > %v;", x1) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a=tregular1.a and tregular1.a > %v;", x1) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ merge_join(trange, thash) */ * from trange, thash where trange.a=thash.a and trange.b = thash.b and thash.a > %v;", x1) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a=tregular1.a and tregular1.b = tregular2.b and tregular1.a > %v;", x1) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ merge_join(trange, thash) */ * from trange, thash where trange.a=thash.a and thash.a = %v;", x1) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a=tregular1.a and tregular1.a = %v;", x1) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) // group 4 // merge_join range partition and regular table queryHash = fmt.Sprintf("select /*+ merge_join(trange, tregular1) */ * from trange, tregular1 where trange.a = tregular1.a and trange.a >= %v and tregular1.a > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a = tregular1.a and tregular2.a >= %v and tregular1.a > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ merge_join(trange, tregular1) */ * from trange, tregular1 where trange.a = tregular1.a and trange.a in (%v, %v, %v);", x1, x2, x3) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a = tregular1.a and tregular2.a in (%v, %v, %v);", x1, x2, x3) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ merge_join(trange, tregular1) */ * from trange, tregular1 where trange.a = tregular1.a and tregular1.a >= %v;", x1) queryRegular = fmt.Sprintf("select /*+ merge_join(tregular2, tregular1) */ * from tregular2, tregular1 where tregular2.a = tregular1.a and tregular1.a >= %v;", x1) - require.True(t, tk.HasPlan(queryHash, "MergeJoin")) + tk.MustHavePlan(queryHash, "MergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) // new table instances @@ -1637,28 +1637,28 @@ func TestPartitionTableWithDifferentJoin(t *testing.T) { // Currently don't support index merge join on two partition tables. Only test warning. queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, trange2) */ * from trange, trange2 where trange.a=trange2.a and trange.a > %v;", x1) // queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v;", x1) - // require.True(t,tk.HasPlan(queryHash, "IndexMergeJoin")) + // tk.MustHavePlan(queryHash, "IndexMergeJoin") // tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) tk.MustQuery(queryHash) tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1815|Optimizer Hint /*+ INL_MERGE_JOIN(trange, trange2) */ is inapplicable")) queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, trange2) */ * from trange, trange2 where trange.a=trange2.a and trange.a > %v and trange2.a > %v;", x1, x2) // queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v and tregular4.a > %v;", x1, x2) - // require.True(t,tk.HasPlan(queryHash, "IndexMergeJoin")) + // tk.MustHavePlan(queryHash, "IndexMergeJoin") // tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) tk.MustQuery(queryHash) tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1815|Optimizer Hint /*+ INL_MERGE_JOIN(trange, trange2) */ is inapplicable")) queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, trange2) */ * from trange, trange2 where trange.a=trange2.a and trange.a > %v and trange.b > %v;", x1, x2) // queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v and tregular2.b > %v;", x1, x2) - // require.True(t,tk.HasPlan(queryHash, "IndexMergeJoin")) + // tk.MustHavePlan(queryHash, "IndexMergeJoin") // tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) tk.MustQuery(queryHash) tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1815|Optimizer Hint /*+ INL_MERGE_JOIN(trange, trange2) */ is inapplicable")) queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, trange2) */ * from trange, trange2 where trange.a=trange2.a and trange.a > %v and trange2.b > %v;", x1, x2) // queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v and tregular4.b > %v;", x1, x2) - // require.True(t,tk.HasPlan(queryHash, "IndexMergeJoin")) + // tk.MustHavePlan(queryHash, "IndexMergeJoin") // tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) tk.MustQuery(queryHash) tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1815|Optimizer Hint /*+ INL_MERGE_JOIN(trange, trange2) */ is inapplicable")) @@ -1667,56 +1667,56 @@ func TestPartitionTableWithDifferentJoin(t *testing.T) { // index_merge_join range partition and regualr table queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, tregular4) */ * from trange, tregular4 where trange.a=tregular4.a and trange.a > %v;", x1) queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v;", x1) - require.True(t, tk.HasPlan(queryHash, "IndexMergeJoin")) + tk.MustHavePlan(queryHash, "IndexMergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, tregular4) */ * from trange, tregular4 where trange.a=tregular4.a and trange.a > %v and tregular4.a > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v and tregular4.a > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexMergeJoin")) + tk.MustHavePlan(queryHash, "IndexMergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, tregular4) */ * from trange, tregular4 where trange.a=tregular4.a and trange.a > %v and trange.b > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v and tregular2.b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexMergeJoin")) + tk.MustHavePlan(queryHash, "IndexMergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_merge_join(trange, tregular4) */ * from trange, tregular4 where trange.a=tregular4.a and trange.a > %v and tregular4.b > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_merge_join(tregular2, tregular4) */ * from tregular2, tregular4 where tregular2.a=tregular4.a and tregular2.a > %v and tregular4.b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexMergeJoin")) + tk.MustHavePlan(queryHash, "IndexMergeJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) // group 7 // index_hash_join hash partition and hash partition queryHash = fmt.Sprintf("select /*+ inl_hash_join(thash, thash2) */ * from thash, thash2 where thash.a = thash2.a and thash.a in (%v, %v);", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_hash_join(tregular1, tregular3) */ * from tregular1, tregular3 where tregular1.a = tregular3.a and tregular1.a in (%v, %v);", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexHashJoin")) + tk.MustHavePlan(queryHash, "IndexHashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_hash_join(thash, thash2) */ * from thash, thash2 where thash.a = thash2.a and thash.a in (%v, %v) and thash2.a in (%v, %v);", x1, x2, x3, x4) queryRegular = fmt.Sprintf("select /*+ inl_hash_join(tregular1, tregular3) */ * from tregular1, tregular3 where tregular1.a = tregular3.a and tregular1.a in (%v, %v) and tregular3.a in (%v, %v);", x1, x2, x3, x4) - require.True(t, tk.HasPlan(queryHash, "IndexHashJoin")) + tk.MustHavePlan(queryHash, "IndexHashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_hash_join(thash, thash2) */ * from thash, thash2 where thash.a = thash2.a and thash.a > %v and thash2.b > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_hash_join(tregular1, tregular3) */ * from tregular1, tregular3 where tregular1.a = tregular3.a and tregular1.a > %v and tregular3.b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexHashJoin")) + tk.MustHavePlan(queryHash, "IndexHashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) // group 8 // index_hash_join hash partition and hash partition queryHash = fmt.Sprintf("select /*+ inl_hash_join(thash, tregular3) */ * from thash, tregular3 where thash.a = tregular3.a and thash.a in (%v, %v);", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_hash_join(tregular1, tregular3) */ * from tregular1, tregular3 where tregular1.a = tregular3.a and tregular1.a in (%v, %v);", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexHashJoin")) + tk.MustHavePlan(queryHash, "IndexHashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_hash_join(thash, tregular3) */ * from thash, tregular3 where thash.a = tregular3.a and thash.a in (%v, %v) and tregular3.a in (%v, %v);", x1, x2, x3, x4) queryRegular = fmt.Sprintf("select /*+ inl_hash_join(tregular1, tregular3) */ * from tregular1, tregular3 where tregular1.a = tregular3.a and tregular1.a in (%v, %v) and tregular3.a in (%v, %v);", x1, x2, x3, x4) - require.True(t, tk.HasPlan(queryHash, "IndexHashJoin")) + tk.MustHavePlan(queryHash, "IndexHashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) queryHash = fmt.Sprintf("select /*+ inl_hash_join(thash, tregular3) */ * from thash, tregular3 where thash.a = tregular3.a and thash.a > %v and tregular3.b > %v;", x1, x2) queryRegular = fmt.Sprintf("select /*+ inl_hash_join(tregular1, tregular3) */ * from tregular1, tregular3 where tregular1.a = tregular3.a and tregular1.a > %v and tregular3.b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryHash, "IndexHashJoin")) + tk.MustHavePlan(queryHash, "IndexHashJoin") tk.MustQuery(queryHash).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows()) } @@ -2819,7 +2819,7 @@ func TestDirectReadingWithUnionScan(t *testing.T) { var result [][]interface{} for _, tb := range []string{`trange`, `tnormal`, `thash`} { q := fmt.Sprintf(sql, tb) - tk.HasPlan(q, `UnionScan`) + tk.MustHavePlan(q, `UnionScan`) if result == nil { result = tk.MustQuery(q).Sort().Rows() } else { @@ -2907,7 +2907,7 @@ func TestUnsignedPartitionColumn(t *testing.T) { for tid, tbl := range []string{"tnormal_pk", "trange_pk", "thash_pk"} { // unsigned + TableReader scanSQL := fmt.Sprintf("select * from %v use index(primary) where %v", tbl, scanCond) - require.True(t, tk.HasPlan(scanSQL, "TableReader")) + tk.MustHavePlan(scanSQL, "TableReader") r := tk.MustQuery(scanSQL).Sort() if tid == 0 { rScan = r.Rows() @@ -2927,7 +2927,7 @@ func TestUnsignedPartitionColumn(t *testing.T) { // unsigned + BatchGet on PK batchSQL := fmt.Sprintf("select * from %v where %v", tbl, batchCond) - require.True(t, tk.HasPlan(batchSQL, "Batch_Point_Get")) + tk.MustHavePlan(batchSQL, "Batch_Point_Get") r = tk.MustQuery(batchSQL).Sort() if tid == 0 { rBatch = r.Rows() @@ -2941,7 +2941,7 @@ func TestUnsignedPartitionColumn(t *testing.T) { for tid, tbl := range []string{"tnormal_uniq", "trange_uniq", "thash_uniq"} { // unsigned + IndexReader scanSQL := fmt.Sprintf("select a from %v use index(a) where %v", tbl, scanCond) - require.True(t, tk.HasPlan(scanSQL, "IndexReader")) + tk.MustHavePlan(scanSQL, "IndexReader") r := tk.MustQuery(scanSQL).Sort() if tid == 0 { rScan = r.Rows() @@ -2971,7 +2971,7 @@ func TestUnsignedPartitionColumn(t *testing.T) { // unsigned + BatchGet on UniqueIndex batchSQL := fmt.Sprintf("select * from %v where %v", tbl, batchCond) - require.True(t, tk.HasPlan(batchSQL, "Batch_Point_Get")) + tk.MustHavePlan(batchSQL, "Batch_Point_Get") r = tk.MustQuery(batchSQL).Sort() if tid == 0 { rBatch = r.Rows() @@ -3038,12 +3038,12 @@ func TestDirectReadingWithAgg(t *testing.T) { queryPartition1 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from trange where a > %v group by a;", x) queryRegular1 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tregular1 where a > %v group by a;", x) - require.True(t, tk.HasPlan(queryPartition1, "StreamAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition1, "StreamAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition1).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryPartition2 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from trange where a > %v group by a;", x) queryRegular2 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tregular1 where a > %v group by a;", x) - require.True(t, tk.HasPlan(queryPartition2, "HashAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition2, "HashAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition2).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) y := rand.Intn(1099) @@ -3051,12 +3051,12 @@ func TestDirectReadingWithAgg(t *testing.T) { queryPartition3 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from trange where a in(%v, %v, %v) group by a;", x, y, z) queryRegular3 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tregular1 where a in(%v, %v, %v) group by a;", x, y, z) - require.True(t, tk.HasPlan(queryPartition3, "StreamAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition3, "StreamAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition3).Sort().Check(tk.MustQuery(queryRegular3).Sort().Rows()) queryPartition4 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from trange where a in (%v, %v, %v) group by a;", x, y, z) queryRegular4 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tregular1 where a in (%v, %v, %v) group by a;", x, y, z) - require.True(t, tk.HasPlan(queryPartition4, "HashAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition4, "HashAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition4).Sort().Check(tk.MustQuery(queryRegular4).Sort().Rows()) } @@ -3070,12 +3070,12 @@ func TestDirectReadingWithAgg(t *testing.T) { queryPartition1 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from thash where a > %v group by a;", x) queryRegular1 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tregular1 where a > %v group by a;", x) - require.True(t, tk.HasPlan(queryPartition1, "StreamAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition1, "StreamAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition1).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryPartition2 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from thash where a > %v group by a;", x) queryRegular2 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tregular1 where a > %v group by a;", x) - require.True(t, tk.HasPlan(queryPartition2, "HashAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition2, "HashAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition2).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) y := rand.Intn(1099) @@ -3083,12 +3083,12 @@ func TestDirectReadingWithAgg(t *testing.T) { queryPartition3 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from thash where a in(%v, %v, %v) group by a;", x, y, z) queryRegular3 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tregular1 where a in(%v, %v, %v) group by a;", x, y, z) - require.True(t, tk.HasPlan(queryPartition3, "StreamAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition3, "StreamAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition3).Sort().Check(tk.MustQuery(queryRegular3).Sort().Rows()) queryPartition4 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from thash where a in (%v, %v, %v) group by a;", x, y, z) queryRegular4 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tregular1 where a in (%v, %v, %v) group by a;", x, y, z) - require.True(t, tk.HasPlan(queryPartition4, "HashAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition4, "HashAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition4).Sort().Check(tk.MustQuery(queryRegular4).Sort().Rows()) } @@ -3102,12 +3102,12 @@ func TestDirectReadingWithAgg(t *testing.T) { queryPartition1 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tlist where a > %v group by a;", x) queryRegular1 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tregular2 where a > %v group by a;", x) - require.True(t, tk.HasPlan(queryPartition1, "StreamAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition1, "StreamAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition1).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryPartition2 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tlist where a > %v group by a;", x) queryRegular2 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tregular2 where a > %v group by a;", x) - require.True(t, tk.HasPlan(queryPartition2, "HashAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition2, "HashAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition2).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) y := rand.Intn(12) + 1 @@ -3115,12 +3115,12 @@ func TestDirectReadingWithAgg(t *testing.T) { queryPartition3 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tlist where a in(%v, %v, %v) group by a;", x, y, z) queryRegular3 := fmt.Sprintf("select /*+ stream_agg() */ count(*), sum(b), max(b), a from tregular2 where a in(%v, %v, %v) group by a;", x, y, z) - require.True(t, tk.HasPlan(queryPartition3, "StreamAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition3, "StreamAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition3).Sort().Check(tk.MustQuery(queryRegular3).Sort().Rows()) queryPartition4 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tlist where a in (%v, %v, %v) group by a;", x, y, z) queryRegular4 := fmt.Sprintf("select /*+ hash_agg() */ count(*), sum(b), max(b), a from tregular2 where a in (%v, %v, %v) group by a;", x, y, z) - require.True(t, tk.HasPlan(queryPartition4, "HashAgg")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition4, "HashAgg") // check if IndexLookUp is used tk.MustQuery(queryPartition4).Sort().Check(tk.MustQuery(queryRegular4).Sort().Rows()) } } @@ -3242,12 +3242,12 @@ func TestIdexMerge(t *testing.T) { queryPartition1 := fmt.Sprintf("select /*+ use_index_merge(trange) */ * from trange where a > %v or b < %v;", x1, x2) queryRegular1 := fmt.Sprintf("select /*+ use_index_merge(tregular1) */ * from tregular1 where a > %v or b < %v;", x1, x2) - require.True(t, tk.HasPlan(queryPartition1, "IndexMerge")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition1, "IndexMerge") // check if IndexLookUp is used tk.MustQuery(queryPartition1).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryPartition2 := fmt.Sprintf("select /*+ use_index_merge(trange) */ * from trange where a > %v or b > %v;", x1, x2) queryRegular2 := fmt.Sprintf("select /*+ use_index_merge(tregular1) */ * from tregular1 where a > %v or b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryPartition2, "IndexMerge")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition2, "IndexMerge") // check if IndexLookUp is used tk.MustQuery(queryPartition2).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) } @@ -3258,12 +3258,12 @@ func TestIdexMerge(t *testing.T) { queryPartition1 := fmt.Sprintf("select /*+ use_index_merge(thash) */ * from thash where a > %v or b < %v;", x1, x2) queryRegular1 := fmt.Sprintf("select /*+ use_index_merge(tregualr1) */ * from tregular1 where a > %v or b < %v;", x1, x2) - require.True(t, tk.HasPlan(queryPartition1, "IndexMerge")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition1, "IndexMerge") // check if IndexLookUp is used tk.MustQuery(queryPartition1).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryPartition2 := fmt.Sprintf("select /*+ use_index_merge(thash) */ * from thash where a > %v or b > %v;", x1, x2) queryRegular2 := fmt.Sprintf("select /*+ use_index_merge(tregular1) */ * from tregular1 where a > %v or b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryPartition2, "IndexMerge")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition2, "IndexMerge") // check if IndexLookUp is used tk.MustQuery(queryPartition2).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) } @@ -3273,12 +3273,12 @@ func TestIdexMerge(t *testing.T) { x2 := rand.Intn(12) + 1 queryPartition1 := fmt.Sprintf("select /*+ use_index_merge(tlist) */ * from tlist where a > %v or b < %v;", x1, x2) queryRegular1 := fmt.Sprintf("select /*+ use_index_merge(tregular2) */ * from tregular2 where a > %v or b < %v;", x1, x2) - require.True(t, tk.HasPlan(queryPartition1, "IndexMerge")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition1, "IndexMerge") // check if IndexLookUp is used tk.MustQuery(queryPartition1).Sort().Check(tk.MustQuery(queryRegular1).Sort().Rows()) queryPartition2 := fmt.Sprintf("select /*+ use_index_merge(tlist) */ * from tlist where a > %v or b > %v;", x1, x2) queryRegular2 := fmt.Sprintf("select /*+ use_index_merge(tregular2) */ * from tregular2 where a > %v or b > %v;", x1, x2) - require.True(t, tk.HasPlan(queryPartition2, "IndexMerge")) // check if IndexLookUp is used + tk.MustHavePlan(queryPartition2, "IndexMerge") // check if IndexLookUp is used tk.MustQuery(queryPartition2).Sort().Check(tk.MustQuery(queryRegular2).Sort().Rows()) } } diff --git a/executor/point_get_test.go b/executor/point_get_test.go index 8f13675457481..3c273ac202bda 100644 --- a/executor/point_get_test.go +++ b/executor/point_get_test.go @@ -147,7 +147,7 @@ func TestIssue25489(t *testing.T) { PARTITION PMX VALUES LESS THAN (MAXVALUE) ) ;`) query := "select col1, col2 from UK_RP16939 where col1 in (116, 48, -30);" - require.False(t, tk.HasPlan(query, "Batch_Point_Get")) + tk.MustNotHavePlan(query, "Batch_Point_Get") tk.MustQuery(query).Check(testkit.Rows()) tk.MustExec("drop table if exists UK_RP16939;") @@ -165,7 +165,7 @@ func TestIssue25489(t *testing.T) { PARTITION P1 VALUES IN (-22, 63), PARTITION P2 VALUES IN (75, 90) ) ;`) - require.False(t, tk.HasPlan(query, "Batch_Point_Get")) + tk.MustNotHavePlan(query, "Batch_Point_Get") tk.MustQuery(query).Check(testkit.Rows()) tk.MustExec("drop table if exists UK_RP16939;") } diff --git a/executor/sample_test.go b/executor/sample_test.go index 19183c235fcc2..2dd347534924d 100644 --- a/executor/sample_test.go +++ b/executor/sample_test.go @@ -51,7 +51,7 @@ func TestTableSampleBasic(t *testing.T) { tk.MustExec("alter table t add column c int as (a + 1);") tk.MustQuery("select c from t tablesample regions();").Check(testkit.Rows("1")) tk.MustQuery("select c, _tidb_rowid from t tablesample regions();").Check(testkit.Rows("1 1")) - require.True(t, tk.HasPlan("select * from t tablesample regions();", "TableSample")) + tk.MustHavePlan("select * from t tablesample regions();", "TableSample") tk.MustExec("drop table if exists t;") tk.MustExec("create table t(a BIGINT PRIMARY KEY AUTO_RANDOM(3), b int auto_increment, key(b)) pre_split_regions=8;") diff --git a/executor/temporary_table_test.go b/executor/temporary_table_test.go index 5174a91976a21..43ca00905690e 100644 --- a/executor/temporary_table_test.go +++ b/executor/temporary_table_test.go @@ -111,23 +111,23 @@ func assertTemporaryTableNoNetwork(t *testing.T, createTable func(*testkit.TestK // Check the temporary table do not send request to TiKV. // PointGet - require.True(t, tk.HasPlan("select * from tmp_t where id=1", "Point_Get")) + tk.MustHavePlan("select * from tmp_t where id=1", "Point_Get") tk.MustQuery("select * from tmp_t where id=1").Check(testkit.Rows("1 1 1")) // BatchPointGet - require.True(t, tk.HasPlan("select * from tmp_t where id in (1, 2)", "Batch_Point_Get")) + tk.MustHavePlan("select * from tmp_t where id in (1, 2)", "Batch_Point_Get") tk.MustQuery("select * from tmp_t where id in (1, 2)").Check(testkit.Rows("1 1 1", "2 2 2")) // Table reader - require.True(t, tk.HasPlan("select * from tmp_t", "TableReader")) + tk.MustHavePlan("select * from tmp_t", "TableReader") tk.MustQuery("select * from tmp_t").Check(testkit.Rows("1 1 1", "2 2 2")) // Index reader - require.True(t, tk.HasPlan("select /*+ USE_INDEX(tmp_t, a) */ a from tmp_t", "IndexReader")) + tk.MustHavePlan("select /*+ USE_INDEX(tmp_t, a) */ a from tmp_t", "IndexReader") tk.MustQuery("select /*+ USE_INDEX(tmp_t, a) */ a from tmp_t").Check(testkit.Rows("1", "2")) // Index lookup - require.True(t, tk.HasPlan("select /*+ USE_INDEX(tmp_t, a) */ b from tmp_t where a = 1", "IndexLookUp")) + tk.MustHavePlan("select /*+ USE_INDEX(tmp_t, a) */ b from tmp_t where a = 1", "IndexLookUp") tk.MustQuery("select /*+ USE_INDEX(tmp_t, a) */ b from tmp_t where a = 1").Check(testkit.Rows("1")) tk.MustExec("rollback") diff --git a/executor/test/indexmergereadtest/index_merge_reader_test.go b/executor/test/indexmergereadtest/index_merge_reader_test.go index 6e37c7e6920b9..53930ab8a7d4d 100644 --- a/executor/test/indexmergereadtest/index_merge_reader_test.go +++ b/executor/test/indexmergereadtest/index_merge_reader_test.go @@ -1072,44 +1072,44 @@ func TestOrderByWithLimit(t *testing.T) { limit := rand.Intn(10) + 1 queryHandle := fmt.Sprintf("select /*+ use_index_merge(thandle, idx_ac, idx_bc) */ * from thandle where a = %v or b = %v order by c limit %v", a, b, limit) resHandle := tk.MustQuery(queryHandle).Rows() - require.True(t, tk.HasPlan(queryHandle, "IndexMerge")) - require.False(t, tk.HasPlan(queryHandle, "TopN")) + tk.MustHavePlan(queryHandle, "IndexMerge") + tk.MustNotHavePlan(queryHandle, "TopN") queryPK := fmt.Sprintf("select /*+ use_index_merge(tpk, idx_ac, idx_bc) */ * from tpk where a = %v or b = %v order by c limit %v", a, b, limit) resPK := tk.MustQuery(queryPK).Rows() - require.True(t, tk.HasPlan(queryPK, "IndexMerge")) - require.False(t, tk.HasPlan(queryPK, "TopN")) + tk.MustHavePlan(queryPK, "IndexMerge") + tk.MustNotHavePlan(queryPK, "TopN") queryCommon := fmt.Sprintf("select /*+ use_index_merge(tcommon, idx_ac, idx_bc) */ * from tcommon where a = %v or b = %v order by c limit %v", a, b, limit) resCommon := tk.MustQuery(queryCommon).Rows() - require.True(t, tk.HasPlan(queryCommon, "IndexMerge")) - require.False(t, tk.HasPlan(queryCommon, "TopN")) + tk.MustHavePlan(queryCommon, "IndexMerge") + tk.MustNotHavePlan(queryCommon, "TopN") queryTableScan := fmt.Sprintf("select /*+ use_index_merge(tcommon, primary, idx_bc) */ * from tcommon where a = %v or b = %v order by c limit %v", a, b, limit) resTableScan := tk.MustQuery(queryTableScan).Rows() - require.True(t, tk.HasPlan(queryTableScan, "IndexMerge")) - require.True(t, tk.HasPlan(queryTableScan, "TableRangeScan")) - require.False(t, tk.HasPlan(queryTableScan, "TopN")) + tk.MustHavePlan(queryTableScan, "IndexMerge") + tk.MustHavePlan(queryTableScan, "TableRangeScan") + tk.MustNotHavePlan(queryTableScan, "TopN") queryHash := fmt.Sprintf("select /*+ use_index_merge(thash, idx_ac, idx_bc) */ * from thash where a = %v or b = %v order by c limit %v", a, b, limit) resHash := tk.MustQuery(queryHash).Rows() - require.True(t, tk.HasPlan(queryHash, "IndexMerge")) + tk.MustHavePlan(queryHash, "IndexMerge") if i%2 == 1 { - require.False(t, tk.HasPlan(queryHash, "TopN")) + tk.MustNotHavePlan(queryHash, "TopN") } queryCommonHash := fmt.Sprintf("select /*+ use_index_merge(tcommonhash, primary, idx_bc) */ * from tcommonhash where a = %v or b = %v order by c limit %v", a, b, limit) resCommonHash := tk.MustQuery(queryCommonHash).Rows() - require.True(t, tk.HasPlan(queryCommonHash, "IndexMerge")) + tk.MustHavePlan(queryCommonHash, "IndexMerge") if i%2 == 1 { - require.False(t, tk.HasPlan(queryCommonHash, "TopN")) + tk.MustNotHavePlan(queryCommonHash, "TopN") } queryPKHash := fmt.Sprintf("select /*+ use_index_merge(tpkhash, idx_ac, idx_bc) */ * from tpkhash where a = %v or b = %v order by c limit %v", a, b, limit) resPKHash := tk.MustQuery(queryPKHash).Rows() - require.True(t, tk.HasPlan(queryPKHash, "IndexMerge")) + tk.MustHavePlan(queryPKHash, "IndexMerge") if i%2 == 1 { - require.False(t, tk.HasPlan(queryPKHash, "TopN")) + tk.MustNotHavePlan(queryPKHash, "TopN") } sliceRes := getResult(valueSlice, a, b, limit, false) @@ -1205,9 +1205,9 @@ func TestIndexMergeLimitPushedAsIntersectionEmbeddedLimit(t *testing.T) { valA, valB, valC, limit := rand.Intn(100), rand.Intn(100), rand.Intn(50), rand.Intn(100)+1 queryTableScan := fmt.Sprintf("select * from t use index() where a > %d and b > %d and c >= %d limit %d", valA, valB, valC, limit) queryWithIndexMerge := fmt.Sprintf("select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a > %d and b > %d and c >= %d limit %d", valA, valB, valC, limit) - require.True(t, tk.HasPlan(queryWithIndexMerge, "IndexMerge")) + tk.MustHavePlan(queryWithIndexMerge, "IndexMerge") require.True(t, tk.HasKeywordInOperatorInfo(queryWithIndexMerge, "limit embedded")) - require.True(t, tk.HasPlan(queryTableScan, "TableFullScan")) + tk.MustHavePlan(queryTableScan, "TableFullScan") // index merge with embedded limit couldn't compare the exactly results with normal plan, because limit admission control has some difference, while we can only check // the row count is exactly the same with tableFullScan plan, in case of index pushedLimit and table pushedLimit cut down the source table rows. require.Equal(t, len(tk.MustQuery(queryWithIndexMerge).Rows()), len(tk.MustQuery(queryTableScan).Rows())) @@ -1232,8 +1232,8 @@ func TestIndexMergeLimitNotPushedOnPartialSideButKeepOrder(t *testing.T) { maxEle := tk.MustQuery(fmt.Sprintf("select ifnull(max(c), 100) from (select c from t use index(idx3) where (a = %d or b = %d) and c >= %d order by c limit %d) t", valA, valB, valC, limit)).Rows()[0][0] queryWithIndexMerge := fmt.Sprintf("select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where (a = %d or b = %d) and c >= %d and c < greatest(%d, %v) order by c limit %d", valA, valB, valC, valC+1, maxEle, limit) queryWithNormalIndex := fmt.Sprintf("select * from t use index(idx3) where (a = %d or b = %d) and c >= %d and c < greatest(%d, %v) order by c limit %d", valA, valB, valC, valC+1, maxEle, limit) - require.True(t, tk.HasPlan(queryWithIndexMerge, "IndexMerge")) - require.True(t, tk.HasPlan(queryWithIndexMerge, "Limit")) + tk.MustHavePlan(queryWithIndexMerge, "IndexMerge") + tk.MustHavePlan(queryWithIndexMerge, "Limit") normalResult := tk.MustQuery(queryWithNormalIndex).Sort().Rows() tk.MustQuery(queryWithIndexMerge).Sort().Check(normalResult) } @@ -1242,8 +1242,8 @@ func TestIndexMergeLimitNotPushedOnPartialSideButKeepOrder(t *testing.T) { maxEle := tk.MustQuery(fmt.Sprintf("select ifnull(max(c), 100) from (select c from t use index(idx3) where (a = %d or b = %d) and c >= %d order by c limit %d offset %d) t", valA, valB, valC, limit, offset)).Rows()[0][0] queryWithIndexMerge := fmt.Sprintf("select /*+ USE_INDEX_MERGE(t, idx, idx2) */ c from t where (a = %d or b = %d) and c >= %d and c < greatest(%d, %v) order by c limit %d offset %d", valA, valB, valC, valC+1, maxEle, limit, offset) queryWithNormalIndex := fmt.Sprintf("select c from t use index(idx3) where (a = %d or b = %d) and c >= %d and c < greatest(%d, %v) order by c limit %d offset %d", valA, valB, valC, valC+1, maxEle, limit, offset) - require.True(t, tk.HasPlan(queryWithIndexMerge, "IndexMerge")) - require.True(t, tk.HasPlan(queryWithIndexMerge, "Limit")) + tk.MustHavePlan(queryWithIndexMerge, "IndexMerge") + tk.MustHavePlan(queryWithIndexMerge, "Limit") normalResult := tk.MustQuery(queryWithNormalIndex).Sort().Rows() tk.MustQuery(queryWithIndexMerge).Sort().Check(normalResult) } @@ -1256,8 +1256,8 @@ func TestIndexMergeNoOrderLimitPushed(t *testing.T) { tk.MustExec("create table t(a int, b int, c int, index idx(a, c), index idx2(b, c))") tk.MustExec("insert into t values(1, 1, 1), (2, 2, 2)") sql := "select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1" - require.True(t, tk.HasPlan(sql, "IndexMerge")) - require.True(t, tk.HasPlan(sql, "Limit")) + tk.MustHavePlan(sql, "IndexMerge") + tk.MustHavePlan(sql, "Limit") // 6 means that IndexMerge(embedded limit){Limit->PartialIndexScan, Limit->PartialIndexScan, FinalTableScan} require.Equal(t, 6, len(tk.MustQuery("explain "+sql).Rows())) // The result is not stable. So we just check that it can run successfully. @@ -1273,15 +1273,15 @@ func TestIndexMergeKeepOrderDirtyRead(t *testing.T) { tk.MustExec("begin") tk.MustExec("insert into t values(1, 1, -3)") querySQL := "select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2" - tk.HasPlan(querySQL, "Limit") - tk.HasPlan(querySQL, "IndexMerge") + tk.MustHavePlan(querySQL, "Limit") + tk.MustHavePlan(querySQL, "IndexMerge") tk.MustQuery(querySQL).Check(testkit.Rows("1 1 -3", "2 1 -2")) tk.MustExec("rollback") tk.MustExec("begin") tk.MustExec("insert into t values(1, 2, 4)") querySQL = "select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2" - tk.HasPlan(querySQL, "Limit") - tk.HasPlan(querySQL, "IndexMerge") + tk.MustHavePlan(querySQL, "Limit") + tk.MustHavePlan(querySQL, "IndexMerge") tk.MustQuery(querySQL).Check(testkit.Rows("1 2 4", "1 1 1")) tk.MustExec("rollback") } diff --git a/executor/test/tiflashtest/tiflash_test.go b/executor/test/tiflashtest/tiflash_test.go index bfc8d1caf8ff2..0615208314125 100644 --- a/executor/test/tiflashtest/tiflash_test.go +++ b/executor/test/tiflashtest/tiflash_test.go @@ -990,7 +990,7 @@ func TestTiFlashPartitionTableShuffledHashAggregation(t *testing.T) { tk.MustExec(fmt.Sprintf("set @@tidb_partition_prune_mode = '%v'", mode)) for _, tbl := range []string{`thash`, `trange`, `tlist`, `tnormal`} { q := fmt.Sprintf("select /*+ HASH_AGG() */ count(*) from %v t1 where %v", tbl, cond) - require.True(t, tk.HasPlan(q, "HashAgg")) + tk.MustHavePlan(q, "HashAgg") if res == nil { res = tk.MustQuery(q).Sort().Rows() } else { diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go index efe5d1562e97f..a4b7932b49b13 100644 --- a/executor/union_scan_test.go +++ b/executor/union_scan_test.go @@ -531,29 +531,22 @@ func TestIssue32422(t *testing.T) { tk.MustQuery("select id+1, c from t where c = 4;").Check(testkit.Rows("5 4")) tk.MustExec("insert into t values (6, 6)") // Check for the new added data. - tk.HasPlan("select id+1, c from t where c = 6;", "UnionScan") + tk.MustHavePlan("select id+1, c from t where c = 6;", "UnionScan") tk.MustQuery("select id+1, c from t where c = 6;").Check(testkit.Rows("7 6")) require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) // Check for the old data. tk.MustQuery("select id+1, c from t where c = 4;").Check(testkit.Rows("5 4")) require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) - // Point get - tk.HasPlan("select id+1, c from t where id = 6", "PointGet") - tk.MustQuery("select id+1, c from t where id = 6").Check(testkit.Rows("7 6")) - require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) - tk.MustQuery("select id+1, c from t where id = 4").Check(testkit.Rows("5 4")) - require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) - // Index Lookup - tk.HasPlan("select id+1, c from t where id = 6", "IndexLookUp") + tk.MustHavePlan("select id+1, c from t where id = 6", "IndexLookUp") tk.MustQuery("select id+1, c from t use index(id) where id = 6").Check(testkit.Rows("7 6")) require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) tk.MustQuery("select id+1, c from t use index(id) where id = 4").Check(testkit.Rows("5 4")) require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) // Index Reader - tk.HasPlan("select id from t where id = 6", "IndexReader") + tk.MustHavePlan("select id from t where id = 6", "IndexReader") tk.MustQuery("select id from t use index(id) where id = 6").Check(testkit.Rows("6")) require.True(t, tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache) tk.MustQuery("select id from t use index(id) where id = 4").Check(testkit.Rows("4")) @@ -624,7 +617,7 @@ func BenchmarkUnionScanIndexReadDescRead(b *testing.B) { tk.MustExec(fmt.Sprintf("insert into t values (%d, %d, %d)", i, i, i)) } - tk.HasPlan("select b from t use index(k) where b > 50 order by b desc", "IndexReader") + tk.MustHavePlan("select b from t use index(k) where b > 50 order by b desc", "IndexReader") b.ReportAllocs() b.ResetTimer() @@ -646,7 +639,7 @@ func BenchmarkUnionScanTableReadDescRead(b *testing.B) { tk.MustExec(fmt.Sprintf("insert into t values (%d, %d, %d)", i, i, i)) } - tk.HasPlan("select * from t where a > 50 order by a desc", "TableReader") + tk.MustHavePlan("select * from t where a > 50 order by a desc", "TableReader") b.ReportAllocs() b.ResetTimer() @@ -668,7 +661,7 @@ func BenchmarkUnionScanIndexLookUpDescRead(b *testing.B) { tk.MustExec(fmt.Sprintf("insert into t values (%d, %d, %d)", i, i, i)) } - tk.HasPlan("select * from t use index(k) where b > 50 order by b desc", "IndexLookUp") + tk.MustHavePlan("select * from t use index(k) where b > 50 order by b desc", "IndexLookUp") b.ReportAllocs() b.ResetTimer() diff --git a/planner/core/casetest/integration_test.go b/planner/core/casetest/integration_test.go index 08738026534fd..b920db766729f 100644 --- a/planner/core/casetest/integration_test.go +++ b/planner/core/casetest/integration_test.go @@ -1230,16 +1230,16 @@ func TestFixControl45132(t *testing.T) { } tk.MustExec(`analyze table t`) // the cost model prefers to use TableScan instead of IndexLookup to avoid double requests. - require.True(t, tk.HasPlan(`select * from t where a=2`, `TableFullScan`)) + tk.MustHavePlan(`select * from t where a=2`, `TableFullScan`) tk.MustExec(`set @@tidb_opt_fix_control = "45132:99"`) tk.MustIndexLookup(`select * from t where a=2`) // index lookup tk.MustExec(`set @@tidb_opt_fix_control = "45132:500"`) - require.True(t, tk.HasPlan(`select * from t where a=2`, `TableFullScan`)) + tk.MustHavePlan(`select * from t where a=2`, `TableFullScan`) tk.MustExec(`set @@tidb_opt_fix_control = "45132:0"`) - require.True(t, tk.HasPlan(`select * from t where a=2`, `TableFullScan`)) + tk.MustHavePlan(`select * from t where a=2`, `TableFullScan`) } func TestFixControl44262(t *testing.T) { diff --git a/planner/core/indexmerge_intersection_test.go b/planner/core/indexmerge_intersection_test.go index 8b352f3b5cead..9ed4bbe86658f 100644 --- a/planner/core/indexmerge_intersection_test.go +++ b/planner/core/indexmerge_intersection_test.go @@ -30,19 +30,15 @@ func TestSPMForIntersectionIndexMerge(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int, c int, d int, e int, index ia(a), index ib(b), index ic(c), index id(d), index ie(e))") - require.False(t, tk.HasPlan("select * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100)", "IndexMerge")) - require.True(t, - tk.HasPlan("select /*+ use_index_merge(t, ia, ib, ic, id, ie) */ * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100)", - "IndexMerge", - ), - ) + tk.MustNotHavePlan("select * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100)", "IndexMerge") + tk.MustHavePlan("select /*+ use_index_merge(t, ia, ib, ic, id, ie) */ * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100)", "IndexMerge") tk.MustExec(` create global binding for select * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100) using select /*+ use_index_merge(t, ia, ib, ic, id, ie) */ * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100) `) - require.True(t, tk.HasPlan("select * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100)", "IndexMerge")) + tk.MustHavePlan("select * from t where a = 10 and b = 20 and c > 30 and d is null and e in (0, 100)", "IndexMerge") } func TestPlanCacheForIntersectionIndexMerge(t *testing.T) { diff --git a/planner/core/integration_partition_test.go b/planner/core/integration_partition_test.go index 881e04bc8af4a..f2d30d9a11cfe 100644 --- a/planner/core/integration_partition_test.go +++ b/planner/core/integration_partition_test.go @@ -636,11 +636,11 @@ func TestListPartitionInvisibleIdx(t *testing.T) { tk.MustExec(`create table tlist (a int, b int, key(a)) partition by list (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5))`) tk.MustExec(`alter table tlist alter index a invisible`) - tk.HasPlan(`select a from tlist where a>=0 and a<=5`, "TableFullScan") + tk.MustHavePlan(`select a from tlist where a>=0 and a<=5`, "TableFullScan") tk.MustExec(`create table tcollist (a int, b int, key(a)) partition by list columns (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5))`) tk.MustExec(`alter table tcollist alter index a invisible`) - tk.HasPlan(`select a from tcollist where a>=0 and a<=5`, "TableFullScan") + tk.MustHavePlan(`select a from tcollist where a>=0 and a<=5`, "TableFullScan") } func TestListPartitionCTE(t *testing.T) { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b5fc2c7a06591..78b1e487db705 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -903,14 +903,6 @@ func TestIndexMergePartialScansClusteredIndex(t *testing.T) { condition string expected []string }{ - { - // 3 table scans - "a < 2 or a < 10 or a > 11", []string{"1", "100"}, - }, - { - // 3 index scans - "c < 10 or c < 11 or c > 50", []string{"1", "10", "100"}, - }, { // 1 table scan + 1 index scan "a < 2 or c > 10000", []string{"1"}, @@ -931,7 +923,7 @@ func TestIndexMergePartialScansClusteredIndex(t *testing.T) { for _, p := range projections { for _, ca := range cases { query := fmt.Sprintf(queryTemplate, strings.Join(p, ","), ca.condition) - tk.HasPlan(query, "IndexMerge") + tk.MustHavePlan(query, "IndexMerge") expected := make([]string, 0, len(ca.expected)) for _, datum := range ca.expected { row := strings.Repeat(datum+" ", len(p)) @@ -956,10 +948,6 @@ func TestIndexMergePartialScansTiDBRowID(t *testing.T) { condition string expected []string }{ - { - // 3 index scans - "c < 10 or c < 11 or c > 50", []string{"1", "10", "100"}, - }, { // 2 index scans "c < 10 or a < 2", []string{"1"}, @@ -984,7 +972,7 @@ func TestIndexMergePartialScansTiDBRowID(t *testing.T) { for _, p := range projections { for _, ca := range cases { query := fmt.Sprintf(queryTemplate, strings.Join(p, ","), ca.condition) - tk.HasPlan(query, "IndexMerge") + tk.MustHavePlan(query, "IndexMerge") expected := make([]string, 0, len(ca.expected)) for _, datum := range ca.expected { row := strings.Repeat(datum+" ", len(p)) @@ -1033,7 +1021,7 @@ func TestIndexMergePartialScansPKIsHandle(t *testing.T) { for _, p := range projections { for _, ca := range cases { query := fmt.Sprintf(queryTemplate, strings.Join(p, ","), ca.condition) - tk.HasPlan(query, "IndexMerge") + tk.MustHavePlan(query, "IndexMerge") expected := make([]string, 0, len(ca.expected)) for _, datum := range ca.expected { row := strings.Repeat(datum+" ", len(p)) @@ -2188,7 +2176,7 @@ func TestQueryBlockTableAliasInHint(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - require.True(t, tk.HasPlan("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2", "HashJoin")) + tk.MustHavePlan("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2", "HashJoin") tk.MustQuery("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2").Check(testkit.Rows( "1 2", )) @@ -2917,7 +2905,7 @@ func TestIssue25799(t *testing.T) { tk.MustExec(`insert into t1 values (1, 1)`) tk.MustExec(`create table t2 (a float default null, b tinyint(4) DEFAULT NULL, key b (b))`) tk.MustExec(`insert into t2 values (null, 1)`) - tk.HasPlan(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`, `IndexJoin`) + tk.MustHavePlan(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`, `IndexJoin`) tk.MustQuery(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`).Check(testkit.Rows()) } diff --git a/planner/core/issuetest/planner_issue_test.go b/planner/core/issuetest/planner_issue_test.go index b47d826b58301..58ce55a948949 100644 --- a/planner/core/issuetest/planner_issue_test.go +++ b/planner/core/issuetest/planner_issue_test.go @@ -205,7 +205,7 @@ func TestIssue46005(t *testing.T) { tk.MustExec("use test") tk.MustExec("create table tbl_39(col_239 year(4) not null default '2009', primary key(col_239), unique key idx_223(col_239), key idx_224(col_239))") tk.MustExec("insert into tbl_39 values (1994),(1995),(1996),(1997)") - tk.HasPlan( + tk.MustHavePlan( "select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382", "IndexMerge", ) diff --git a/session/clusteredindextest/clustered_index_test.go b/session/clusteredindextest/clustered_index_test.go index 4b251d0d25671..1e04cc9d0ed47 100644 --- a/session/clusteredindextest/clustered_index_test.go +++ b/session/clusteredindextest/clustered_index_test.go @@ -143,7 +143,7 @@ func TestClusteredUnionScanIndexLookup(t *testing.T) { tk.MustExec("begin") tk.MustExec("update t set a = a + 1, pk = '222' where a = 1;") sql := "select pk, c from t where a = 2;" - tk.HasPlan(sql, "IndexLookUp") + tk.MustHavePlan(sql, "IndexLookUp") tk.MustQuery(sql).Check(testkit.Rows("222 3")) tk.MustExec("commit") @@ -258,8 +258,8 @@ func TestClusteredPrefixingPrimaryKey(t *testing.T) { tk.MustGetErrCode("insert into t(name, b) values('aaa', 3);", errno.ErrDupEntry) sql := "select * from t use index(primary) where name = 'aaaaa';" - tk.HasPlan(sql, "TableReader") - tk.HasPlan(sql, "TableRangeScan") + tk.MustHavePlan(sql, "TableReader") + tk.MustHavePlan(sql, "TableRangeScan") tk.MustQuery(sql).Check(testkit.Rows("aaaaa 1 ")) tk.MustExec("admin check table t;") diff --git a/sessionctx/sessionstates/session_states_test.go b/sessionctx/sessionstates/session_states_test.go index 87576f0630d36..e3eaf89dd3ef9 100644 --- a/sessionctx/sessionstates/session_states_test.go +++ b/sessionctx/sessionstates/session_states_test.go @@ -1225,7 +1225,7 @@ func TestSQLBinding(t *testing.T) { }, checkFunc: func(tk *testkit.TestKit, param any) { tk.MustQuery("show session bindings").Check(param.([][]any)) - require.True(t, tk.HasPlan("select * from test.t1", "IndexFullScan")) + tk.MustHavePlan("select * from test.t1", "IndexFullScan") tk.MustExec("drop session binding for select * from test.t1") tk.MustQuery("show session bindings").Check(testkit.Rows()) }, @@ -1240,7 +1240,7 @@ func TestSQLBinding(t *testing.T) { }, checkFunc: func(tk *testkit.TestKit, param any) { tk.MustQuery("show session bindings").Check(param.([][]any)) - require.True(t, tk.HasPlan("select * from test.t1", "IndexFullScan")) + tk.MustHavePlan("select * from test.t1", "IndexFullScan") tk.MustExec("drop session binding for select * from test.t1") tk.MustQuery("show session bindings").Check(testkit.Rows()) }, @@ -1268,7 +1268,7 @@ func TestSQLBinding(t *testing.T) { }, checkFunc: func(tk *testkit.TestKit, param any) { tk.MustQuery("show session bindings").Check(param.([][]any)) - require.True(t, tk.HasPlan("select * from test.t1", "IndexFullScan")) + tk.MustHavePlan("select * from test.t1", "IndexFullScan") }, }, { @@ -1322,9 +1322,9 @@ func TestSQLBinding(t *testing.T) { rows := param.([][][]any) tk.MustQuery("show bindings").Check(rows[0]) tk.MustQuery("show global bindings").Check(rows[1]) - require.True(t, tk.HasPlan("select * from test.t1", "IndexFullScan")) + tk.MustHavePlan("select * from test.t1", "IndexFullScan") tk.MustExec("drop session binding for select * from test.t1") - require.True(t, tk.HasPlan("select * from test.t1", "TableFullScan")) + tk.MustHavePlan("select * from test.t1", "TableFullScan") }, cleanFunc: func(tk *testkit.TestKit) { tk.MustExec("drop global binding for select * from test.t1") @@ -1342,7 +1342,7 @@ func TestSQLBinding(t *testing.T) { }, checkFunc: func(tk *testkit.TestKit, param any) { tk.MustQuery("show bindings").Check(param.([][]any)) - require.True(t, tk.HasPlan("select * from test.t1", "IndexFullScan")) + tk.MustHavePlan("select * from test.t1", "IndexFullScan") }, }, } diff --git a/table/tables/cache_test.go b/table/tables/cache_test.go index 2560ea834fefc..713a7760fa493 100644 --- a/table/tables/cache_test.go +++ b/table/tables/cache_test.go @@ -80,7 +80,6 @@ func TestCacheTableBasicScan(t *testing.T) { for i := 0; i < 10; i++ { tk.MustQuery("select * from join_t1 join join_t3").Check(testkit.Rows("1 3")) if lastReadFromCache(tk) { - // if tk.HasPlan("select *from join_t1 join join_t3", "UnionScan") { planUsed = true break } @@ -94,7 +93,6 @@ func TestCacheTableBasicScan(t *testing.T) { "10 110 1010", "12 112 1012", "14 114 1014", "16 116 1016", "18 118 1018", )) if lastReadFromCache(tk) { - // if tk.HasPlan("select * from tmp1 where id>4 order by id", "UnionScan") { planUsed = true break } diff --git a/testkit/testkit.go b/testkit/testkit.go index 3f492303293da..2564435f4cba4 100644 --- a/testkit/testkit.go +++ b/testkit/testkit.go @@ -178,7 +178,7 @@ func (tk *TestKit) MustQueryWithContext(ctx context.Context, sql string, args .. // MustIndexLookup checks whether the plan for the sql is IndexLookUp. func (tk *TestKit) MustIndexLookup(sql string, args ...interface{}) *Result { - tk.require.True(tk.HasPlan(sql, "IndexLookUp", args...)) + tk.MustHavePlan(sql, "IndexLookUp", args...) return tk.MustQuery(sql, args...) } @@ -243,15 +243,26 @@ func (tk *TestKit) ResultSetToResultWithCtx(ctx context.Context, rs sqlexec.Reco return &Result{rows: rows, comment: comment, assert: tk.assert, require: tk.require} } -// HasPlan checks if the result execution plan contains specific plan. -func (tk *TestKit) HasPlan(sql string, plan string, args ...interface{}) bool { +func (tk *TestKit) hasPlan(sql string, plan string, args ...interface{}) (bool, *Result) { rs := tk.MustQuery("explain "+sql, args...) for i := range rs.rows { if strings.Contains(rs.rows[i][0], plan) { - return true + return true, rs } } - return false + return false, rs +} + +// MustHavePlan checks if the result execution plan contains specific plan. +func (tk *TestKit) MustHavePlan(sql string, plan string, args ...interface{}) { + has, rs := tk.hasPlan(sql, plan, args...) + tk.require.True(has, fmt.Sprintf("%s doesn't have plan %s, full plan %v", sql, plan, rs.Rows())) +} + +// MustNotHavePlan checks if the result execution plan contains specific plan. +func (tk *TestKit) MustNotHavePlan(sql string, plan string, args ...interface{}) { + has, rs := tk.hasPlan(sql, plan, args...) + tk.require.False(has, fmt.Sprintf("%s shouldn't have plan %s, full plan %v", sql, plan, rs.Rows())) } // HasTiFlashPlan checks if the result execution plan contains TiFlash plan. diff --git a/tests/realtikvtest/sessiontest/session_fail_test.go b/tests/realtikvtest/sessiontest/session_fail_test.go index 8fcacc4df5f32..634aa85ec1b94 100644 --- a/tests/realtikvtest/sessiontest/session_fail_test.go +++ b/tests/realtikvtest/sessiontest/session_fail_test.go @@ -235,7 +235,7 @@ func TestIndexLookUpWithStaticPrune(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a bigint, b decimal(41,16), c set('a', 'b', 'c'), key idx_c(c)) partition by hash(a) partitions 4") tk.MustExec("insert into t values (1,2.0,'c')") - tk.HasPlan("select * from t use index(idx_c) order by c limit 5", "Limit") + tk.MustHavePlan("select * from t use index(idx_c) order by c limit 5", "Limit") tk.MustExec("select * from t use index(idx_c) order by c limit 5") } diff --git a/tests/realtikvtest/txntest/txn_test.go b/tests/realtikvtest/txntest/txn_test.go index 8aab7b7b7286f..babb64f33071c 100644 --- a/tests/realtikvtest/txntest/txn_test.go +++ b/tests/realtikvtest/txntest/txn_test.go @@ -263,7 +263,7 @@ func TestSelectLockForPartitionTable(t *testing.T) { tk1.MustExec("insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3)") tk1.MustExec("analyze table t") tk1.MustExec("begin") - tk1.HasPlan("select * from t use index(idx) where a = 1 and b = 1 order by a limit 1 for update", "IndexLookUp_9") + tk1.MustHavePlan("select * from t use index(idx) where a = 1 and b = 1 order by a limit 1 for update", "IndexLookUp") tk1.MustExec("select * from t use index(idx) where a = 1 and b = 1 order by a limit 1 for update") ch := make(chan bool, 1) go func() {