diff --git a/executor/executor_issue_test.go b/executor/executor_issue_test.go index f0b52422c19a2..5d2912f78f449 100644 --- a/executor/executor_issue_test.go +++ b/executor/executor_issue_test.go @@ -133,6 +133,7 @@ func TestIssue24210(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=1") // for ProjectionExec require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/mockProjectionExecBaseExecutorOpenReturnedError", `return(true)`)) @@ -579,6 +580,7 @@ func TestIssue30382(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("set @@session.tidb_enable_list_partition = ON;") tk.MustExec("drop table if exists t1, t2;") tk.MustExec("create table t1 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str(2)) , key(c_decimal) ) partition by list (c_int) ( partition p0 values IN (1, 5, 9, 13, 17, 21, 25, 29, 33, 37), partition p1 values IN (2, 6, 10, 14, 18, 22, 26, 30, 34, 38), partition p2 values IN (3, 7, 11, 15, 19, 23, 27, 31, 35, 39), partition p3 values IN (4, 8, 12, 16, 20, 24, 28, 32, 36, 40)) ;") @@ -596,7 +598,7 @@ func TestIssue30382(t *testing.T) { "SelectLock 6400.00 root for update 0", "└─HashJoin 6400.00 root CARTESIAN inner join, other cond:or(gt(Column#8, 1), or(ne(test.t1.c_str, Column#7), if(ne(Column#9, 0), NULL, 0)))", " ├─Selection(Build) 0.80 root ne(Column#10, 0)", - " │ └─StreamAgg 1.00 root funcs:max(Column#17)->Column#7, funcs:count(distinct Column#18)->Column#8, funcs:sum(Column#19)->Column#9, funcs:count(1)->Column#10", + " │ └─HashAgg 1.00 root funcs:max(Column#17)->Column#7, funcs:count(distinct Column#18)->Column#8, funcs:sum(Column#19)->Column#9, funcs:count(1)->Column#10", " │ └─Projection 3323.33 root test.t2.c_str, test.t2.c_str, cast(isnull(test.t2.c_str), decimal(20,0) BINARY)->Column#19", " │ └─TableReader 3323.33 root partition:all data:Selection", " │ └─Selection 3323.33 cop[tikv] lt(test.t2.c_decimal, 5)", diff --git a/executor/join_test.go b/executor/join_test.go index 9fd6d2c318818..be006d7dc0063 100644 --- a/executor/join_test.go +++ b/executor/join_test.go @@ -1412,6 +1412,7 @@ func TestIndexNestedLoopHashJoin(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("set @@tidb_init_chunk_size=2") tk.MustExec("set @@tidb_index_join_batch_size=10") tk.MustExec("DROP TABLE IF EXISTS t, s") @@ -1478,7 +1479,7 @@ func TestIndexNestedLoopHashJoin(t *testing.T) { " └─TableRowIDScan 27.00 cop[tikv] table:l2 keep order:false")) tk.MustQuery("select * from t l1 where exists ( select * from t l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey )order by `l_orderkey`,`l_linenumber`;").Check(testkit.Rows("0 0 0 0", "0 1 0 1", "0 2 0 0", "1 0 1 0", "1 1 1 1", "1 2 1 0", "2 0 0 0", "2 1 0 1", "2 2 0 0")) tk.MustQuery("desc format = 'brief' select count(*) from t l1 where exists ( select * from t l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey );").Check(testkit.Rows( - "StreamAgg 1.00 root funcs:count(1)->Column#11", + "HashAgg 1.00 root funcs:count(1)->Column#11", "└─IndexHashJoin 7.20 root semi join, inner:IndexLookUp, outer key:test.t.l_orderkey, inner key:test.t.l_orderkey, equal cond:eq(test.t.l_orderkey, test.t.l_orderkey), other cond:ne(test.t.l_suppkey, test.t.l_suppkey)", " ├─TableReader(Build) 9.00 root data:Selection", " │ └─Selection 9.00 cop[tikv] not(isnull(test.t.l_suppkey))", diff --git a/executor/oomtest/oom_test.go b/executor/oomtest/oom_test.go index 853b687f8c273..8a9f2c0263d76 100644 --- a/executor/oomtest/oom_test.go +++ b/executor/oomtest/oom_test.go @@ -137,6 +137,7 @@ func TestMemTracker4DeleteExec(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=1") tk.MustExec("create table MemTracker4DeleteExec1 (id int, a int, b int, index idx_a(`a`))") tk.MustExec("create table MemTracker4DeleteExec2 (id int, a int, b int, index idx_a(`a`))") diff --git a/executor/partition_table_test.go b/executor/partition_table_test.go index 39ac194311588..50bb68a7b5235 100644 --- a/executor/partition_table_test.go +++ b/executor/partition_table_test.go @@ -2115,6 +2115,7 @@ func TestParallelApply(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("create database test_parallel_apply") tk.MustExec("use test_parallel_apply") tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'") @@ -2149,9 +2150,9 @@ func TestParallelApply(t *testing.T) { `└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(10,0) BINARY), Column#7)`, ` ├─TableReader(Build) 10000.00 root data:TableFullScan`, ` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, - ` └─StreamAgg(Probe) 10000.00 root funcs:sum(Column#9)->Column#7`, - ` └─IndexReader 10000.00 root partition:all index:StreamAgg`, // IndexReader is a inner child of Apply - ` └─StreamAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.thash.a)->Column#9`, + ` └─HashAgg(Probe) 10000.00 root funcs:sum(Column#8)->Column#7`, + ` └─IndexReader 10000.00 root partition:all index:HashAgg`, // IndexReader is a inner child of Apply + ` └─HashAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.thash.a)->Column#8`, ` └─Selection 80000000.00 cop[tikv] gt(test_parallel_apply.thash.a, test_parallel_apply.touter.b)`, ` └─IndexFullScan 100000000.00 cop[tikv] table:thash, index:a(a) keep order:false, stats:pseudo`)) tk.MustQuery(`select * from touter where touter.a > (select sum(thash.a) from thash use index(a) where thash.a>touter.b)`).Sort().Check( @@ -2163,9 +2164,9 @@ func TestParallelApply(t *testing.T) { `└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(10,0) BINARY), Column#7)`, ` ├─TableReader(Build) 10000.00 root data:TableFullScan`, ` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, - ` └─StreamAgg(Probe) 10000.00 root funcs:sum(Column#9)->Column#7`, - ` └─TableReader 10000.00 root partition:all data:StreamAgg`, // TableReader is a inner child of Apply - ` └─StreamAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.thash.b)->Column#9`, + ` └─HashAgg(Probe) 10000.00 root funcs:sum(Column#8)->Column#7`, + ` └─TableReader 10000.00 root partition:all data:HashAgg`, // TableReader is a inner child of Apply + ` └─HashAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.thash.b)->Column#8`, ` └─Selection 80000000.00 cop[tikv] gt(test_parallel_apply.thash.a, test_parallel_apply.touter.b)`, ` └─TableFullScan 100000000.00 cop[tikv] table:thash keep order:false, stats:pseudo`)) tk.MustQuery(`select * from touter where touter.a > (select sum(thash.b) from thash ignore index(a) where thash.a>touter.b)`).Sort().Check( @@ -2192,9 +2193,9 @@ func TestParallelApply(t *testing.T) { `└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(10,0) BINARY), Column#7)`, ` ├─TableReader(Build) 10000.00 root data:TableFullScan`, ` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, - ` └─StreamAgg(Probe) 10000.00 root funcs:sum(Column#9)->Column#7`, - ` └─IndexReader 10000.00 root partition:all index:StreamAgg`, // IndexReader is a inner child of Apply - ` └─StreamAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.trange.a)->Column#9`, + ` └─HashAgg(Probe) 10000.00 root funcs:sum(Column#8)->Column#7`, + ` └─IndexReader 10000.00 root partition:all index:HashAgg`, // IndexReader is a inner child of Apply + ` └─HashAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.trange.a)->Column#8`, ` └─Selection 80000000.00 cop[tikv] gt(test_parallel_apply.trange.a, test_parallel_apply.touter.b)`, ` └─IndexFullScan 100000000.00 cop[tikv] table:trange, index:a(a) keep order:false, stats:pseudo`)) tk.MustQuery(`select * from touter where touter.a > (select sum(trange.a) from trange use index(a) where trange.a>touter.b)`).Sort().Check( @@ -2206,9 +2207,9 @@ func TestParallelApply(t *testing.T) { `└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(10,0) BINARY), Column#7)`, ` ├─TableReader(Build) 10000.00 root data:TableFullScan`, ` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, - ` └─StreamAgg(Probe) 10000.00 root funcs:sum(Column#9)->Column#7`, - ` └─TableReader 10000.00 root partition:all data:StreamAgg`, // TableReader is a inner child of Apply - ` └─StreamAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.trange.b)->Column#9`, + ` └─HashAgg(Probe) 10000.00 root funcs:sum(Column#8)->Column#7`, + ` └─TableReader 10000.00 root partition:all data:HashAgg`, // TableReader is a inner child of Apply + ` └─HashAgg 10000.00 cop[tikv] funcs:sum(test_parallel_apply.trange.b)->Column#8`, ` └─Selection 80000000.00 cop[tikv] gt(test_parallel_apply.trange.a, test_parallel_apply.touter.b)`, ` └─TableFullScan 100000000.00 cop[tikv] table:trange keep order:false, stats:pseudo`)) tk.MustQuery(`select * from touter where touter.a > (select sum(trange.b) from trange ignore index(a) where trange.a>touter.b)`).Sort().Check( diff --git a/executor/prepared_test.go b/executor/prepared_test.go index fbb8f2d0dd53a..13ef8fda55c12 100644 --- a/executor/prepared_test.go +++ b/executor/prepared_test.go @@ -421,6 +421,7 @@ func TestPlanCacheWithDifferentVariableTypes(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec(`set tidb_enable_prepared_plan_cache=1`) + tk.MustExec("set tidb_cost_model_version=1") tk.MustExec("use test") tk.MustExec("drop table if exists t1, t2") tk.MustExec("set @@tidb_enable_collect_execution_info=0;") diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 2afc708834311..24b19bad5c3e9 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -2880,6 +2880,7 @@ func TestBitColumnPushDown(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=1") tk.MustExec("create table t1(a bit(8), b int)") tk.MustExec("create table t2(a bit(8), b int)") tk.MustExec("insert into t1 values ('1', 1), ('2', 2), ('3', 3), ('4', 4), ('1', 1), ('2', 2), ('3', 3), ('4', 4)") @@ -5693,6 +5694,7 @@ func TestIndexJoinCost(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec(`drop table if exists t_outer, t_inner_pk, t_inner_idx`) tk.MustExec(`create table t_outer (a int)`) tk.MustExec(`create table t_inner_pk (a int primary key)`) @@ -5702,46 +5704,46 @@ func TestIndexJoinCost(t *testing.T) { tk.MustExec("set @@tidb_enable_chunk_rpc = on") tk.MustQuery(`explain format=verbose select /*+ TIDB_INLJ(t_outer, t_inner_pk) */ * from t_outer, t_inner_pk where t_outer.a=t_inner_pk.a`).Check(testkit.Rows( // IndexJoin with inner TableScan - `IndexJoin_11 12487.50 206368.09 root inner join, inner:TableReader_8, outer key:test.t_outer.a, inner key:test.t_inner_pk.a, equal cond:eq(test.t_outer.a, test.t_inner_pk.a)`, - `├─TableReader_18(Build) 9990.00 36412.58 root data:Selection_17`, - `│ └─Selection_17 9990.00 465000.00 cop[tikv] not(isnull(test.t_outer.a))`, - `│ └─TableFullScan_16 10000.00 435000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, - `└─TableReader_8(Probe) 9990.00 3.88 root data:TableRangeScan_7`, - ` └─TableRangeScan_7 9990.00 30.00 cop[tikv] table:t_inner_pk range: decided by [test.t_outer.a], keep order:false, stats:pseudo`)) + `IndexJoin_11 12487.50 11918182.35 root inner join, inner:TableReader_8, outer key:test.t_outer.a, inner key:test.t_inner_pk.a, equal cond:eq(test.t_outer.a, test.t_inner_pk.a)`, + `├─TableReader_18(Build) 9990.00 211131.09 root data:Selection_17`, + `│ └─Selection_17 9990.00 2534000.00 cop[tikv] not(isnull(test.t_outer.a))`, + `│ └─TableFullScan_16 10000.00 2035000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, + `└─TableReader_8(Probe) 9990.00 10.25 root data:TableRangeScan_7`, + ` └─TableRangeScan_7 9990.00 122.10 cop[tikv] table:t_inner_pk range: decided by [test.t_outer.a], keep order:false, stats:pseudo`)) tk.MustQuery(`explain format=verbose select /*+ TIDB_INLJ(t_outer, t_inner_idx) */ t_inner_idx.a from t_outer, t_inner_idx where t_outer.a=t_inner_idx.a`).Check(testkit.Rows( // IndexJoin with inner IndexScan - `IndexJoin_10 12487.50 235192.19 root inner join, inner:IndexReader_9, outer key:test.t_outer.a, inner key:test.t_inner_idx.a, equal cond:eq(test.t_outer.a, test.t_inner_idx.a)`, - `├─TableReader_20(Build) 9990.00 36412.58 root data:Selection_19`, - `│ └─Selection_19 9990.00 465000.00 cop[tikv] not(isnull(test.t_outer.a))`, - `│ └─TableFullScan_18 10000.00 435000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, - `└─IndexReader_9(Probe) 12487.50 5.89 root index:Selection_8`, - ` └─Selection_8 12487.50 58.18 cop[tikv] not(isnull(test.t_inner_idx.a))`, - ` └─IndexRangeScan_7 12500.00 54.43 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:false, stats:pseudo`)) + `IndexJoin_10 12487.50 11918207.26 root inner join, inner:IndexReader_9, outer key:test.t_outer.a, inner key:test.t_inner_idx.a, equal cond:eq(test.t_outer.a, test.t_inner_idx.a)`, + `├─TableReader_20(Build) 9990.00 211131.09 root data:Selection_19`, + `│ └─Selection_19 9990.00 2534000.00 cop[tikv] not(isnull(test.t_outer.a))`, + `│ └─TableFullScan_18 10000.00 2035000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, + `└─IndexReader_9(Probe) 12487.50 23.02 root index:Selection_8`, + ` └─Selection_8 12487.50 266.14 cop[tikv] not(isnull(test.t_inner_idx.a))`, + ` └─IndexRangeScan_7 12500.00 203.70 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:false, stats:pseudo`)) tk.MustQuery(`explain format=verbose select /*+ TIDB_INLJ(t_outer, t_inner_idx) */ * from t_outer, t_inner_idx where t_outer.a=t_inner_idx.a`).Check(testkit.Rows( // IndexJoin with inner IndexLookup - `IndexJoin_11 12487.50 531469.38 root inner join, inner:IndexLookUp_10, outer key:test.t_outer.a, inner key:test.t_inner_idx.a, equal cond:eq(test.t_outer.a, test.t_inner_idx.a)`, - `├─TableReader_23(Build) 9990.00 36412.58 root data:Selection_22`, - `│ └─Selection_22 9990.00 465000.00 cop[tikv] not(isnull(test.t_outer.a))`, - `│ └─TableFullScan_21 10000.00 435000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, - `└─IndexLookUp_10(Probe) 12487.50 35.55 root `, - ` ├─Selection_9(Build) 12487.50 75.08 cop[tikv] not(isnull(test.t_inner_idx.a))`, - ` │ └─IndexRangeScan_7 12500.00 71.32 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:false, stats:pseudo`, - ` └─TableRowIDScan_8(Probe) 12487.50 71.25 cop[tikv] table:t_inner_idx keep order:false, stats:pseudo`)) + `IndexJoin_11 12487.50 11922930.69 root inner join, inner:IndexLookUp_10, outer key:test.t_outer.a, inner key:test.t_inner_idx.a, equal cond:eq(test.t_outer.a, test.t_inner_idx.a)`, + `├─TableReader_23(Build) 9990.00 211131.09 root data:Selection_22`, + `│ └─Selection_22 9990.00 2534000.00 cop[tikv] not(isnull(test.t_outer.a))`, + `│ └─TableFullScan_21 10000.00 2035000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, + `└─IndexLookUp_10(Probe) 12487.50 2443.84 root `, + ` ├─Selection_9(Build) 12487.50 317.07 cop[tikv] not(isnull(test.t_inner_idx.a))`, + ` │ └─IndexRangeScan_7 12500.00 254.63 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:false, stats:pseudo`, + ` └─TableRowIDScan_8(Probe) 12487.50 284.13 cop[tikv] table:t_inner_idx keep order:false, stats:pseudo`)) tk.MustQuery("explain format=verbose select /*+ inl_hash_join(t_outer, t_inner_idx) */ t_inner_idx.a from t_outer, t_inner_idx where t_outer.a=t_inner_idx.a").Check(testkit.Rows( - `IndexHashJoin_12 12487.50 235192.19 root inner join, inner:IndexReader_9, outer key:test.t_outer.a, inner key:test.t_inner_idx.a, equal cond:eq(test.t_outer.a, test.t_inner_idx.a)`, - `├─TableReader_20(Build) 9990.00 36412.58 root data:Selection_19`, - `│ └─Selection_19 9990.00 465000.00 cop[tikv] not(isnull(test.t_outer.a))`, - `│ └─TableFullScan_18 10000.00 435000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, - `└─IndexReader_9(Probe) 12487.50 5.89 root index:Selection_8`, - ` └─Selection_8 12487.50 58.18 cop[tikv] not(isnull(test.t_inner_idx.a))`, - ` └─IndexRangeScan_7 12500.00 54.43 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:false, stats:pseudo`)) + `IndexHashJoin_12 12487.50 11918207.26 root inner join, inner:IndexReader_9, outer key:test.t_outer.a, inner key:test.t_inner_idx.a, equal cond:eq(test.t_outer.a, test.t_inner_idx.a)`, + `├─TableReader_20(Build) 9990.00 211131.09 root data:Selection_19`, + `│ └─Selection_19 9990.00 2534000.00 cop[tikv] not(isnull(test.t_outer.a))`, + `│ └─TableFullScan_18 10000.00 2035000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, + `└─IndexReader_9(Probe) 12487.50 23.02 root index:Selection_8`, + ` └─Selection_8 12487.50 266.14 cop[tikv] not(isnull(test.t_inner_idx.a))`, + ` └─IndexRangeScan_7 12500.00 203.70 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:false, stats:pseudo`)) tk.MustQuery("explain format=verbose select /*+ inl_merge_join(t_outer, t_inner_idx) */ t_inner_idx.a from t_outer, t_inner_idx where t_outer.a=t_inner_idx.a").Check(testkit.Rows( - `IndexMergeJoin_17 12487.50 229210.68 root inner join, inner:IndexReader_15, outer key:test.t_outer.a, inner key:test.t_inner_idx.a`, - `├─TableReader_20(Build) 9990.00 36412.58 root data:Selection_19`, - `│ └─Selection_19 9990.00 465000.00 cop[tikv] not(isnull(test.t_outer.a))`, - `│ └─TableFullScan_18 10000.00 435000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, - `└─IndexReader_15(Probe) 12487.50 5.89 root index:Selection_14`, - ` └─Selection_14 12487.50 58.18 cop[tikv] not(isnull(test.t_inner_idx.a))`, - ` └─IndexRangeScan_13 12500.00 54.43 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:true, stats:pseudo`)) + `IndexMergeJoin_17 12487.50 11918207.26 root inner join, inner:IndexReader_15, outer key:test.t_outer.a, inner key:test.t_inner_idx.a`, + `├─TableReader_20(Build) 9990.00 211131.09 root data:Selection_19`, + `│ └─Selection_19 9990.00 2534000.00 cop[tikv] not(isnull(test.t_outer.a))`, + `│ └─TableFullScan_18 10000.00 2035000.00 cop[tikv] table:t_outer keep order:false, stats:pseudo`, + `└─IndexReader_15(Probe) 12487.50 23.02 root index:Selection_14`, + ` └─Selection_14 12487.50 266.14 cop[tikv] not(isnull(test.t_inner_idx.a))`, + ` └─IndexRangeScan_13 12500.00 203.70 cop[tikv] table:t_inner_idx, index:a(a) range: decided by [eq(test.t_inner_idx.a, test.t_outer.a)], keep order:true, stats:pseudo`)) } func TestHeuristicIndexSelection(t *testing.T) { diff --git a/planner/core/partition_pruner_test.go b/planner/core/partition_pruner_test.go index ea23b9c4257ba..803b2adb647ba 100644 --- a/planner/core/partition_pruner_test.go +++ b/planner/core/partition_pruner_test.go @@ -261,6 +261,7 @@ func TestListPartitionPruner(t *testing.T) { tk.MustExec("drop database if exists test_partition;") tk.MustExec("create database test_partition") tk.MustExec("use test_partition") + tk.MustExec("set tidb_cost_model_version=2") tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly tk.MustExec("set @@session.tidb_enable_list_partition = ON") tk.MustExec(`set @@session.tidb_regard_null_as_point=false`) @@ -331,6 +332,7 @@ func TestListColumnsPartitionPruner(t *testing.T) { defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune") store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("set @@session.tidb_enable_list_partition = ON") tk.MustExec("drop database if exists test_partition;") tk.MustExec("create database test_partition") diff --git a/planner/core/plan_cost_detail_test.go b/planner/core/plan_cost_detail_test.go index 0054cd351bf84..0cad1210ec2f4 100644 --- a/planner/core/plan_cost_detail_test.go +++ b/planner/core/plan_cost_detail_test.go @@ -34,6 +34,7 @@ func TestPlanCostDetail(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=1") tk.MustExec(`create table t (a int primary key, b int, c int, d int, k int, key b(b), key cd(c, d), unique key(k))`) testcases := []struct { sql string diff --git a/planner/core/testdata/partition_pruner_out.json b/planner/core/testdata/partition_pruner_out.json index b1ab71b8f8145..c16109a17bbc2 100644 --- a/planner/core/testdata/partition_pruner_out.json +++ b/planner/core/testdata/partition_pruner_out.json @@ -802,7 +802,7 @@ "1" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(1)->Column#9", + "HashAgg 1.00 root funcs:count(1)->Column#9", "└─HashJoin 4.00 root inner join, equal:[eq(test_partition.t6.b, test_partition.t5.b)]", " ├─IndexReader(Build) 4.00 root partition:p0,p1 index:Selection", " │ └─Selection 4.00 cop[tikv] not(isnull(test_partition.t5.b))", @@ -818,7 +818,7 @@ "1" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(1)->Column#9", + "HashAgg 1.00 root funcs:count(1)->Column#9", "└─IndexJoin 4.00 root inner join, inner:IndexReader, outer key:test_partition.t6.b, inner key:test_partition.t5.b, equal cond:eq(test_partition.t6.b, test_partition.t5.b)", " ├─IndexReader(Build) 4.00 root partition:p0 index:Selection", " │ └─Selection 4.00 cop[tikv] not(isnull(test_partition.t6.b))", @@ -834,7 +834,7 @@ "1" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(1)->Column#9", + "HashAgg 1.00 root funcs:count(1)->Column#9", "└─IndexHashJoin 4.00 root inner join, inner:IndexReader, outer key:test_partition.t6.b, inner key:test_partition.t5.b, equal cond:eq(test_partition.t6.b, test_partition.t5.b)", " ├─IndexReader(Build) 4.00 root partition:p0 index:Selection", " │ └─Selection 4.00 cop[tikv] not(isnull(test_partition.t6.b))", @@ -897,9 +897,9 @@ "Plan": [ "Projection 1.00 root Column#5", "└─Sort 1.00 root test_partition.t1.id, test_partition.t1.a", - " └─StreamAgg 1.00 root funcs:count(Column#10)->Column#5, funcs:firstrow(Column#11)->test_partition.t1.id, funcs:firstrow(Column#12)->test_partition.t1.a", - " └─TableReader 1.00 root partition:all data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#10, funcs:firstrow(test_partition.t1.id)->Column#11, funcs:firstrow(test_partition.t1.a)->Column#12", + " └─HashAgg 1.00 root funcs:count(Column#7)->Column#5, funcs:firstrow(Column#8)->test_partition.t1.id, funcs:firstrow(Column#9)->test_partition.t1.a", + " └─TableReader 1.00 root partition:all data:HashAgg", + " └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#7, funcs:firstrow(test_partition.t1.id)->Column#8, funcs:firstrow(test_partition.t1.a)->Column#9", " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], "IndexPlan": [ @@ -934,9 +934,9 @@ "2" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#7)->Column#5", - "└─TableReader 1.00 root partition:p0 data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#7", + "HashAgg 1.00 root funcs:count(Column#6)->Column#5", + "└─TableReader 1.00 root partition:p0 data:HashAgg", + " └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#6", " └─Selection 19.99 cop[tikv] or(eq(test_partition.t1.a, 1), eq(test_partition.t1.b, 2))", " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], @@ -1941,9 +1941,9 @@ "1" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#7)->Column#5", - "└─TableReader 1.00 root partition:p0 data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#7", + "HashAgg 1.00 root funcs:count(Column#6)->Column#5", + "└─TableReader 1.00 root partition:p0 data:HashAgg", + " └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#6", " └─Selection 5542.21 cop[tikv] or(lt(test_partition.t1.a, 1), lt(test_partition.t1.b, 2))", " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], @@ -2789,7 +2789,7 @@ "2" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(1)->Column#9", + "HashAgg 1.00 root funcs:count(1)->Column#9", "└─HashJoin 7.81 root inner join, equal:[eq(test_partition.t1.b, test_partition.t2.b)]", " ├─TableReader(Build) 6.25 root partition:p0,p1 data:Selection", " │ └─Selection 6.25 cop[tikv] ge(test_partition.t2.a, 1), ge(test_partition.t2.b, 1), le(test_partition.t2.a, 6), le(test_partition.t2.b, 6), not(isnull(test_partition.t2.b))", @@ -2815,7 +2815,7 @@ "2" ], "Plan": [ - "StreamAgg 1.00 root funcs:count(1)->Column#9", + "HashAgg 1.00 root funcs:count(1)->Column#9", "└─HashJoin 7.81 root inner join, equal:[eq(test_partition.t2.b, test_partition.t1.b)]", " ├─TableReader(Build) 6.25 root partition:p0,p1 data:Selection", " │ └─Selection 6.25 cop[tikv] ge(test_partition.t1.a, 1), ge(test_partition.t1.b, 1), le(test_partition.t1.a, 6), le(test_partition.t1.b, 6), not(isnull(test_partition.t1.b))", diff --git a/statistics/handle/handle_test.go b/statistics/handle/handle_test.go index 6943265ce091b..4d268a59ae76e 100644 --- a/statistics/handle/handle_test.go +++ b/statistics/handle/handle_test.go @@ -2157,11 +2157,13 @@ func TestPartitionPruneModeSessionVariable(t *testing.T) { store := testkit.CreateMockStore(t) tk1 := testkit.NewTestKit(t, store) tk1.MustExec("use test") + tk1.MustExec("set tidb_cost_model_version=1") tk1.MustExec("set @@tidb_partition_prune_mode = '" + string(variable.Dynamic) + "'") tk1.MustExec(`set @@tidb_analyze_version=2`) tk2 := testkit.NewTestKit(t, store) tk2.MustExec("use test") + tk2.MustExec("set tidb_cost_model_version=1") tk2.MustExec("set @@tidb_partition_prune_mode = '" + string(variable.Static) + "'") tk2.MustExec(`set @@tidb_analyze_version=2`)