drop table if exists t; create table t(a int); insert into t values(1),(2); select count(1) from t join (select count(1) from t where false) as tmp; count(1) 2 select count(1) from t join (select max(a) from t where false) as tmp; count(1) 2 select count(1) from t join (select min(a) from t where false) as tmp; count(1) 2 select count(1) from t join (select sum(a) from t where false) as tmp; count(1) 2 select count(1) from t join (select avg(a) from t where false) as tmp; count(1) 2 select count(1) from t join (select count(1) from t where false group by a) as tmp; count(1) 0 select count(1) from t join (select max(a) from t where false group by a) as tmp; count(1) 0 select count(1) from t join (select min(a) from t where false group by a) as tmp; count(1) 0 select count(1) from t join (select sum(a) from t where false group by a) as tmp; count(1) 0 select count(1) from t join (select avg(a) from t where false group by a) as tmp; count(1) 0 SELECT avg(2) FROM(SELECT min(c) FROM t JOIN(SELECT 1 c) d ORDER BY a) e; avg(2) 2.0000 drop table if exists t; create table t(a bigint, b bigint); explain format='plan_tree' select * from t t1 left join t t2 on t1.a=t2.a where from_unixtime(t2.b); id task access object operator info Projection root planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.b, planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.b └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] from_unixtime(cast(planner__core__casetest__integration.t.b, decimal(20,0) BINARY)), not(isnull(planner__core__casetest__integration.t.a)) │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)) └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo drop table if exists t; create table t(a int not null, b datetime default null); explain format='plan_tree' select * from t t1 left join t t2 on t1.a = t2.a where cast(t1.b as date) >= '2019-01-01'; id task access object operator info HashJoin root left outer join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] ge(cast(planner__core__casetest__integration.t.b, date BINARY), 2019-01-01 00:00:00.000000) │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo set @@tidb_partition_prune_mode='static'; set tidb_opt_limit_push_down_threshold=0; drop table if exists t; create table t(a int, b int)partition by range columns(a)(partition p0 values less than (10), partition p1 values less than(20), partition p2 values less than(30)); insert into t values(21, 1), (22, 2), (23, 3), (24, 4), (15, 5); analyze table t all columns; explain format='plan_tree' select * from t order by a; id task access object operator info Sort root planner__core__casetest__integration.t.a └─PartitionUnion root ├─TableReader root data:TableFullScan │ └─TableFullScan cop[tikv] table:t, partition:p0 keep order:false, stats:pseudo ├─TableReader root data:TableFullScan │ └─TableFullScan cop[tikv] table:t, partition:p1 keep order:false └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t, partition:p2 keep order:false select * from t order by a; a b 15 5 21 1 22 2 23 3 24 4 explain format='plan_tree' select * from t order by a limit 3; id task access object operator info TopN root planner__core__casetest__integration.t.a, offset:0, count:3 └─PartitionUnion root ├─TopN root planner__core__casetest__integration.t.a, offset:0, count:3 │ └─TableReader root data:TopN │ └─TopN cop[tikv] planner__core__casetest__integration.t.a, offset:0, count:3 │ └─TableFullScan cop[tikv] table:t, partition:p0 keep order:false, stats:pseudo ├─TopN root planner__core__casetest__integration.t.a, offset:0, count:3 │ └─TableReader root data:TableFullScan │ └─TableFullScan cop[tikv] table:t, partition:p1 keep order:false └─TopN root planner__core__casetest__integration.t.a, offset:0, count:3 └─TableReader root data:TopN └─TopN cop[tikv] planner__core__casetest__integration.t.a, offset:0, count:3 └─TableFullScan cop[tikv] table:t, partition:p2 keep order:false select * from t order by a limit 3; a b 15 5 21 1 22 2 set tidb_opt_limit_push_down_threshold=default; drop table if exists t; create table t(a int primary key); set tidb_enable_clustered_index='ON'; create table cluster_index_t(a int, b int, c int, primary key (a, b)); explain format='plan_tree' (select max(a) from t) union (select min(a) from t); id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─StreamAgg root funcs:max(planner__core__casetest__integration.t.a)->Column │ └─Limit root offset:0, count:1 │ └─TableReader root data:Limit │ └─Limit cop[tikv] offset:0, count:1 │ └─TableFullScan cop[tikv] table:t keep order:true, desc, stats:pseudo └─StreamAgg root funcs:min(planner__core__casetest__integration.t.a)->Column └─Limit root offset:0, count:1 └─TableReader root data:Limit └─Limit cop[tikv] offset:0, count:1 └─TableFullScan cop[tikv] table:t keep order:true, stats:pseudo explain format='plan_tree' select min(a), max(a) from cluster_index_t; id task access object operator info HashJoin root CARTESIAN inner join ├─StreamAgg(Build) root funcs:max(planner__core__casetest__integration.cluster_index_t.a)->Column │ └─Limit root offset:0, count:1 │ └─TableReader root data:Limit │ └─Limit cop[tikv] offset:0, count:1 │ └─TableFullScan cop[tikv] table:cluster_index_t keep order:true, desc, stats:pseudo └─StreamAgg(Probe) root funcs:min(planner__core__casetest__integration.cluster_index_t.a)->Column └─Limit root offset:0, count:1 └─TableReader root data:Limit └─Limit cop[tikv] offset:0, count:1 └─TableFullScan cop[tikv] table:cluster_index_t keep order:true, stats:pseudo explain format='plan_tree' select min(b), max(b) from cluster_index_t where a = 1; id task access object operator info HashJoin root CARTESIAN inner join ├─StreamAgg(Build) root funcs:max(planner__core__casetest__integration.cluster_index_t.b)->Column │ └─Limit root offset:0, count:1 │ └─TableReader root data:Limit │ └─Limit cop[tikv] offset:0, count:1 │ └─TableRangeScan cop[tikv] table:cluster_index_t range:[1,1], keep order:true, desc, stats:pseudo └─StreamAgg(Probe) root funcs:min(planner__core__casetest__integration.cluster_index_t.b)->Column └─Limit root offset:0, count:1 └─TableReader root data:Limit └─Limit cop[tikv] offset:0, count:1 └─TableRangeScan cop[tikv] table:cluster_index_t range:[1,1], keep order:true, stats:pseudo explain format='plan_tree' select min(a), max(a) from cluster_index_t where b = 1; id task access object operator info StreamAgg root funcs:min(Column)->Column, funcs:max(Column)->Column └─TableReader root data:StreamAgg └─StreamAgg cop[tikv] funcs:min(planner__core__casetest__integration.cluster_index_t.a)->Column, funcs:max(planner__core__casetest__integration.cluster_index_t.a)->Column └─Selection cop[tikv] eq(planner__core__casetest__integration.cluster_index_t.b, 1) └─TableFullScan cop[tikv] table:cluster_index_t keep order:false, stats:pseudo explain format='plan_tree' select min(b), max(b) from cluster_index_t where b = 1; id task access object operator info StreamAgg root funcs:min(Column)->Column, funcs:max(Column)->Column └─TableReader root data:StreamAgg └─StreamAgg cop[tikv] funcs:min(planner__core__casetest__integration.cluster_index_t.b)->Column, funcs:max(planner__core__casetest__integration.cluster_index_t.b)->Column └─Selection cop[tikv] eq(planner__core__casetest__integration.cluster_index_t.b, 1) └─TableFullScan cop[tikv] table:cluster_index_t keep order:false, stats:pseudo set tidb_enable_clustered_index=DEFAULT; drop table if exists t; create table t(a int, b int); explain format='plan_tree' select t1.b from t t1 where t1.b in (select t2.a from t t2 order by t1.a+t2.a limit 1); id task access object operator info Projection root planner__core__casetest__integration.t.b └─Apply root semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t.b, planner__core__casetest__integration.t.a)] ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.b)) │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─Selection(Probe) root not(isnull(planner__core__casetest__integration.t.a)) └─Projection root planner__core__casetest__integration.t.a └─TopN root Column, offset:0, count:1 └─Projection root planner__core__casetest__integration.t.a, plus(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)->Column └─TableReader root data:TopN └─TopN cop[tikv] plus(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a), offset:0, count:1 └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo explain format='plan_tree' select t1.a from t t1 order by (t1.b = 1 and exists (select 1 from t t2 where t1.b = t2.b)) limit 1; id task access object operator info Projection root planner__core__casetest__integration.t.a └─TopN root Column, offset:0, count:1 └─Projection root planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.b, Column, and(eq(planner__core__casetest__integration.t.b, 1), Column)->Column └─HashJoin root left outer semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t.b, planner__core__casetest__integration.t.b)] ├─TableReader(Build) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo explain format='plan_tree' select * from (select b+b as x from t) t1, t t2 where t1.x=t2.b order by t1.x limit 1; id task access object operator info TopN root Column, offset:0, count:1 └─Projection root Column, planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.b └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.b, Column)] ├─Projection(Build) root plus(planner__core__casetest__integration.t.b, planner__core__casetest__integration.t.b)->Column │ └─TableReader root data:Selection │ └─Selection cop[tikv] not(isnull(plus(planner__core__casetest__integration.t.b, planner__core__casetest__integration.t.b))) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.b)) └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo drop table if exists t; create table t(a int, b int); insert into t values(1, 1), (2, 1), (3, 2), (4, 2), (5, 2); explain format='plan_tree' select approx_percentile(a, 50) from t; id task access object operator info HashAgg root funcs:approx_percentile(planner__core__casetest__integration.t.a, 50)->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select approx_percentile(a, 50) from t; approx_percentile(a, 50) 3 explain format='plan_tree' select approx_percentile(a, 10) from t; id task access object operator info HashAgg root funcs:approx_percentile(planner__core__casetest__integration.t.a, 10)->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select approx_percentile(a, 10) from t; approx_percentile(a, 10) 1 explain format='plan_tree' select approx_percentile(a, 10+70) from t; id task access object operator info HashAgg root funcs:approx_percentile(planner__core__casetest__integration.t.a, 80)->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select approx_percentile(a, 10+70) from t; approx_percentile(a, 10+70) 4 explain format='plan_tree' select approx_percentile(a, 10*10) from t; id task access object operator info HashAgg root funcs:approx_percentile(planner__core__casetest__integration.t.a, 100)->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select approx_percentile(a, 10*10) from t; approx_percentile(a, 10*10) 5 explain format='plan_tree' select approx_percentile(a, 50) from t group by b order by b; id task access object operator info Projection root Column └─Sort root planner__core__casetest__integration.t.b └─HashAgg root group by:planner__core__casetest__integration.t.b, funcs:approx_percentile(planner__core__casetest__integration.t.a, 50)->Column, funcs:firstrow(planner__core__casetest__integration.t.b)->planner__core__casetest__integration.t.b └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select approx_percentile(a, 50) from t group by b order by b; approx_percentile(a, 50) 1 4 drop table if exists t; create table t(a int); insert into t values(1),(1),(2); explain format='plan_tree' select /*+ stream_agg() */ count(*) c from t group by a order by c limit 1; id task access object operator info TopN root Column, offset:0, count:1 └─StreamAgg root group by:planner__core__casetest__integration.t.a, funcs:count(1)->Column └─Sort root planner__core__casetest__integration.t.a └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select /*+ stream_agg() */ count(*) c from t group by a order by c limit 1; c 1 explain format='plan_tree' select /*+ stream_agg() */ count(*) c from t group by a order by c; id task access object operator info Sort root Column └─StreamAgg root group by:planner__core__casetest__integration.t.a, funcs:count(1)->Column └─Sort root planner__core__casetest__integration.t.a └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select /*+ stream_agg() */ count(*) c from t group by a order by c; c 1 2 explain format='plan_tree' select /*+ stream_agg() */ count(*) c from t group by a order by a limit 1; id task access object operator info Limit root offset:0, count:1 └─StreamAgg root group by:planner__core__casetest__integration.t.a, funcs:count(1)->Column, funcs:firstrow(planner__core__casetest__integration.t.a)->planner__core__casetest__integration.t.a └─Sort root planner__core__casetest__integration.t.a └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select /*+ stream_agg() */ count(*) c from t group by a order by a limit 1; c 2 explain format='plan_tree' select /*+ stream_agg() */ count(*) c from t group by a order by a; id task access object operator info Projection root Column └─StreamAgg root group by:planner__core__casetest__integration.t.a, funcs:count(1)->Column, funcs:firstrow(planner__core__casetest__integration.t.a)->planner__core__casetest__integration.t.a └─Sort root planner__core__casetest__integration.t.a └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select /*+ stream_agg() */ count(*) c from t group by a order by a; c 2 1 drop table if exists t; drop table if exists s; create table t(a int, b int); create table s(a int, b int, index(a)); insert into t values(1,1),(1,2),(2,2); insert into s values(1,1),(2,2),(2,1); explain format='plan_tree' select /*+ inl_join(s) */ * from t join s on t.a=s.a and t.b = s.b; id task access object operator info IndexJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t.a, inner key:planner__core__casetest__integration.s.a, equal cond:eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.a), eq(planner__core__casetest__integration.t.b, planner__core__casetest__integration.s.b) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)), not(isnull(planner__core__casetest__integration.t.b)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.s.a)) │ └─IndexRangeScan cop[tikv] table:s, index:a(a) range: decided by [eq(planner__core__casetest__integration.s.a, planner__core__casetest__integration.t.a)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] not(isnull(planner__core__casetest__integration.s.b)) └─TableRowIDScan cop[tikv] table:s keep order:false, stats:pseudo explain format='plan_tree' select /*+ inl_join(s) */ * from t join s on t.a=s.a and t.b = s.a; id task access object operator info IndexJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t.a, inner key:planner__core__casetest__integration.s.a, equal cond:eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.a), eq(planner__core__casetest__integration.t.b, planner__core__casetest__integration.s.a) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)), not(isnull(planner__core__casetest__integration.t.b)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.s.a)) │ └─IndexRangeScan cop[tikv] table:s, index:a(a) range: decided by [eq(planner__core__casetest__integration.s.a, planner__core__casetest__integration.t.a)], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:s keep order:false, stats:pseudo explain format='plan_tree' select /*+ inl_join(s) */ * from t join s on t.a=s.a and t.a = s.b; id task access object operator info Projection root planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.b, planner__core__casetest__integration.s.a, planner__core__casetest__integration.s.b └─IndexJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t.a, inner key:planner__core__casetest__integration.s.a, equal cond:eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.a), eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.b) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.s.a)) │ └─IndexRangeScan cop[tikv] table:s, index:a(a) range: decided by [eq(planner__core__casetest__integration.s.a, planner__core__casetest__integration.t.a)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] not(isnull(planner__core__casetest__integration.s.b)) └─TableRowIDScan cop[tikv] table:s keep order:false, stats:pseudo explain format='plan_tree' select /*+ inl_hash_join(s) */ * from t join s on t.a=s.a and t.b = s.b; id task access object operator info IndexHashJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t.a, inner key:planner__core__casetest__integration.s.a, equal cond:eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.a), eq(planner__core__casetest__integration.t.b, planner__core__casetest__integration.s.b) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)), not(isnull(planner__core__casetest__integration.t.b)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.s.a)) │ └─IndexRangeScan cop[tikv] table:s, index:a(a) range: decided by [eq(planner__core__casetest__integration.s.a, planner__core__casetest__integration.t.a)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] not(isnull(planner__core__casetest__integration.s.b)) └─TableRowIDScan cop[tikv] table:s keep order:false, stats:pseudo explain format='plan_tree' select /*+ inl_hash_join(s) */ * from t join s on t.a=s.a and t.b = s.a; id task access object operator info IndexHashJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t.a, inner key:planner__core__casetest__integration.s.a, equal cond:eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.a), eq(planner__core__casetest__integration.t.b, planner__core__casetest__integration.s.a) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)), not(isnull(planner__core__casetest__integration.t.b)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.s.a)) │ └─IndexRangeScan cop[tikv] table:s, index:a(a) range: decided by [eq(planner__core__casetest__integration.s.a, planner__core__casetest__integration.t.a)], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:s keep order:false, stats:pseudo explain format='plan_tree' select /*+ inl_hash_join(s) */ * from t join s on t.a=s.a and t.a = s.b; id task access object operator info Projection root planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.b, planner__core__casetest__integration.s.a, planner__core__casetest__integration.s.b └─IndexHashJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t.a, inner key:planner__core__casetest__integration.s.a, equal cond:eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.a), eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.s.b) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.a)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.s.a)) │ └─IndexRangeScan cop[tikv] table:s, index:a(a) range: decided by [eq(planner__core__casetest__integration.s.a, planner__core__casetest__integration.t.a)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] not(isnull(planner__core__casetest__integration.s.b)) └─TableRowIDScan cop[tikv] table:s keep order:false, stats:pseudo drop table if exists t; create table t(a int, b int); insert into t values(1, 2), (3, 4); explain format='plan_tree' select (2) in (select b from t) from (select t.a < (select t.a from t t1 limit 1) from t) t; id task access object operator info HashJoin root CARTESIAN left outer semi join, left side:TableReader, other cond:eq(2, planner__core__casetest__integration.t.b) ├─TableReader(Build) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo select (2) in (select b from t) from (select t.a < (select t.a from t t1 limit 1) from t) t; (2) in (select b from t) 1 1 drop table if exists t1; create table t1 (c1 int primary key, c2 int, c3 int, index c2 (c2)); select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2; count(1) 1 drop table if exists t1,t2,t3; create table t1 (pk char(32) primary key nonclustered, col1 char(32), col2 varchar(40), col3 char(32), key (col1), key (col3), key (col2,col3), key (col1,col3)); create table t2 (pk char(32) primary key nonclustered, col1 varchar(100)); create table t3 (pk char(32) primary key nonclustered, keycol varchar(100), pad1 tinyint(1) default null, pad2 varchar(40), key (keycol,pad1,pad2)); explain format='plan_tree' SELECT t1.pk FROM t1 INNER JOIN t2 ON t1.col1 = t2.pk INNER JOIN t3 ON t1.col3 = t3.pk WHERE t2.col1 IN ('a' , 'b') AND t3.keycol = 'c' AND t1.col2 = 'a' AND t1.col1 != 'abcdef' AND t1.col1 != 'aaaaaa'; id task access object operator info IndexHashJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t1.col1, inner key:planner__core__casetest__integration.t2.pk, equal cond:eq(planner__core__casetest__integration.t1.col1, planner__core__casetest__integration.t2.pk) ├─IndexHashJoin(Build) root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t3.pk, inner key:planner__core__casetest__integration.t1.col3, equal cond:eq(planner__core__casetest__integration.t3.pk, planner__core__casetest__integration.t1.col3) │ ├─IndexLookUp(Build) root │ │ ├─IndexRangeScan(Build) cop[tikv] table:t3, index:keycol(keycol, pad1, pad2) range:["c","c"], keep order:false, stats:pseudo │ │ └─TableRowIDScan(Probe) cop[tikv] table:t3 keep order:false, stats:pseudo │ └─IndexLookUp(Probe) root │ ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.t1.col3)) │ │ └─IndexRangeScan cop[tikv] table:t1, index:col2(col2, col3) range: decided by [eq(planner__core__casetest__integration.t1.col3, planner__core__casetest__integration.t3.pk) eq(planner__core__casetest__integration.t1.col2, a)], keep order:false, stats:pseudo │ └─Selection(Probe) cop[tikv] ne(planner__core__casetest__integration.t1.col1, "aaaaaa"), ne(planner__core__casetest__integration.t1.col1, "abcdef"), not(isnull(planner__core__casetest__integration.t1.col1)) │ └─TableRowIDScan cop[tikv] table:t1 keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] ne(planner__core__casetest__integration.t2.pk, "aaaaaa"), ne(planner__core__casetest__integration.t2.pk, "abcdef") │ └─IndexRangeScan cop[tikv] table:t2, index:PRIMARY(pk) range: decided by [eq(planner__core__casetest__integration.t2.pk, planner__core__casetest__integration.t1.col1)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] in(planner__core__casetest__integration.t2.col1, "a", "b") └─TableRowIDScan cop[tikv] table:t2 keep order:false, stats:pseudo explain format='plan_tree' SELECT t1.pk FROM t1 LEFT JOIN t2 ON t1.col1 = t2.pk LEFT JOIN t3 ON t1.col3 = t3.pk WHERE t2.col1 IN ('a' , 'b') AND t3.keycol = 'c' AND t1.col2 = 'a' AND t1.col1 != 'abcdef' AND t1.col1 != 'aaaaaa'; id task access object operator info IndexHashJoin root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t1.col1, inner key:planner__core__casetest__integration.t2.pk, equal cond:eq(planner__core__casetest__integration.t1.col1, planner__core__casetest__integration.t2.pk) ├─IndexHashJoin(Build) root inner join, inner:IndexLookUp, outer key:planner__core__casetest__integration.t3.pk, inner key:planner__core__casetest__integration.t1.col3, equal cond:eq(planner__core__casetest__integration.t3.pk, planner__core__casetest__integration.t1.col3) │ ├─IndexLookUp(Build) root │ │ ├─IndexRangeScan(Build) cop[tikv] table:t3, index:keycol(keycol, pad1, pad2) range:["c","c"], keep order:false, stats:pseudo │ │ └─TableRowIDScan(Probe) cop[tikv] table:t3 keep order:false, stats:pseudo │ └─IndexLookUp(Probe) root │ ├─Selection(Build) cop[tikv] not(isnull(planner__core__casetest__integration.t1.col3)) │ │ └─IndexRangeScan cop[tikv] table:t1, index:col2(col2, col3) range: decided by [eq(planner__core__casetest__integration.t1.col3, planner__core__casetest__integration.t3.pk) eq(planner__core__casetest__integration.t1.col2, a)], keep order:false, stats:pseudo │ └─Selection(Probe) cop[tikv] ne(planner__core__casetest__integration.t1.col1, "aaaaaa"), ne(planner__core__casetest__integration.t1.col1, "abcdef"), not(isnull(planner__core__casetest__integration.t1.col1)) │ └─TableRowIDScan cop[tikv] table:t1 keep order:false, stats:pseudo └─IndexLookUp(Probe) root ├─Selection(Build) cop[tikv] ne(planner__core__casetest__integration.t2.pk, "aaaaaa"), ne(planner__core__casetest__integration.t2.pk, "abcdef") │ └─IndexRangeScan cop[tikv] table:t2, index:PRIMARY(pk) range: decided by [eq(planner__core__casetest__integration.t2.pk, planner__core__casetest__integration.t1.col1)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] in(planner__core__casetest__integration.t2.col1, "a", "b") └─TableRowIDScan cop[tikv] table:t2 keep order:false, stats:pseudo drop table if exists t1, t2; create table t1(a int, b int, c int, d int, index idx_a_b_c(a, b, c)); create table t2(a int, b int, c int, d int, index idx_a_b_c_d(a, b, c, d)); explain format='plan_tree' select a, b, c from t1 where a > 3 and b = 4 order by a, c; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.t1.b, 4) └─IndexRangeScan cop[tikv] table:t1, index:idx_a_b_c(a, b, c) range:(3,+inf], keep order:true, stats:pseudo explain format='plan_tree' select * from t2 where a = 1 and c = 2 order by b, d; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.t2.c, 2) └─IndexRangeScan cop[tikv] table:t2, index:idx_a_b_c_d(a, b, c, d) range:[1,1], keep order:true, stats:pseudo explain format='plan_tree' select a, b, c from t1 where (a = 1 and b = 1 and c = 1) or (a = 1 and b = 1 and c = 2) order by c; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:t1, index:idx_a_b_c(a, b, c) range:[1 1 1,1 1 2], keep order:true, stats:pseudo explain format='plan_tree' select a, b, c from t1 where (a = 1 and b = 1 and c < 3) or (a = 1 and b = 1 and c > 6) order by c; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:t1, index:idx_a_b_c(a, b, c) range:[1 1 -inf,1 1 3), (1 1 6,1 1 +inf], keep order:true, stats:pseudo explain format='plan_tree' select * from t2 where ((a = 1 and b = 1 and d < 3) or (a = 1 and b = 1 and d > 6)) and c = 3 order by d; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] or(and(eq(planner__core__casetest__integration.t2.a, 1), and(eq(planner__core__casetest__integration.t2.b, 1), lt(planner__core__casetest__integration.t2.d, 3))), and(eq(planner__core__casetest__integration.t2.a, 1), and(eq(planner__core__casetest__integration.t2.b, 1), gt(planner__core__casetest__integration.t2.d, 6)))) └─IndexRangeScan cop[tikv] table:t2, index:idx_a_b_c_d(a, b, c, d) range:[1 1 3,1 1 3], keep order:true, stats:pseudo drop table if exists t; create table t(a int not null, b int not null); explain format='plan_tree' select * from t where exists (select 1 from t t1 join t t2 where t1.a = t2.a and t1.a = t.a); id task access object operator info HashJoin root semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─HashJoin(Build) root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] │ ├─TableReader(Build) root data:TableFullScan │ │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where exists (select 1 from t t1 join t t2 on t1.a = t2.a and t1.a = t.a); id task access object operator info HashJoin root semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─HashJoin(Build) root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] │ ├─TableReader(Build) root data:TableFullScan │ │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 join t t2 where t1.a = t2.a and t1.a = t.a); id task access object operator info HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─HashAgg(Build) root group by:planner__core__casetest__integration.t.a, funcs:firstrow(planner__core__casetest__integration.t.a)->planner__core__casetest__integration.t.a │ └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] │ ├─TableReader(Build) root data:TableFullScan │ │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 join t t2 on t1.a = t2.a and t1.a = t.a); id task access object operator info HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─HashAgg(Build) root group by:planner__core__casetest__integration.t.a, funcs:firstrow(planner__core__casetest__integration.t.a)->planner__core__casetest__integration.t.a │ └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] │ ├─TableReader(Build) root data:TableFullScan │ │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select /*+ hash_join_build(t) */ * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 join t t2 where t1.a = t2.a and t1.a = t.a); id task access object operator info HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─HashAgg(Build) root group by:planner__core__casetest__integration.t.a, funcs:firstrow(planner__core__casetest__integration.t.a)->planner__core__casetest__integration.t.a │ └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] │ ├─TableReader(Build) root data:TableFullScan │ │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select /*+ hash_join_probe(t) */ * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 join t t2 where t1.a = t2.a and t1.a = t.a); id task access object operator info HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] ├─HashAgg(Build) root group by:planner__core__casetest__integration.t.a, funcs:firstrow(planner__core__casetest__integration.t.a)->planner__core__casetest__integration.t.a │ └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.a, planner__core__casetest__integration.t.a)] │ ├─TableReader(Build) root data:TableFullScan │ │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; create table t(a int); insert into t values (0), (1); set @@tidb_opt_enable_semi_join_rewrite = on; with c as (select * from t) select max(t.a) from t where exists ( select /*+ SEMI_JOIN_REWRITE() */ 1 from c where c.a < 1 ) and exists ( select 1 from c where c.a < 2 ); max(t.a) 1 set @@tidb_opt_enable_semi_join_rewrite = default; drop table if exists test; create table test(id int, value int); drop table if exists t; create table t(c int); insert t values(10), (8), (7), (9), (11); explain format='plan_tree' select count(*) from test t1 where exists (select value from test t2 where t1.id = t2.id limit 1); id task access object operator info HashAgg root funcs:count(1)->Column └─HashJoin root semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.test.id, planner__core__casetest__integration.test.id)] ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.test.id)) │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.test.id)) └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo explain format='plan_tree' select count(*) from test t1 where exists (select value from test t2 where t1.id = t2.id); id task access object operator info HashAgg root funcs:count(1)->Column └─HashJoin root semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.test.id, planner__core__casetest__integration.test.id)] ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.test.id)) │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.test.id)) └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo explain format='plan_tree' select count(*) from test t1 where exists (select value from test t2 where t1.id = t2.id limit 1,2); id task access object operator info HashAgg root funcs:count(1)->Column └─Apply root CARTESIAN semi join, left side:TableReader ├─TableReader(Build) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─Limit(Probe) root offset:1, count:2 └─TableReader root data:Limit └─Limit cop[tikv] offset:0, count:3 └─Selection cop[tikv] eq(planner__core__casetest__integration.test.id, planner__core__casetest__integration.test.id) └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo explain format='plan_tree' select * from t where 9 in (select c from t s where s.c < t.c limit 3); id task access object operator info Apply root CARTESIAN semi join, left side:TableReader ├─TableReader(Build) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─Selection(Probe) root eq(9, planner__core__casetest__integration.t.c) └─Limit root offset:0, count:3 └─TableReader root data:Limit └─Limit cop[tikv] offset:0, count:3 └─Selection cop[tikv] lt(planner__core__casetest__integration.t.c, planner__core__casetest__integration.t.c) └─TableFullScan cop[tikv] table:s keep order:false, stats:pseudo drop table if exists t0; create table t0 (a int, b int, index(a, b)); insert into t0 values (1, 1); insert into t0 values (2, 2); insert into t0 values (2, 2); insert into t0 values (2, 2); insert into t0 values (2, 2); insert into t0 values (2, 2); insert into t0 values (3, 3); drop table if exists t1; create table t1 (a int, b int, c int, index(a, b, c)); drop table if exists t2; create table t2 (a float, b float, index(a, b)); drop table if exists t3; create table t3 (a char(10), b char(10), c char(10), index(a, b, c)); explain format='plan_tree' select * from t0 where a > 1 and a < 3 order by b limit 2; id task access object operator info Limit root offset:0, count:2 └─IndexReader root index:Limit └─Limit cop[tikv] offset:0, count:2 └─IndexRangeScan cop[tikv] table:t0, index:a(a, b) range:[2,2], keep order:true, stats:pseudo explain format='plan_tree' select * from t1 where a >= 2 and a <= 2 and b = 2 and c > 2; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:t1, index:a(a, b, c) range:(2 2 2,2 2 +inf], keep order:false, stats:pseudo explain format='plan_tree' select * from t2 where a >= 2.5 and a <= 2.5 order by b limit 2; id task access object operator info Limit root offset:0, count:2 └─IndexReader root index:Limit └─Limit cop[tikv] offset:0, count:2 └─IndexRangeScan cop[tikv] table:t2, index:a(a, b) range:[2.5,2.5], keep order:true, stats:pseudo explain format='plan_tree' select * from t3 where a >= 'a' and a <= 'a' and b = 'b' and c > 'c'; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:t3, index:a(a, b, c) range:("a" "b" "c","a" "b" +inf], keep order:false, stats:pseudo explain format='plan_tree' select * from t1 where a is null or a in (1, 2, 3); id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:t1, index:a(a, b, c) range:[NULL,NULL], [1,3], keep order:false, stats:pseudo explain format='plan_tree' select * from t1 where a is null and a = 1; id task access object operator info TableDual root rows:0 drop table if exists t1; CREATE TABLE t1 ( key1 int(11) NOT NULL, key2 int(11) NOT NULL, key3 int(11) NOT NULL, key4 int(11) NOT NULL, key5 int(11) DEFAULT NULL, key6 int(11) DEFAULT NULL, key7 int(11) NOT NULL, key8 int(11) NOT NULL, KEY i1 (key1), KEY i2 (key2), KEY i3 (key3), KEY i4 (key4), KEY i5 (key5), KEY i6 (key6) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; explain format='plan_tree' SELECT /*+ use_index_merge(t1)*/ COUNT(*) FROM t1 WHERE (key4=42 AND key6 IS NOT NULL) OR (key1=4 AND key3=6); id task access object operator info StreamAgg root funcs:count(1)->Column └─IndexMerge root type: union ├─IndexRangeScan(Build) cop[tikv] table:t1, index:i4(key4) range:[42,42], keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:t1, index:i1(key1) range:[4,4], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] or(and(eq(planner__core__casetest__integration.t1.key4, 42), not(isnull(planner__core__casetest__integration.t1.key6))), and(eq(planner__core__casetest__integration.t1.key1, 4), eq(planner__core__casetest__integration.t1.key3, 6))) └─TableRowIDScan cop[tikv] table:t1 keep order:false, stats:pseudo drop table if exists tpk; create table tuk (a int, b int, c int, unique key (a, b, c)); create table tik (a int, b int, c int, key (a, b, c)); insert into tuk values (NULL, NULL, NULL); insert into tik values (NULL, NULL, NULL); insert into tuk values (NULL, NULL, NULL); insert into tik values (NULL, NULL, NULL); insert into tuk values (NULL, NULL, 1); insert into tik values (NULL, NULL, 1); insert into tuk values (NULL, NULL, 1); insert into tik values (NULL, NULL, 1); insert into tuk values (NULL, 1, NULL); insert into tik values (NULL, 1, NULL); insert into tuk values (NULL, 1, NULL); insert into tik values (NULL, 1, NULL); insert into tuk values (NULL, 1, 1); insert into tik values (NULL, 1, 1); insert into tuk values (NULL, 1, 1); insert into tik values (NULL, 1, 1); insert into tuk values (1, NULL, NULL); insert into tik values (1, NULL, NULL); insert into tuk values (1, NULL, NULL); insert into tik values (1, NULL, NULL); insert into tuk values (1, NULL, 1); insert into tik values (1, NULL, 1); insert into tuk values (1, NULL, 1); insert into tik values (1, NULL, 1); insert into tuk values (1, 1, NULL); insert into tik values (1, 1, NULL); insert into tuk values (1, 1, NULL); insert into tik values (1, 1, NULL); insert into tuk values (1, 1, 1); insert into tik values (1, 1, 1); set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a<=>null and b=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL 1,NULL 1], keep order:false, stats:pseudo select * from tuk where a<=>null and b=1; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a<=>null and b=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tuk.b, 1) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b=1; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a<=>null and b=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL 1,NULL 1], keep order:false, stats:pseudo select * from tik where a<=>null and b=1; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a<=>null and b=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tik.b, 1) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b=1; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a<=>null and b>0 and b<2; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL 1,NULL 1], keep order:false, stats:pseudo select * from tuk where a<=>null and b>0 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a<=>null and b>0 and b<2; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tuk.b, 1) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b>0 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a<=>null and b>0 and b<2; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL 1,NULL 1], keep order:false, stats:pseudo select * from tik where a<=>null and b>0 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a<=>null and b>0 and b<2; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tik.b, 1) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b>0 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a<=>null and b>=1 and b<2; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL 1,NULL 1], keep order:false, stats:pseudo select * from tuk where a<=>null and b>=1 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a<=>null and b>=1 and b<2; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tuk.b, 1) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b>=1 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a<=>null and b>=1 and b<2; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL 1,NULL 1], keep order:false, stats:pseudo select * from tik where a<=>null and b>=1 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a<=>null and b>=1 and b<2; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tik.b, 1) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b>=1 and b<2; a b c NULL 1 NULL NULL 1 NULL NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a<=>null and b=1 and c=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL 1 1,NULL 1 1], keep order:false, stats:pseudo select * from tuk where a<=>null and b=1 and c=1; a b c NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a<=>null and b=1 and c=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tuk.b, 1), eq(planner__core__casetest__integration.tuk.c, 1) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b=1 and c=1; a b c NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a<=>null and b=1 and c=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL 1 1,NULL 1 1], keep order:false, stats:pseudo select * from tik where a<=>null and b=1 and c=1; a b c NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a<=>null and b=1 and c=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tik.b, 1), eq(planner__core__casetest__integration.tik.c, 1) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b=1 and c=1; a b c NULL 1 1 NULL 1 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a=1 and b<=>null and c=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[1 NULL 1,1 NULL 1], keep order:false, stats:pseudo select * from tuk where a=1 and b<=>null and c=1; a b c 1 NULL 1 1 NULL 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a=1 and b<=>null and c=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tuk.c, 1) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[1 NULL,1 NULL], keep order:false, stats:pseudo select * from tuk where a=1 and b<=>null and c=1; a b c 1 NULL 1 1 NULL 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a=1 and b<=>null and c=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[1 NULL 1,1 NULL 1], keep order:false, stats:pseudo select * from tik where a=1 and b<=>null and c=1; a b c 1 NULL 1 1 NULL 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a=1 and b<=>null and c=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tik.c, 1) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[1 NULL,1 NULL], keep order:false, stats:pseudo select * from tik where a=1 and b<=>null and c=1; a b c 1 NULL 1 1 NULL 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a<=>null and b<=>null and c=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL NULL 1,NULL NULL 1], keep order:false, stats:pseudo select * from tuk where a<=>null and b<=>null and c=1; a b c NULL NULL 1 NULL NULL 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a<=>null and b<=>null and c=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tuk.c, 1), nulleq(planner__core__casetest__integration.tuk.b, NULL) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b<=>null and c=1; a b c NULL NULL 1 NULL NULL 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a<=>null and b<=>null and c=1; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL NULL 1,NULL NULL 1], keep order:false, stats:pseudo select * from tik where a<=>null and b<=>null and c=1; a b c NULL NULL 1 NULL NULL 1 set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a<=>null and b<=>null and c=1; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.tik.c, 1), nulleq(planner__core__casetest__integration.tik.b, NULL) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b<=>null and c=1; a b c NULL NULL 1 NULL NULL 1 set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tuk where a<=>null and b<=>null and c<=>null; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL NULL NULL,NULL NULL NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b<=>null and c<=>null; a b c NULL NULL NULL NULL NULL NULL set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tuk where a<=>null and b<=>null and c<=>null; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] nulleq(planner__core__casetest__integration.tuk.b, NULL), nulleq(planner__core__casetest__integration.tuk.c, NULL) └─IndexRangeScan cop[tikv] table:tuk, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tuk where a<=>null and b<=>null and c<=>null; a b c NULL NULL NULL NULL NULL NULL set @@session.tidb_regard_null_as_point=true; explain format='plan_tree' select * from tik where a<=>null and b<=>null and c<=>null; id task access object operator info IndexReader root index:IndexRangeScan └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL NULL NULL,NULL NULL NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b<=>null and c<=>null; a b c NULL NULL NULL NULL NULL NULL set @@session.tidb_regard_null_as_point=false; explain format='plan_tree' select * from tik where a<=>null and b<=>null and c<=>null; id task access object operator info IndexReader root index:Selection └─Selection cop[tikv] nulleq(planner__core__casetest__integration.tik.b, NULL), nulleq(planner__core__casetest__integration.tik.c, NULL) └─IndexRangeScan cop[tikv] table:tik, index:a(a, b, c) range:[NULL,NULL], keep order:false, stats:pseudo select * from tik where a<=>null and b<=>null and c<=>null; a b c NULL NULL NULL NULL NULL NULL set @@session.tidb_regard_null_as_point=default; drop table if exists t1; create table t1(c1 varchar(100), c2 varchar(100), key(c1), key(c2), c3 varchar(100)); insert into t1 values('ab', '10', '10'); drop table if exists tt1; create table tt1(c1 varchar(100), c2 varchar(100), c3 varchar(100), c4 varchar(100), key idx_0(c1), key idx_1(c2, c3)); insert into tt1 values('ab', '10', '10', '10'); drop table if exists tt2; create table tt2 (c1 int , pk int, primary key( pk ) , unique key( c1)); insert into tt2 values(-3896405, -1), (-2, 1), (-1, -2); drop table if exists tt3; create table tt3(c1 int, c2 int, c3 int as (c1 + c2), key(c1), key(c2), key(c3)); insert into tt3(c1, c2) values(1, 1); select @@tidb_enable_index_merge; @@tidb_enable_index_merge 1 set tidb_enable_index_merge = on; explain format='plan_tree' select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c1)) = 'ab'; id task access object operator info Projection root 1->Column └─Selection root or(eq(planner__core__casetest__integration.t1.c1, "de"), and(eq(planner__core__casetest__integration.t1.c2, "10"), eq(from_base64(to_base64(planner__core__casetest__integration.t1.c1)), "ab"))) └─IndexMerge root type: union ├─IndexRangeScan(Build) cop[tikv] table:t1, index:c1(c1) range:["de","de"], keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:t1, index:c2(c2) range:["10","10"], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:t1 keep order:false, stats:pseudo select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c1)) = 'ab'; 1 1 explain format='plan_tree' select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'ab' or c2 = '10' and char_length(left(c1, 10)) = 10; id task access object operator info Projection root 1->Column └─Selection root or(eq(planner__core__casetest__integration.t1.c1, "ab"), and(eq(planner__core__casetest__integration.t1.c2, "10"), eq(char_length(left(planner__core__casetest__integration.t1.c1, 10)), 10))) └─IndexMerge root type: union ├─IndexRangeScan(Build) cop[tikv] table:t1, index:c1(c1) range:["ab","ab"], keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:t1, index:c2(c2) range:["10","10"], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:t1 keep order:false, stats:pseudo select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'ab' or c2 = '10' and char_length(left(c1, 10)) = 10; 1 1 explain format='plan_tree' select /*+ use_index_merge(tt1) */ 1 from tt1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c3)) = '10'; id task access object operator info Projection root 1->Column └─Selection root or(eq(planner__core__casetest__integration.tt1.c1, "de"), and(eq(planner__core__casetest__integration.tt1.c2, "10"), eq(from_base64(to_base64(planner__core__casetest__integration.tt1.c3)), "10"))) └─IndexMerge root type: union ├─IndexRangeScan(Build) cop[tikv] table:tt1, index:idx_0(c1) range:["de","de"], keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:tt1, index:idx_1(c2, c3) range:["10","10"], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:tt1 keep order:false, stats:pseudo select /*+ use_index_merge(tt1) */ 1 from tt1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c3)) = '10'; 1 1 explain format='plan_tree' select /*+ use_index_merge( tt2 ) */ 1 from tt2 where tt2.c1 in (-3896405) or tt2.pk in (1, 53330) and to_base64(left(pk, 5)); id task access object operator info Projection root 1->Column └─Selection root or(eq(planner__core__casetest__integration.tt2.c1, -3896405), and(in(planner__core__casetest__integration.tt2.pk, 1, 53330), istrue_with_null(cast(to_base64(left(cast(planner__core__casetest__integration.tt2.pk, var_string(20)), 5)), double BINARY)))) └─IndexMerge root type: union ├─IndexRangeScan(Build) cop[tikv] table:tt2, index:c1(c1) range:[-3896405,-3896405], keep order:false, stats:pseudo ├─TableRangeScan(Build) cop[tikv] table:tt2 range:[1,1], [53330,53330], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:tt2 keep order:false, stats:pseudo select /*+ use_index_merge( tt2 ) */ 1 from tt2 where tt2.c1 in (-3896405) or tt2.pk in (1, 53330) and to_base64(left(pk, 5)); 1 1 explain format='plan_tree' select /*+ use_index_merge(tt3) */ 1 from tt3 where c1 < -10 or c2 < 10 and reverse(c3) = '2'; id task access object operator info Projection root 1->Column └─Selection root or(lt(planner__core__casetest__integration.tt3.c1, -10), and(lt(planner__core__casetest__integration.tt3.c2, 10), eq(reverse(cast(planner__core__casetest__integration.tt3.c3, var_string(20))), "2"))) └─IndexMerge root type: union ├─IndexRangeScan(Build) cop[tikv] table:tt3, index:c1(c1) range:[-inf,-10), keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:tt3, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:tt3 keep order:false, stats:pseudo select /*+ use_index_merge(tt3) */ 1 from tt3 where c1 < -10 or c2 < 10 and reverse(c3) = '2'; 1 1 explain format='plan_tree' select 1 from t1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c1)) = 'ab'; id task access object operator info Projection root 1->Column └─Selection root or(eq(planner__core__casetest__integration.t1.c1, "de"), and(eq(planner__core__casetest__integration.t1.c2, "10"), eq(from_base64(to_base64(planner__core__casetest__integration.t1.c1)), "ab"))) └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo select 1 from t1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c1)) = 'ab'; 1 1 set tidb_enable_index_merge = 1; set tidb_enable_index_merge = default; drop table if exists t1,t2; create table t1(a int); create table t2(a int, b int, c int, primary key(a,b) nonclustered); explain format='plan_tree' select (select c from t2 where t2.a = t1.a and t2.b = 1) from t1; id task access object operator info HashJoin root left outer join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2.a)] ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] eq(planner__core__casetest__integration.t2.b, 1) │ └─TableFullScan cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo explain format='plan_tree' select (select c from t2 where t2.a = t1.a and (t2.b = 1 or t2.b = 2)) from t1; id task access object operator info Projection root planner__core__casetest__integration.t2.c └─Apply root CARTESIAN left outer join, left side:TableReader ├─TableReader(Build) root data:TableFullScan │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─MaxOneRow(Probe) root └─IndexLookUp root ├─Selection(Build) cop[tikv] or(eq(planner__core__casetest__integration.t2.b, 1), eq(planner__core__casetest__integration.t2.b, 2)) │ └─IndexRangeScan cop[tikv] table:t2, index:PRIMARY(a, b) range: decided by [eq(planner__core__casetest__integration.t2.a, planner__core__casetest__integration.t1.a)], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:t2 keep order:false, stats:pseudo drop sequence if exists s1, s2; create sequence s1; create sequence s2; explain format='plan_tree' select 1 from s1; id task access object operator info Projection root 1->Column └─TableDual root rows:1 explain format='plan_tree' select count(1) from s1; id task access object operator info StreamAgg root funcs:count(1)->Column └─TableDual root rows:1 explain format='plan_tree' select count(*) from s1; id task access object operator info StreamAgg root funcs:count(1)->Column └─TableDual root rows:1 explain format='plan_tree' select sum(1) from s1; id task access object operator info StreamAgg root funcs:sum(1)->Column └─TableDual root rows:1 explain format='plan_tree' select count(1) as cnt from s1 union select count(1) as cnt from s2; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─StreamAgg root funcs:count(1)->Column │ └─TableDual root rows:1 └─StreamAgg root funcs:count(1)->Column └─TableDual root rows:1 drop table if exists t; create table t(a int, b int, c int, d int, e int, f int, g int, primary key (a), unique key c_d_e (c, d, e), unique key f (f), unique key f_g (f, g), key g (g)); set @@tidb_enable_chunk_rpc = on; explain format = 'brief' select * from t where a > 1 order by f; id estRows task access object operator info Sort 3333.33 root planner__core__casetest__integration.t.f └─TableReader 3333.33 root data:TableRangeScan └─TableRangeScan 3333.33 cop[tikv] table:t range:(1,+inf], keep order:false, stats:pseudo explain format = 'brief' select * from t where f > 1; id estRows task access object operator info TableReader 3333.33 root data:Selection └─Selection 3333.33 cop[tikv] gt(planner__core__casetest__integration.t.f, 1) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select f from t where f > 1; id estRows task access object operator info IndexReader 3333.33 root index:IndexRangeScan └─IndexRangeScan 3333.33 cop[tikv] table:t, index:f(f) range:(1,+inf], keep order:false, stats:pseudo explain format = 'brief' select * from t where f > 3 and g = 5; id estRows task access object operator info IndexLookUp 3.33 root ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:g(g) range:[5,5], keep order:false, stats:pseudo └─Selection(Probe) 3.33 cop[tikv] gt(planner__core__casetest__integration.t.f, 3) └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t where g = 5 order by f; id estRows task access object operator info Sort 10.00 root planner__core__casetest__integration.t.f └─IndexLookUp 10.00 root ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:g(g) range:[5,5], keep order:false, stats:pseudo └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t where d = 3 order by c, e; id estRows task access object operator info IndexLookUp 10.00 root ├─Selection(Build) 10.00 cop[tikv] eq(planner__core__casetest__integration.t.d, 3) │ └─IndexFullScan 10000.00 cop[tikv] table:t, index:c_d_e(c, d, e) keep order:true, stats:pseudo └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo set @@tidb_enable_chunk_rpc = default; drop table if exists t; create table t(a int unsigned primary key, b int, c int, index idx_b(b)); insert into t values (1,2,3), (4,5,6), (7,8,9), (10,11,12), (13,14,15); analyze table t; set @@tidb_enable_chunk_rpc = on; set tidb_opt_prefer_range_scan = 0; explain format = 'brief' select * from t where b > 5; id estRows task access object operator info TableReader 3.00 root data:Selection └─Selection 3.00 cop[tikv] gt(planner__core__casetest__integration.t.b, 5) └─TableFullScan 5.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b = 6 order by a limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─TableReader 1.00 root data:Limit └─Limit 1.00 cop[tikv] offset:0, count:1 └─Selection 1.00 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) └─TableFullScan 5.00 cop[tikv] table:t keep order:true explain format = 'brief' select * from t where b = 6 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─TableReader 1.00 root data:Limit └─Limit 1.00 cop[tikv] offset:0, count:1 └─Selection 1.00 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) └─TableFullScan 5.00 cop[tikv] table:t keep order:false set tidb_opt_prefer_range_scan = 1; explain format = 'brief' select * from t where b > 5; id estRows task access object operator info TableReader 3.00 root data:Selection └─Selection 3.00 cop[tikv] gt(planner__core__casetest__integration.t.b, 5) └─TableFullScan 5.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b = 6 order by a limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─TableReader 1.00 root data:Limit └─Limit 1.00 cop[tikv] offset:0, count:1 └─Selection 1.00 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) └─TableFullScan 5.00 cop[tikv] table:t keep order:true explain format = 'brief' select * from t where b = 6 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─TableReader 1.00 root data:Limit └─Limit 1.00 cop[tikv] offset:0, count:1 └─Selection 1.00 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) └─TableFullScan 5.00 cop[tikv] table:t keep order:false set @@tidb_enable_chunk_rpc = default; set tidb_opt_prefer_range_scan = default; drop table if exists t; create table t(a int primary key, b int, c int, index idx_b(b)); insert into t values (1,2,3), (4,5,6), (7,8,9), (10, 11, 12), (13,14,15), (16, 17, 18); analyze table t; explain format='plan_tree' select * from t use index (idx_b) where b = 2 limit 1; id task access object operator info IndexLookUp root limit embedded(offset:0, count:1) ├─Limit(Build) cop[tikv] offset:0, count:1 │ └─IndexRangeScan cop[tikv] table:t, index:idx_b(b) range:[2,2], keep order:false └─TableRowIDScan(Probe) cop[tikv] table:t keep order:false drop table if exists t1; create table t1(c1 int); insert into t1 values(1), (2), (3), (4), (5), (6); select floor(dt.rn/2) rownum, count(c1) from (select @rownum := @rownum + 1 rn, c1 from (select @rownum := -1) drn, t1) dt group by floor(dt.rn/2) order by rownum; rownum count(c1) 0 2 1 2 2 2 create table ta(a int, b int); set sql_mode=''; explain format='plan_tree' select floor(dt.rn/2) rownum, count(c1) from (select @rownum := @rownum + 1 rn, c1 from (select @rownum := -1) drn, t1) dt group by floor(dt.rn/2) order by rownum; id task access object operator info Sort root Column └─Projection root floor(div(cast(Column, decimal(20,0) BINARY), 2))->Column, Column └─HashAgg root group by:Column, funcs:count(Column)->Column, funcs:firstrow(Column)->Column └─Projection root planner__core__casetest__integration.t1.c1->Column, Column, floor(div(cast(Column, decimal(20,0) BINARY), 2))->Column └─Projection root setvar(rownum, plus(getvar(rownum), 1))->Column, planner__core__casetest__integration.t1.c1 └─HashJoin root CARTESIAN inner join ├─Projection(Build) root setvar(rownum, -1)->Column │ └─TableDual root rows:1 └─TableReader(Probe) root data:TableFullScan └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo explain format='plan_tree' select @n:=@n+1 as e from ta group by e; id task access object operator info Projection root setvar(n, plus(getvar(n), 1))->Column └─HashAgg root group by:Column, funcs:firstrow(1)->Column └─Projection root setvar(n, plus(cast(getvar(n), double BINARY), 1))->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:ta keep order:false, stats:pseudo explain format='plan_tree' select @n:=@n+a as e from ta group by e; id task access object operator info Projection root setvar(n, plus(getvar(n), cast(planner__core__casetest__integration.ta.a, double BINARY)))->Column └─HashAgg root group by:Column, funcs:firstrow(Column)->planner__core__casetest__integration.ta.a └─Projection root planner__core__casetest__integration.ta.a->Column, setvar(n, plus(getvar(n), cast(planner__core__casetest__integration.ta.a, double BINARY)))->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:ta keep order:false, stats:pseudo explain format='plan_tree' select * from (select @n:=@n+1 as e from ta) tt group by e; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Projection root setvar(n, plus(getvar(n), 1))->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:ta keep order:false, stats:pseudo explain format='plan_tree' select * from (select @n:=@n+a as e from ta) tt group by e; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Projection root setvar(n, plus(getvar(n), cast(planner__core__casetest__integration.ta.a, double BINARY)))->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:ta keep order:false, stats:pseudo explain format='plan_tree' select a from ta group by @n:=@n+1; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->planner__core__casetest__integration.ta.a └─Projection root planner__core__casetest__integration.ta.a->Column, setvar(n, plus(getvar(n), 1))->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:ta keep order:false, stats:pseudo explain format='plan_tree' select a from ta group by @n:=@n+a; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->planner__core__casetest__integration.ta.a └─Projection root planner__core__casetest__integration.ta.a->Column, setvar(n, plus(getvar(n), cast(planner__core__casetest__integration.ta.a, double BINARY)))->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:ta keep order:false, stats:pseudo set sql_mode=default; drop table if exists t1, t2, t3, t4, t5, t6, t7, t8; create table t1 (a bigint key); create table t2 (a int key); create definer=`root`@`127.0.0.1` view v1 as (select a from t1) union (select a from t2); create table t3 (a varchar(100) key); create table t4 (a varchar(10) key); create definer=`root`@`127.0.0.1` view v2 as (select a from t3) union (select a from t4); create table t5 (a char(100) key); create table t6 (a char(10) key); create definer=`root`@`127.0.0.1` view v3 as (select a from t5) union (select a from t6); create table t7 (a varchar(100) key); create table t8 (a int key); create definer=`root`@`127.0.0.1` view v4 as (select a from t7) union (select a from t8); explain format='plan_tree' select * from v1 where a = 1; -- the condition should be downcast through both side and go get point; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─Point_Get root table:t1 handle:1 └─Projection root cast(planner__core__casetest__integration.t2.a, bigint BINARY)->Column └─Point_Get root table:t2 handle:1 select * from v1 where a = 1; -- the condition should be downcast through both side and go get point; a explain format='plan_tree' select * from v1 where a = '1test'; -- the condition should be downcast through both side and go get point too; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─Point_Get root table:t1 handle:1 └─Projection root cast(planner__core__casetest__integration.t2.a, bigint BINARY)->Column └─Point_Get root table:t2 handle:1 select * from v1 where a = '1test'; -- the condition should be downcast through both side and go get point too; a explain format='plan_tree' select * from v1 where a > 1; -- the condition should be downcast through both side and go range scan; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─TableReader root data:TableRangeScan │ └─TableRangeScan cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo └─Projection root cast(planner__core__casetest__integration.t2.a, bigint BINARY)->Column └─TableReader root data:TableRangeScan └─TableRangeScan cop[tikv] table:t2 range:(1,+inf], keep order:false, stats:pseudo select * from v1 where a > 1; -- the condition should be downcast through both side and go range scan; a explain format='plan_tree' select * from v2 where a = 'test'; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─Point_Get root table:t3, clustered index:PRIMARY(a) └─Projection root cast(planner__core__casetest__integration.t4.a, varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─Point_Get root table:t4, clustered index:PRIMARY(a) select * from v2 where a = 'test'; a explain format='plan_tree' select * from v2 where a = 1; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─TableReader root data:Selection │ └─Selection cop[tikv] eq(cast(planner__core__casetest__integration.t3.a, double BINARY), 1) │ └─TableFullScan cop[tikv] table:t3 keep order:false, stats:pseudo └─Projection root cast(planner__core__casetest__integration.t4.a, varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─TableReader root data:Selection └─Selection cop[tikv] eq(cast(cast(planner__core__casetest__integration.t4.a, varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin), double BINARY), 1) └─TableFullScan cop[tikv] table:t4 keep order:false, stats:pseudo select * from v2 where a = 1; a explain format='plan_tree' select * from v2 where a > 'test'; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─TableReader root data:TableRangeScan │ └─TableRangeScan cop[tikv] table:t3 range:("test",+inf], keep order:false, stats:pseudo └─Projection root cast(planner__core__casetest__integration.t4.a, varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─TableReader root data:TableRangeScan └─TableRangeScan cop[tikv] table:t4 range:("test",+inf], keep order:false, stats:pseudo select * from v2 where a > 'test'; a explain format='plan_tree' select * from v3 where a = 'test' -- the condition shouldn't be downcast through both side and go get point; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─Point_Get root table:t5, clustered index:PRIMARY(a) └─Projection root cast(planner__core__casetest__integration.t6.a, char(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─TableReader root data:Selection └─Selection cop[tikv] eq(cast(planner__core__casetest__integration.t6.a, char(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin), "test") └─TableFullScan cop[tikv] table:t6 keep order:false, stats:pseudo select * from v3 where a = 'test' -- the condition shouldn't be downcast through both side and go get point; a explain format='plan_tree' select * from v3 where a > 'test' -- the condition shouldn't be downcast through both side and go get point too; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─TableReader root data:TableRangeScan │ └─TableRangeScan cop[tikv] table:t5 range:("test",+inf], keep order:false, stats:pseudo └─Projection root cast(planner__core__casetest__integration.t6.a, char(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─TableReader root data:Selection └─Selection cop[tikv] gt(cast(planner__core__casetest__integration.t6.a, char(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin), "test") └─TableFullScan cop[tikv] table:t6 keep order:false, stats:pseudo select * from v3 where a > 'test' -- the condition shouldn't be downcast through both side and go get point too; a explain format='plan_tree' select * from v4 where a = 'test' -- diff column union may have precision loss couldn't downcast the condition to get the range; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─Point_Get root table:t7, clustered index:PRIMARY(a) └─Selection root eq(Column, "test") └─Projection root cast(planner__core__casetest__integration.t8.a, varchar(100) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t8 keep order:false, stats:pseudo select * from v4 where a = 'test' -- diff column union may have precision loss couldn't downcast the condition to get the range; a explain format='plan_tree' select * from v4 where a > 'test' -- diff column union may have precision loss couldn't downcast the condition to get the range; id task access object operator info HashAgg root group by:Column, funcs:firstrow(Column)->Column └─Union root ├─TableReader root data:TableRangeScan │ └─TableRangeScan cop[tikv] table:t7 range:("test",+inf], keep order:false, stats:pseudo └─Selection root gt(Column, "test") └─Projection root cast(planner__core__casetest__integration.t8.a, varchar(100) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column └─TableReader root data:TableFullScan └─TableFullScan cop[tikv] table:t8 keep order:false, stats:pseudo select * from v4 where a > 'test' -- diff column union may have precision loss couldn't downcast the condition to get the range; a drop table if exists t; create table t (id int, value decimal(10,5)); explain format='plan_tree' select count(*) from t join (select t.id, t.value v1 from t join t t1 on t.id = t1.id order by t.value limit 1) v on v.id = t.id and v.v1 = t.value; id task access object operator info StreamAgg root funcs:count(1)->Column └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.id, planner__core__casetest__integration.t.id) eq(planner__core__casetest__integration.t.value, planner__core__casetest__integration.t.value)] ├─Selection(Build) root not(isnull(planner__core__casetest__integration.t.id)), not(isnull(planner__core__casetest__integration.t.value)) │ └─TopN root planner__core__casetest__integration.t.value, offset:0, count:1 │ └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.id, planner__core__casetest__integration.t.id)] │ ├─TableReader(Build) root data:Selection │ │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.id)) │ │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.id)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.id)), not(isnull(planner__core__casetest__integration.t.value)) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select count(*) from t join (select t.id, t.value v1 from t join t t1 on t.id = t1.id order by t.value limit 1) v on v.id = t.id and v.v1 = t.value; id task access object operator info StreamAgg root funcs:count(1)->Column └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.id, planner__core__casetest__integration.t.id) eq(planner__core__casetest__integration.t.value, planner__core__casetest__integration.t.value)] ├─Selection(Build) root not(isnull(planner__core__casetest__integration.t.id)), not(isnull(planner__core__casetest__integration.t.value)) │ └─TopN root planner__core__casetest__integration.t.value, offset:0, count:1 │ └─HashJoin root inner join, equal:[eq(planner__core__casetest__integration.t.id, planner__core__casetest__integration.t.id)] │ ├─TableReader(Build) root data:Selection │ │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.id)) │ │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo │ └─TableReader(Probe) root data:Selection │ └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.id)) │ └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] not(isnull(planner__core__casetest__integration.t.id)), not(isnull(planner__core__casetest__integration.t.value)) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo set tidb_partition_prune_mode='dynamic'; drop table if exists t1, t2_part; create table t1 (a int, b int); create table t2_part (a int, b int, key(a)) partition by hash(a) partitions 4; set @@tidb_skip_missing_partition_stats = off; set @@tidb_opt_fix_control = ""; explain format='plan_tree' select /*+ TIDB_INLJ(t2_part@sel_2), set_var(tidb_hash_join_version=legacy) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20); id task access object operator info HashJoin root anti semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2_part.a)] ├─PartitionUnion(Build) root │ ├─TableReader root data:Projection │ │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ │ └─TableFullScan cop[tikv] table:t2_part, partition:p0 keep order:false, stats:pseudo │ ├─TableReader root data:Projection │ │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ │ └─TableFullScan cop[tikv] table:t2_part, partition:p1 keep order:false, stats:pseudo │ ├─TableReader root data:Projection │ │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ │ └─TableFullScan cop[tikv] table:t2_part, partition:p2 keep order:false, stats:pseudo │ └─TableReader root data:Projection │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ └─TableFullScan cop[tikv] table:t2_part, partition:p3 keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] lt(planner__core__casetest__integration.t1.b, 10) └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1105 disable dynamic pruning due to t2_part has no global stats Warning 1815 Optimizer Hint /*+ INL_JOIN(t2_part) */ or /*+ TIDB_INLJ(t2_part) */ is inapplicable explain format='plan_tree' select /*+ TIDB_INLJ(t2_part@sel_2), set_var(tidb_hash_join_version=optimized) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20); id task access object operator info HashJoin root anti semi join, left side:TableReader, equal:[eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2_part.a)] ├─PartitionUnion(Build) root │ ├─TableReader root data:Projection │ │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ │ └─TableFullScan cop[tikv] table:t2_part, partition:p0 keep order:false, stats:pseudo │ ├─TableReader root data:Projection │ │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ │ └─TableFullScan cop[tikv] table:t2_part, partition:p1 keep order:false, stats:pseudo │ ├─TableReader root data:Projection │ │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ │ └─TableFullScan cop[tikv] table:t2_part, partition:p2 keep order:false, stats:pseudo │ └─TableReader root data:Projection │ └─Projection cop[tikv] planner__core__casetest__integration.t2_part.a │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) │ └─TableFullScan cop[tikv] table:t2_part, partition:p3 keep order:false, stats:pseudo └─TableReader(Probe) root data:Selection └─Selection cop[tikv] lt(planner__core__casetest__integration.t1.b, 10) └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1105 disable dynamic pruning due to t2_part has no global stats Warning 1815 Optimizer Hint /*+ INL_JOIN(t2_part) */ or /*+ TIDB_INLJ(t2_part) */ is inapplicable set @@tidb_opt_fix_control = "44262:ON"; explain format='plan_tree' select /*+ TIDB_INLJ(t2_part@sel_2) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20); id task access object operator info IndexJoin root anti semi join, inner:IndexLookUp, left side:TableReader, outer key:planner__core__casetest__integration.t1.a, inner key:planner__core__casetest__integration.t2_part.a, equal cond:eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2_part.a) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t1.b, 10) │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─IndexLookUp(Probe) root partition:all ├─IndexRangeScan(Build) cop[tikv] table:t2_part, index:a(a) range: decided by [eq(planner__core__casetest__integration.t2_part.a, planner__core__casetest__integration.t1.a)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) └─TableRowIDScan cop[tikv] table:t2_part keep order:false, stats:pseudo set @@tidb_opt_fix_control = ""; set @@tidb_skip_missing_partition_stats = on; explain format='plan_tree' select /*+ TIDB_INLJ(t2_part@sel_2) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20); id task access object operator info IndexJoin root anti semi join, inner:IndexLookUp, left side:TableReader, outer key:planner__core__casetest__integration.t1.a, inner key:planner__core__casetest__integration.t2_part.a, equal cond:eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2_part.a) ├─TableReader(Build) root data:Selection │ └─Selection cop[tikv] lt(planner__core__casetest__integration.t1.b, 10) │ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo └─IndexLookUp(Probe) root partition:all ├─IndexRangeScan(Build) cop[tikv] table:t2_part, index:a(a) range: decided by [eq(planner__core__casetest__integration.t2_part.a, planner__core__casetest__integration.t1.a)], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) └─TableRowIDScan cop[tikv] table:t2_part keep order:false, stats:pseudo set @@tidb_skip_missing_partition_stats = default; drop table if exists t; create table t(a int(11) not null, b int) partition by range (a) (partition p0 values less than (4), partition p1 values less than(10), partition p2 values less than maxvalue); insert into t values (1, 1),(10, 10),(11, 11); set tidb_opt_fix_control='44262:ON'; explain format='plan_tree' select * from t where a in (1, 2,'11'); id task access object operator info TableReader root partition:p0,p2 data:Selection └─Selection cop[tikv] in(planner__core__casetest__integration.t.a, 1, 2, 11) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where a in (17, null); id task access object operator info TableReader root partition:p2 data:Selection └─Selection cop[tikv] in(planner__core__casetest__integration.t.a, 17, NULL) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where a in (16, 'abc'); id task access object operator info TableReader root partition:p0,p2 data:Selection └─Selection cop[tikv] in(planner__core__casetest__integration.t.a, 16, 0) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where a in (15, 0.12, 3.47); id task access object operator info TableReader root partition:p2 data:Selection └─Selection cop[tikv] eq(planner__core__casetest__integration.t.a, 15) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where a in (0.12, 3.47); id task access object operator info TableDual root rows:0 explain format='plan_tree' select * from t where a in (14, floor(3.47)); id task access object operator info TableReader root partition:p0,p2 data:Selection └─Selection cop[tikv] in(planner__core__casetest__integration.t.a, 14, 3) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo explain format='plan_tree' select * from t where b in (3, 4); id task access object operator info TableReader root partition:all data:Selection └─Selection cop[tikv] in(planner__core__casetest__integration.t.b, 3, 4) └─TableFullScan cop[tikv] table:t keep order:false, stats:pseudo set tidb_opt_fix_control=default; drop table if exists pt; create table pt (id int, c int, key i_id(id), key i_c(c)) partition by range (c) ( partition p0 values less than (4), partition p1 values less than (7), partition p2 values less than (10)); set @@tidb_enable_index_merge = 1; set tidb_opt_fix_control='44262:ON'; ## Table reader explain format='plan_tree' select * from pt where c > 10; id task access object operator info TableReader root partition:dual data:Selection └─Selection cop[tikv] gt(planner__core__casetest__integration.pt.c, 10) └─TableFullScan cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select * from pt where c > 8; id task access object operator info TableReader root partition:p2 data:Selection └─Selection cop[tikv] gt(planner__core__casetest__integration.pt.c, 8) └─TableFullScan cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select * from pt where c < 2 or c >= 9; id task access object operator info TableReader root partition:p0,p2 data:Selection └─Selection cop[tikv] or(lt(planner__core__casetest__integration.pt.c, 2), ge(planner__core__casetest__integration.pt.c, 9)) └─TableFullScan cop[tikv] table:pt keep order:false, stats:pseudo ## Index reader explain format='plan_tree' select c from pt; id task access object operator info IndexReader root partition:all index:IndexFullScan └─IndexFullScan cop[tikv] table:pt, index:i_c(c) keep order:false, stats:pseudo explain format='plan_tree' select c from pt where c > 10; id task access object operator info IndexReader root partition:dual index:IndexRangeScan └─IndexRangeScan cop[tikv] table:pt, index:i_c(c) range:(10,+inf], keep order:false, stats:pseudo explain format='plan_tree' select c from pt where c > 8; id task access object operator info IndexReader root partition:p2 index:IndexRangeScan └─IndexRangeScan cop[tikv] table:pt, index:i_c(c) range:(8,+inf], keep order:false, stats:pseudo explain format='plan_tree' select c from pt where c < 2 or c >= 9; id task access object operator info IndexReader root partition:p0,p2 index:IndexRangeScan └─IndexRangeScan cop[tikv] table:pt, index:i_c(c) range:[-inf,2), [9,+inf], keep order:false, stats:pseudo ## Index Lookup explain format='plan_tree' select /*+ use_index(pt, i_id) */ * from pt; id task access object operator info IndexLookUp root partition:all ├─IndexFullScan(Build) cop[tikv] table:pt, index:i_id(id) keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select /*+ use_index(pt, i_id) */ * from pt where id < 4 and c > 10; id task access object operator info IndexLookUp root partition:dual ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_id(id) range:[-inf,4), keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] gt(planner__core__casetest__integration.pt.c, 10) └─TableRowIDScan cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select /*+ use_index(pt, i_id) */ * from pt where id < 10 and c > 8; id task access object operator info IndexLookUp root partition:p2 ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_id(id) range:[-inf,10), keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] gt(planner__core__casetest__integration.pt.c, 8) └─TableRowIDScan cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select /*+ use_index(pt, i_id) */ * from pt where id < 10 and c < 2 or c >= 9; id task access object operator info IndexLookUp root partition:p0,p2 ├─IndexFullScan(Build) cop[tikv] table:pt, index:i_id(id) keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] or(and(lt(planner__core__casetest__integration.pt.id, 10), lt(planner__core__casetest__integration.pt.c, 2)), ge(planner__core__casetest__integration.pt.c, 9)) └─TableRowIDScan cop[tikv] table:pt keep order:false, stats:pseudo ## Partition selection explain format='plan_tree' select * from pt partition (p0) where c > 8; id task access object operator info TableReader root partition:dual data:Selection └─Selection cop[tikv] gt(planner__core__casetest__integration.pt.c, 8) └─TableFullScan cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select c from pt partition (p0, p2) where c > 8; id task access object operator info IndexReader root partition:p2 index:IndexRangeScan └─IndexRangeScan cop[tikv] table:pt, index:i_c(c) range:(8,+inf], keep order:false, stats:pseudo explain format='plan_tree' select /*+ use_index(pt, i_id) */ * from pt partition (p1, p2) where c < 3 and id = 5; id task access object operator info IndexLookUp root partition:dual ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_id(id) range:[5,5], keep order:false, stats:pseudo └─Selection(Probe) cop[tikv] lt(planner__core__casetest__integration.pt.c, 3) └─TableRowIDScan cop[tikv] table:pt keep order:false, stats:pseudo ## Index Merge explain format='plan_tree' select * from pt where id = 4 or c < 7; id task access object operator info IndexMerge root partition:all type: union ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_id(id) range:[4,4], keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_c(c) range:[-inf,7), keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:pt keep order:false, stats:pseudo explain format='plan_tree' select * from pt where id > 4 or c = 7; id task access object operator info IndexMerge root partition:all type: union ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_id(id) range:(4,+inf], keep order:false, stats:pseudo ├─IndexRangeScan(Build) cop[tikv] table:pt, index:i_c(c) range:[7,7], keep order:false, stats:pseudo └─TableRowIDScan(Probe) cop[tikv] table:pt keep order:false, stats:pseudo set tidb_opt_fix_control=default; set @@tidb_enable_index_merge = default; drop table if exists github_events; CREATE TABLE `github_events` ( `id` bigint(20) NOT NULL DEFAULT '0', `type` varchar(29) NOT NULL DEFAULT 'Event', `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00', `repo_id` bigint(20) NOT NULL DEFAULT '0', `repo_name` varchar(140) NOT NULL DEFAULT '', `actor_id` bigint(20) NOT NULL DEFAULT '0', `actor_login` varchar(40) NOT NULL DEFAULT '', `language` varchar(26) NOT NULL DEFAULT '', `additions` bigint(20) NOT NULL DEFAULT '0', `deletions` bigint(20) NOT NULL DEFAULT '0', `action` varchar(11) NOT NULL DEFAULT '', `number` int(11) NOT NULL DEFAULT '0', `commit_id` varchar(40) NOT NULL DEFAULT '', `comment_id` bigint(20) NOT NULL DEFAULT '0', `org_login` varchar(40) NOT NULL DEFAULT '', `org_id` bigint(20) NOT NULL DEFAULT '0', `state` varchar(6) NOT NULL DEFAULT '', `closed_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00', `comments` int(11) NOT NULL DEFAULT '0', `pr_merged_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00', `pr_merged` tinyint(1) NOT NULL DEFAULT '0', `pr_changed_files` int(11) NOT NULL DEFAULT '0', `pr_review_comments` int(11) NOT NULL DEFAULT '0', `pr_or_issue_id` bigint(20) NOT NULL DEFAULT '0', `event_day` date NOT NULL, `event_month` date NOT NULL, `event_year` int(11) NOT NULL, `push_size` int(11) NOT NULL DEFAULT '0', `push_distinct_size` int(11) NOT NULL DEFAULT '0', `creator_user_login` varchar(40) NOT NULL DEFAULT '', `creator_user_id` bigint(20) NOT NULL DEFAULT '0', `pr_or_issue_created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00', KEY `index_github_events_on_id` (`id`), KEY `index_github_events_on_created_at` (`created_at`), KEY `index_github_events_on_repo_id_type_action_month_actor_login` (`repo_id`,`type`,`action`,`event_month`,`actor_login`), KEY `index_ge_on_repo_id_type_action_pr_merged_created_at_add_del` (`repo_id`,`type`,`action`,`pr_merged`,`created_at`,`additions`,`deletions`), KEY `index_ge_on_creator_id_type_action_merged_created_at_add_del` (`creator_user_id`,`type`,`action`,`pr_merged`,`created_at`,`additions`,`deletions`), KEY `index_ge_on_actor_id_type_action_created_at_repo_id_commits` (`actor_id`,`type`,`action`,`created_at`,`repo_id`,`push_distinct_size`), KEY `index_ge_on_repo_id_type_action_created_at_number_pdsize_psize` (`repo_id`,`type`,`action`,`created_at`,`number`,`push_distinct_size`,`push_size`), KEY `index_ge_on_repo_id_type_action_created_at_actor_login` (`repo_id`,`type`,`action`,`created_at`,`actor_login`), KEY `index_ge_on_repo_name_type` (`repo_name`,`type`), KEY `index_ge_on_actor_login_type` (`actor_login`,`type`), KEY `index_ge_on_org_login_type` (`org_login`,`type`), KEY `index_ge_on_language` (`language`), KEY `index_ge_on_org_id_type` (`org_id`,`type`), KEY `index_ge_on_actor_login_lower` ((lower(`actor_login`))), KEY `index_ge_on_repo_name_lower` ((lower(`repo_name`))), KEY `index_ge_on_language_lower` ((lower(`language`))), KEY `index_ge_on_type_action` (`type`,`action`) /*!80000 INVISIBLE */, KEY `index_ge_on_repo_id_type_created_at` (`repo_id`,`type`,`created_at`), KEY `index_ge_on_repo_id_created_at` (`repo_id`,`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY LIST COLUMNS(`type`) (PARTITION `push_event` VALUES IN ('PushEvent'), PARTITION `create_event` VALUES IN ('CreateEvent'), PARTITION `pull_request_event` VALUES IN ('PullRequestEvent'), PARTITION `watch_event` VALUES IN ('WatchEvent'), PARTITION `issue_comment_event` VALUES IN ('IssueCommentEvent'), PARTITION `issues_event` VALUES IN ('IssuesEvent'), PARTITION `delete_event` VALUES IN ('DeleteEvent'), PARTITION `fork_event` VALUES IN ('ForkEvent'), PARTITION `pull_request_review_comment_event` VALUES IN ('PullRequestReviewCommentEvent'), PARTITION `pull_request_review_event` VALUES IN ('PullRequestReviewEvent'), PARTITION `gollum_event` VALUES IN ('GollumEvent'), PARTITION `release_event` VALUES IN ('ReleaseEvent'), PARTITION `member_event` VALUES IN ('MemberEvent'), PARTITION `commit_comment_event` VALUES IN ('CommitCommentEvent'), PARTITION `public_event` VALUES IN ('PublicEvent'), PARTITION `gist_event` VALUES IN ('GistEvent'), PARTITION `follow_event` VALUES IN ('FollowEvent'), PARTITION `event` VALUES IN ('Event'), PARTITION `download_event` VALUES IN ('DownloadEvent'), PARTITION `team_add_event` VALUES IN ('TeamAddEvent'), PARTITION `fork_apply_event` VALUES IN ('ForkApplyEvent')); SELECT repo_id, GROUP_CONCAT( DISTINCT actor_login ORDER BY cnt DESC SEPARATOR ',' ) AS actor_logins FROM ( SELECT ge.repo_id AS repo_id, ge.actor_login AS actor_login, COUNT(*) AS cnt FROM github_events ge WHERE type = 'PullRequestEvent' AND action = 'opened' AND (ge.created_at >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND ge.created_at <= NOW()) GROUP BY ge.repo_id, ge.actor_login ORDER BY cnt DESC ) sub GROUP BY repo_id; repo_id actor_logins drop database if exists testdb; create database testdb; use testdb; drop table if exists `t270`; CREATE TABLE `t270` ( `vkey` int(11) DEFAULT NULL, `pkey` int(11) DEFAULT NULL, `c1128` varchar(100) DEFAULT NULL, `c1129` int(11) DEFAULT NULL, `c1130` varchar(100) DEFAULT NULL, `c1131` double DEFAULT NULL, `c1132` varchar(100) DEFAULT NULL, `c1133` double DEFAULT NULL, `c1134` varchar(100) DEFAULT NULL, `c1135` int(11) DEFAULT NULL ); drop table if exists `t271`; CREATE TABLE `t271` ( `vkey` int(11) DEFAULT NULL, `pkey` int(11) DEFAULT NULL, `c1136` varchar(100) DEFAULT NULL, `c1137` int(11) DEFAULT NULL, `c1138` varchar(100) DEFAULT NULL, `c1139` int(11) DEFAULT NULL, `c1140` double DEFAULT NULL, `c1141` int(11) DEFAULT NULL ); drop table if exists `t272`; CREATE TABLE `t272` ( `vkey` int(11) DEFAULT NULL, `pkey` int(11) DEFAULT NULL, `c1142` int(11) DEFAULT NULL, `c1143` varchar(100) DEFAULT NULL, `c1144` int(11) DEFAULT NULL, `c1145` int(11) DEFAULT NULL, `c1146` varchar(100) DEFAULT NULL, `c1147` double DEFAULT NULL, `c1148` varchar(100) DEFAULT NULL, `c1149` double DEFAULT NULL ); CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `t273_test` (`c0`, `c1`, `c2`, `c3`, `c4`) AS SELECT AVG(37) OVER (PARTITION BY `ref_0`.`c1136` ORDER BY `ref_0`.`vkey` DESC,`ref_0`.`pkey` DESC,`ref_0`.`c1136` DESC,`ref_0`.`c1137`,`ref_0`.`c1138` DESC,`ref_0`.`c1139` DESC,`ref_0`.`c1140` DESC,`ref_0`.`c1141`) AS `c0`,COALESCE(`ref_0`.`c1137`, `ref_0`.`c1141`) AS `c1`,`ref_0`.`vkey` AS `c2`,`ref_0`.`pkey` AS `c3`,`ref_0`.`c1138` AS `c4` FROM `testdb`.`t271` AS `ref_0` WHERE EXISTS (SELECT `subq_0`.`c2` AS `c0`,`subq_0`.`c0` AS `c1`,`subq_0`.`c0` AS `c2`,`subq_0`.`c0` AS `c3`,CASE WHEN EXISTS (SELECT `ref_9`.`c1131` AS `c0`,`ref_9`.`c1131` AS `c1`,(FALSE) XOR (((-45)=(-69)) OR ((-0)>(-71))) AS `c2`,`ref_9`.`c1133` AS `c3`,`ref_9`.`c1128` AS `c4`,-0 AS `c5`,1 AS `c6`,`ref_9`.`c1132` AS `c7`,`ref_9`.`c1131` AS `c8`,`ref_9`.`c1130` AS `c9`,NULL AS `c10` FROM `testdb`.`t270` AS `ref_9` WHERE (-0)<(-8) UNION ALL SELECT `ref_0`.`c1140` AS `c0`,`ref_11`.`c1133` AS `c1`,(NULL)<(NULL) AS `c2`,`ref_0`.`c1140` AS `c3`,`ref_0`.`c1136` AS `c4`,95 AS `c5`,NOT (_UTF8MB4'mum#M' LIKE _UTF8MB4'%_U') AS `c6`,`ref_11`.`c1128` AS `c7`,`ref_11`.`c1131` AS `c8`,(SELECT `c1143` AS `c1143` FROM `testdb`.`t272` ORDER BY `c1143` LIMIT 3,1) AS `c9`,97 AS `c10` FROM `testdb`.`t270` AS `ref_11` WHERE NOT (TRUE)) THEN _UTF8MB4'xf' ELSE _UTF8MB4'>c' END LIKE _UTF8MB4'_^^' AS `c4`,`subq_0`.`c1` AS `c5`,`ref_0`.`vkey` AS `c6`,((`subq_0`.`c1`)=(SELECT `ref_12`.`c1132` AS `c0` FROM `testdb`.`t270` AS `ref_12` WHERE TRUE ORDER BY `c0` DESC LIMIT 1)) XOR ((`ref_0`.`pkey`)>=(SELECT (SELECT `vkey` AS `vkey` FROM `testdb`.`t271` ORDER BY `vkey` LIMIT 1,1) AS `c0` FROM `testdb`.`t271` AS `ref_13` WHERE (-24)<=((SELECT COUNT(`c1140`) AS `count(c1140)` FROM `testdb`.`t271`)) ORDER BY `c0` LIMIT 1)) AS `c7`,`ref_0`.`pkey` AS `c8`,`subq_0`.`c2` AS `c9`,`ref_0`.`vkey` AS `c10`,`ref_0`.`c1139` AS `c11`,TRUE AS `c12`,`subq_0`.`c0` AS `c13`,`subq_0`.`c2` AS `c14`,`subq_0`.`c2` AS `c15`,FALSE AS `c16`,CASE WHEN ((FALSE) OR ((((FALSE) XOR (((-73)<(-91)) OR (((-0) BETWEEN (-0) AND (-0)) AND ((NULL) OR ((0)>((SELECT COUNT(`c1131`) AS `count(c1131)` FROM `testdb`.`t270`))))))) AND ((-19)>(NULL))) OR (((77)<(73)) AND (NOT (((73) IN (SELECT 0 AS `c0` FROM `testdb`.`t271` AS `ref_14` WHERE (NULL) AND (NULL) EXCEPT SELECT NULL AS `c0` FROM `testdb`.`t270` AS `ref_15` WHERE (`ref_15`.`c1131`)!=(SELECT `ref_15`.`c1133` AS `c0` FROM `testdb`.`t270` AS `ref_16` WHERE _UTF8MB4'$@-X' LIKE _UTF8MB4'__%' ORDER BY `c0` DESC LIMIT 1))) IS TRUE))))) OR (NOT ((-24)<=(-43))) THEN `subq_0`.`c1` ELSE `subq_0`.`c2` END AS `c17`,`subq_0`.`c1` AS `c18`,`subq_0`.`c0` AS `c19`,`subq_0`.`c0` AS `c20`,`subq_0`.`c2` AS `c21`,`subq_0`.`c0` AS `c22`,`subq_0`.`c2` AS `c23`,`subq_0`.`c0` AS `c24`,`ref_0`.`c1141` AS `c25` FROM (SELECT DISTINCT TRUE AS `c0`,`ref_1`.`c1143` AS `c1`,`ref_1`.`c1146` AS `c2` FROM `testdb`.`t272` AS `ref_1` WHERE NOT (((`ref_0`.`c1136`)!=(SELECT `ref_2`.`c1146` AS `c0` FROM `testdb`.`t272` AS `ref_2` WHERE (62) BETWEEN ((SELECT COUNT(`c1147`) AS `count(c1147)` FROM `testdb`.`t272`)) AND (-0) ORDER BY `c0` LIMIT 1)) XOR ((-0) BETWEEN (0) AND (-0)))) AS `subq_0` WHERE (CHAR_LENGTH(CASE WHEN ((`subq_0`.`c0`) IS NOT NULL) OR ((`ref_0`.`c1138`)>(SELECT `ref_0`.`c1138` AS `c0` FROM `testdb`.`t272` AS `ref_3` WHERE FALSE ORDER BY `c0` DESC LIMIT 1)) THEN _UTF8MB4'' ELSE _UTF8MB4'tL' END)) BETWEEN (ABS(46%-11)) AND (CASE WHEN (((((`subq_0`.`c2`) IN (SELECT `ref_4`.`c1134` AS `c0` FROM `testdb`.`t270` AS `ref_4` WHERE (NULL LIKE _UTF8MB4'%Ny') OR (EXISTS (SELECT DISTINCT `ref_5`.`c1136` AS `c0`,`ref_5`.`c1140` AS `c1` FROM `testdb`.`t271` AS `ref_5` WHERE FALSE UNION ALL SELECT `ref_4`.`c1130` AS `c0`,`ref_4`.`c1131` AS `c1` FROM `testdb`.`t271` AS `ref_6` WHERE (-97) BETWEEN (73) AND (-10))) UNION ALL SELECT `ref_7`.`c1138` AS `c0` FROM `testdb`.`t271` AS `ref_7` WHERE FALSE)) IS TRUE) OR (NULL)) AND ((NULL)>=((SELECT COUNT(`c1140`) AS `count(c1140)` FROM `testdb`.`t271`)))) XOR (((`ref_0`.`vkey`) IN (SELECT `ref_8`.`c1145` AS `c0` FROM `testdb`.`t272` AS `ref_8` WHERE ((FALSE) AND (NULL)) OR ((`ref_8`.`c1144`) IS NULL))) IS TRUE) THEN 87 ELSE CASE WHEN ((`ref_0`.`c1138`) IS NULL) OR ((-22)!=(-0)) THEN 17 ELSE -67 END END)) ORDER BY `c0` DESC,`c1` DESC,`c2`,`c3`,`c4` DESC; select (select subq_1.c0 as c0 from t273_test as ref_84 where exists ( select (select ref_86.c1147 as c0 from t272 as ref_86 where (subq_1.c0) > (subq_1.c0) window w0 as (partition by ref_86.c1147 order by ref_86.c1143 desc) order by c0 limit 1 ) as c3, (select subq_1.c0 as c0 from t273_test as ref_89 order by c0 limit 1) as c4 from t271 as ref_85 ) order by c0 desc limit 1) as c1 from (select 1 as c0) as subq_1; c1 NULL select (select subq_1.c0 as c0 from t271 as ref_84 where exists ( select (select ref_86.c1147 as c0 from t272 as ref_86 where (subq_1.c0) > (subq_1.c0) window w0 as (partition by ref_86.c1147 order by ref_86.c1143 desc) order by c0 limit 1 ) as c3, (select subq_1.c0 as c0 from t271 as ref_89 order by c0 limit 1) as c4 from t271 as ref_85 ) order by c0 desc limit 1) as c1 from (select 1 as c0) as subq_1; c1 NULL use test; drop table if exists tt; create table tt(a bigint, b bigint, c bigint, d bigint, e bigint, primary key(c,d)); explain format='plan_tree' update tt, (select 1 as c1 ,2 as c2 ,3 as c3, 4 as c4 union all select 2,3,4,5 union all select 3,4,5,6) tmp set tt.a=tmp.c1, tt.b=tmp.c2 where tt.c=tmp.c3 and tt.d=tmp.c4 and (tt.c,tt.d) in ((11,111),(22,222),(33,333),(44,444)); id task access object operator info Update root N/A └─IndexJoin root inner join, inner:TableReader, outer key:Column, Column, inner key:test.tt.c, test.tt.d, equal cond:eq(Column, test.tt.c), eq(Column, test.tt.d) ├─Union(Build) root │ ├─Projection root 1->Column, 2->Column, 3->Column, 4->Column │ │ └─TableDual root rows:1 │ ├─Projection root 2->Column, 3->Column, 4->Column, 5->Column │ │ └─TableDual root rows:1 │ └─Projection root 3->Column, 4->Column, 5->Column, 6->Column │ └─TableDual root rows:1 └─TableReader(Probe) root data:Selection └─Selection cop[tikv] or(or(and(eq(test.tt.c, 11), eq(test.tt.d, 111)), and(eq(test.tt.c, 22), eq(test.tt.d, 222))), or(and(eq(test.tt.c, 33), eq(test.tt.d, 333)), and(eq(test.tt.c, 44), eq(test.tt.d, 444)))) └─TableRangeScan cop[tikv] table:tt range: decided by [eq(test.tt.c, Column) eq(test.tt.d, Column)], keep order:false, stats:pseudo CREATE TABLE test_62564(c0 DECIMAL); INSERT INTO test_62564 VALUES (0); SELECT * FROM test_62564 WHERE CAST((CASE test_62564.c0 WHEN test_62564.c0 THEN CAST(test_62564.c0 AS TIME) ELSE NULL END ) AS DATE); c0 0 SET @b = NULL; PREPARE prepare_query FROM 'SELECT * FROM test_62564 WHERE CAST((CASE test_62564.c0 WHEN test_62564.c0 THEN CAST(test_62564.c0 AS TIME) ELSE ? END ) AS DATE)'; EXECUTE prepare_query USING @b; c0 0 SET tidb_mview_enable = OFF; CREATE TABLE t_commit_ts (a INT PRIMARY KEY, b INT, c INT, INDEX idx_b(b), INDEX idx_c(c)); INSERT INTO t_commit_ts VALUES (1, 1, 2), (2, 2, 1); explain format = 'plan_tree' select _tidb_commit_ts from t_commit_ts where a = 1; id task access object operator info TableReader root data:Projection └─Projection cop[tikv] test.t_commit_ts._tidb_commit_ts └─TableRangeScan cop[tikv] table:t_commit_ts range:[1,1], keep order:false, stats:pseudo explain format = 'plan_tree' select _tidb_commit_ts from t_commit_ts where a in (1, 2); id task access object operator info TableReader root data:Projection └─Projection cop[tikv] test.t_commit_ts._tidb_commit_ts └─TableRangeScan cop[tikv] table:t_commit_ts range:[1,1], [2,2], keep order:false, stats:pseudo select _tidb_commit_ts > 0 as valid_commit_ts from t_commit_ts use index (idx_b) where b = 1; valid_commit_ts 1 select _tidb_commit_ts > 0 as valid_commit_ts from t_commit_ts where a = 1; valid_commit_ts 1 select a from t_commit_ts where _tidb_commit_ts > 0 order by a; a 1 2 select _tidb_commit_ts > 0 as valid_commit_ts from t_commit_ts union all select _tidb_commit_ts > 0 from t_commit_ts; valid_commit_ts 1 1 1 1 explain format = 'plan_tree' select /*+ use_index_merge(t_commit_ts, idx_b, idx_c) */ _tidb_commit_ts from t_commit_ts where b = 1 or c = 1; Error 1815 (HY000): Internal : Can't find a proper physical plan for this query update t_commit_ts set b = b + 10 where a = 1 and _tidb_commit_ts > 0; update t_commit_ts set b = 20 + (_tidb_commit_ts > 0) where a = 2; update t_commit_ts set b = b + 100 where _tidb_commit_ts = 0; select a, b from t_commit_ts order by a; a b 1 11 2 21 create table t_commit_ts_copy (a int, ts bigint unsigned); insert into t_commit_ts_copy select a, _tidb_commit_ts from t_commit_ts where _tidb_commit_ts > 0; select a, ts > 0 from t_commit_ts_copy order by a; a ts > 0 1 1 2 1 update t_commit_ts t join t_commit_ts_copy s on t.a = s.a set t.c = 10 + (s._tidb_commit_ts > 0), s.ts = t._tidb_commit_ts; select t.a, t.c, s.ts > 0 from t_commit_ts t join t_commit_ts_copy s on t.a = s.a order by t.a; a c s.ts > 0 1 11 1 2 11 1 update t_commit_ts set _tidb_commit_ts = 1; Error 1815 (HY000): Usage of column name '_tidb_commit_ts' is not supported for now insert into t_commit_ts (_tidb_commit_ts) select a from t_commit_ts_copy; Error 1815 (HY000): Usage of column name '_tidb_commit_ts' is not supported for now insert into t_commit_ts (a) values (1) on duplicate key update _tidb_commit_ts = 1; Error 1815 (HY000): Usage of column name '_tidb_commit_ts' is not supported for now delete from t_commit_ts where _tidb_commit_ts = 0; select count(*) from t_commit_ts; count(*) 2 delete from t_commit_ts where _tidb_commit_ts > 0 limit 1; select count(*) from t_commit_ts; count(*) 1 delete from t_commit_ts where _tidb_commit_ts > 0; select count(*) from t_commit_ts; count(*) 0