use test; drop table if exists t1, t2, t3, t4; create table t1 (c1 int primary key, c2 int, c3 int, index c2 (c2)); create table t2 (c1 int unique, c2 int); insert into t2 values(1, 0), (2, 1); create table t3 (a bigint, b bigint, c bigint, d bigint); create table t4 (a int, b int, c int, index idx(a, b), primary key(a)); create index expr_idx on t4((a+b+1)); set @@session.tidb_opt_agg_push_down = 1; set @@session.tidb_opt_insubq_to_join_and_agg=1; set @@session.tidb_hashagg_partial_concurrency = 1; set @@session.tidb_hashagg_final_concurrency = 1; set @@session.tidb_window_concurrency = 1; explain format = 'brief' select * from t3 where exists (select s.a from t3 s having sum(s.a) = t3.a ); id estRows task access object operator info HashJoin 8000.00 root semi join, equal:[eq(Column#13, Column#11)] ├─StreamAgg(Build) 1.00 root funcs:sum(Column#16)->Column#11 │ └─TableReader 1.00 root data:StreamAgg │ └─StreamAgg 1.00 cop[tikv] funcs:sum(test.t3.a)->Column#16 │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:false, stats:pseudo └─Projection(Probe) 10000.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d, cast(test.t3.a, decimal(20,0) BINARY)->Column#13 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo explain format = 'brief' select * from t1; id estRows task access object operator info TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c2; id estRows task access object operator info IndexLookUp 10000.00 root ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:true, stats:pseudo └─TableRowIDScan(Probe) 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t2 order by c2; id estRows task access object operator info Sort 10000.00 root test.t2.c2 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where t1.c1 > 0; id estRows task access object operator info TableReader 3333.33 root data:TableRangeScan └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(0,+inf], keep order:false, stats:pseudo explain format = 'brief' select t1.c1, t1.c2 from t1 where t1.c2 = 1; id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan └─IndexRangeScan 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo explain format = 'brief' select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id estRows task access object operator info HashJoin 4166.67 root left outer join, equal:[eq(test.t1.c2, test.t2.c1)] ├─TableReader(Build) 3333.33 root data:TableRangeScan │ └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo └─TableReader(Probe) 9990.00 root data:Selection └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c1)) └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' update t1 set t1.c2 = 2 where t1.c1 = 1; id estRows task access object operator info Update N/A root N/A └─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' delete from t1 where t1.c2 = 1; id estRows task access object operator info Delete N/A root N/A └─IndexLookUp 10.00 root ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id estRows task access object operator info Projection 9990.00 root Column#7 └─HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] ├─HashAgg(Build) 7992.00 root group by:test.t2.c2, funcs:count(Column#9)->Column#8, funcs:firstrow(test.t2.c2)->test.t2.c2 │ └─TableReader 7992.00 root data:HashAgg │ └─HashAgg 7992.00 cop[tikv] group by:test.t2.c2, funcs:count(test.t2.c2)->Column#9 │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 10000.00 cop[tikv] table:b keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:a keep order:false, stats:pseudo explain format = 'brief' select * from t2 order by t2.c2 limit 0, 1; id estRows task access object operator info TopN 1.00 root test.t2.c2, offset:0, count:1 └─TableReader 1.00 root data:TopN └─TopN 1.00 cop[tikv] test.t2.c2, offset:0, count:1 └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where c1 > 1 and c2 = 1 and c3 < 1; id estRows task access object operator info IndexLookUp 11.08 root ├─IndexRangeScan(Build) 33.33 cop[tikv] table:t1, index:c2(c2) range:(1 1,1 +inf], keep order:false, stats:pseudo └─Selection(Probe) 11.08 cop[tikv] lt(test.t1.c3, 1) └─TableRowIDScan 33.33 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where c1 = 1 and c2 > 1; id estRows task access object operator info Selection 0.33 root gt(test.t1.c2, 1) └─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info StreamAgg 1.00 root funcs:sum(Column#13)->Column#11 └─Projection 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select c1 from t1 where c1 in (select c2 from t2); id estRows task access object operator info HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] ├─HashAgg(Build) 7992.00 root group by:test.t2.c2, funcs:firstrow(test.t2.c2)->test.t2.c2 │ └─TableReader 9990.00 root data:Selection │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) from t1; id estRows task access object operator info Projection 12500.00 root ifnull(Column#10, 0)->Column#10 └─MergeJoin 12500.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1 ├─Projection(Build) 10000.00 root 1->Column#10, test.t1.c1 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:true, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo explain format = 'brief' select * from information_schema.columns; id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#11 └─Apply 10000.00 root CARTESIAN left outer join ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─Limit(Probe) 1.00 root offset:0, count:1 └─Projection 1.00 root test.t2.c1, test.t2.c2 └─IndexLookUp 1.00 root ├─Limit(Build) 1.00 cop[tikv] offset:0, count:1 │ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:c1(c1) range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true, stats:pseudo └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c1 desc 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 └─TableFullScan 1.00 cop[tikv] table:t1 keep order:true, desc, stats:pseudo explain format = 'brief' select * from t4 use index(idx) where a > 1 and b > 1 and c > 1 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─IndexLookUp 1.00 root ├─Selection(Build) 3.00 cop[tikv] gt(test.t4.b, 1) │ └─IndexRangeScan 9.00 cop[tikv] table:t4, index:idx(a, b) range:(1,+inf], keep order:false, stats:pseudo └─Limit(Probe) 1.00 cop[tikv] offset:0, count:1 └─Selection 1.00 cop[tikv] gt(test.t4.c, 1) └─TableRowIDScan 3.00 cop[tikv] table:t4 keep order:false, stats:pseudo explain format = 'brief' select * from t4 where a > 1 and c > 1 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] gt(test.t4.c, 1) └─TableRangeScan 3.00 cop[tikv] table:t4 range:(1,+inf], keep order:false, stats:pseudo explain format = 'brief' select ifnull(null, t1.c1) from t1; id estRows task access object operator info TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select if(10, t1.c1, t1.c2) from t1; id estRows task access object operator info TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select c1 from t2 union select c1 from t2 union all select c1 from t2; id estRows task access object operator info Union 26000.00 root ├─HashAgg 16000.00 root group by:Column#10, funcs:firstrow(Column#12)->Column#10 │ └─Union 16000.00 root │ ├─StreamAgg 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#12, funcs:firstrow(test.t2.c1)->Column#10 │ │ └─IndexReader 10000.00 root index:IndexFullScan │ │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo │ └─StreamAgg 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#12, funcs:firstrow(test.t2.c1)->Column#10 │ └─IndexReader 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo └─IndexReader 10000.00 root index:IndexFullScan └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo explain format = 'brief' select c1 from t2 union all select c1 from t2 union select c1 from t2; id estRows task access object operator info HashAgg 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#10 └─Union 24000.00 root ├─StreamAgg 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10 │ └─IndexReader 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo ├─StreamAgg 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10 │ └─IndexReader 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo └─StreamAgg 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10 └─IndexReader 10000.00 root index:IndexFullScan └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo select * from information_schema.tidb_indexes where table_name='t4'; TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE CLUSTERED test t4 0 PRIMARY 1 a NULL NULL 0 YES YES test t4 1 idx 1 a NULL NULL 1 YES NO test t4 1 idx 2 b NULL NULL 1 YES NO test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 2 YES NO explain format = 'brief' select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2; id estRows task access object operator info StreamAgg 1.00 root funcs:count(1)->Column#5 └─StreamAgg 1.00 root funcs:count(Column#9)->Column#7 └─TableReader 1.00 root data:StreamAgg └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#9 └─Selection 10.00 cop[tikv] eq(test.t1.c3, 100) └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select 1 from (select count(c2), count(c3) from t1) k; id estRows task access object operator info Projection 1.00 root 1->Column#6 └─StreamAgg 1.00 root funcs:count(Column#14)->Column#9 └─TableReader 1.00 root data:StreamAgg └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#14 └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(1) from (select max(c2), count(c3) as m from t1) k; id estRows task access object operator info StreamAgg 1.00 root funcs:count(1)->Column#6 └─StreamAgg 1.00 root funcs:count(Column#13)->Column#8 └─TableReader 1.00 root data:StreamAgg └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#13 └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(1) from (select count(c2) from t1 group by c3) k; id estRows task access object operator info StreamAgg 1.00 root funcs:count(1)->Column#5 └─HashAgg 8000.00 root group by:test.t1.c3, funcs:count(Column#9)->Column#7 └─TableReader 8000.00 root data:HashAgg └─HashAgg 8000.00 cop[tikv] group by:test.t1.c3, funcs:count(1)->Column#9 └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo set @@session.tidb_opt_insubq_to_join_and_agg=0; explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info StreamAgg 1.00 root funcs:sum(Column#13)->Column#11 └─Projection 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select 1 in (select c2 from t2) from t1; id estRows task access object operator info HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select sum(6 in (select c2 from t2)) from t1; id estRows task access object operator info StreamAgg 1.00 root funcs:sum(Column#13)->Column#11 └─Projection 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format="dot" select sum(t1.c1 in (select c1 from t2)) from t1; dot contents digraph StreamAgg_10 { subgraph cluster10{ node [style=filled, color=lightgrey] color=black label = "root" "StreamAgg_10" -> "Projection_21" "Projection_21" -> "HashJoin_20" "HashJoin_20" -> "TableReader_13" "HashJoin_20" -> "IndexReader_19" } subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" "TableFullScan_12" } subgraph cluster18{ node [style=filled, color=lightgrey] color=black label = "cop" "IndexFullScan_18" } "TableReader_13" -> "TableFullScan_12" "IndexReader_19" -> "IndexFullScan_18" } explain format="dot" select 1 in (select c2 from t2) from t1; dot contents digraph HashJoin_8 { subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "root" "HashJoin_8" -> "TableReader_10" "HashJoin_8" -> "TableReader_14" } subgraph cluster9{ node [style=filled, color=lightgrey] color=black label = "cop" "TableFullScan_9" } subgraph cluster13{ node [style=filled, color=lightgrey] color=black label = "cop" "TableFullScan_13" } "TableReader_10" -> "TableFullScan_9" "TableReader_14" -> "TableFullScan_13" } drop table if exists t1, t2, t3, t4; drop table if exists t; create table t(a int primary key, b int, c int, index idx(b)); explain format = 'brief' select t.c in (select count(*) from t s ignore index(idx), t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info Projection 10000.00 root Column#17 └─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 12.50 root inner join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 1.00 root data:TableRangeScan │ └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo └─TableReader(Probe) 1.00 root data:TableRangeScan └─TableRangeScan 1.00 cop[tikv] table:s range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t; id estRows task access object operator info Projection 10000.00 root Column#17 └─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─IndexJoin 12.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) ├─IndexReader(Build) 10.00 root index:IndexRangeScan │ └─IndexRangeScan 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo └─TableReader(Probe) 1.00 root data:TableRangeScan └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false, stats:pseudo explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t; id estRows task access object operator info Projection 10000.00 root Column#17 └─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─IndexJoin 12.49 root inner join, inner:TableReader, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) ├─IndexLookUp(Build) 9.99 root │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo │ └─Selection(Probe) 9.99 cop[tikv] not(isnull(test.t.c)) │ └─TableRowIDScan 10.00 cop[tikv] table:s keep order:false, stats:pseudo └─TableReader(Probe) 1.00 root data:TableRangeScan └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.c], keep order:false, stats:pseudo insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain format = 'brief' select t.c in (select count(*) from t s, t t1 where s.b = t.a and s.b = 3 and s.a = t1.a) from t; id estRows task access object operator info Projection 5.00 root Column#17 └─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 2.40 root inner join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 4.00 root data:Selection │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:true └─IndexReader(Probe) 2.40 root index:Selection └─Selection 2.40 cop[tikv] eq(3, test.t.a) └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain format = 'brief' select t.c in (select count(*) from t s left join t t1 on s.a = t1.a where 3 = t.a and s.b = 3) from t; id estRows task access object operator info Projection 5.00 root Column#17 └─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 2.40 root left outer join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 4.00 root data:Selection │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:true └─IndexReader(Probe) 2.40 root index:Selection └─Selection 2.40 cop[tikv] eq(3, test.t.a) └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain format = 'brief' select t.c in (select count(*) from t s right join t t1 on s.a = t1.a where 3 = t.a and t1.b = 3) from t; id estRows task access object operator info Projection 5.00 root Column#17 └─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 2.40 root right outer join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 4.00 root data:Selection │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) │ └─TableFullScan 5.00 cop[tikv] table:s keep order:true └─IndexReader(Probe) 2.40 root index:Selection └─Selection 2.40 cop[tikv] eq(3, test.t.a) └─IndexRangeScan 3.00 cop[tikv] table:t1, index:idx(b) range:[3,3], keep order:true drop table if exists t; create table t(a int unsigned not null); explain format = 'brief' select t.a = '123455' from t; id estRows task access object operator info Projection 10000.00 root eq(test.t.a, 123455)->Column#3 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select t.a > '123455' from t; id estRows task access object operator info Projection 10000.00 root gt(test.t.a, 123455)->Column#3 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select t.a != '123455' from t; id estRows task access object operator info Projection 10000.00 root ne(test.t.a, 123455)->Column#3 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select t.a = 12345678912345678998789678687678.111 from t; id estRows task access object operator info Projection 10000.00 root 0->Column#3 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; create table t(a bigint, b bigint, index idx(a, b)); explain format = 'brief' select * from t where a in (1, 2) and a in (1, 3); id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan └─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(a, b) range:[1,1], keep order:false, stats:pseudo explain format = 'brief' select * from t where b in (1, 2) and b in (1, 3); id estRows task access object operator info TableReader 10.00 root data:Selection └─Selection 10.00 cop[tikv] in(test.t.b, 1, 2), in(test.t.b, 1, 3) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t where a = 1 and a = 1; id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan └─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(a, b) range:[1,1], keep order:false, stats:pseudo explain format = 'brief' select * from t where a = 1 and a = 2; id estRows task access object operator info TableDual 8000.00 root rows:0 explain format = 'brief' select * from t where b = 1 and b = 2; id estRows task access object operator info TableDual 8000.00 root rows:0 explain format = 'brief' select * from t t1 join t t2 where t1.b = t2.b and t2.b is null; id estRows task access object operator info Projection 0.00 root test.t.a, test.t.b, test.t.a, test.t.b └─HashJoin 0.00 root inner join, equal:[eq(test.t.b, test.t.b)] ├─TableReader(Build) 0.00 root data:Selection │ └─Selection 0.00 cop[tikv] isnull(test.t.b), not(isnull(test.t.b)) │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 9990.00 root data:Selection └─Selection 9990.00 cop[tikv] not(isnull(test.t.b)) └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t t1 where not exists (select * from t t2 where t1.b = t2.b); id estRows task access object operator info HashJoin 8000.00 root anti semi join, equal:[eq(test.t.b, test.t.b)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo drop table if exists t; create table t(a bigint primary key); explain format = 'brief' select * from t where a = 1 and a = 2; id estRows task access object operator info TableDual 8000.00 root rows:0 explain format = 'brief' select null or a > 1 from t; id estRows task access object operator info Projection 10000.00 root or(, gt(test.t.a, 1))->Column#2 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t where a = 1 for update; id estRows task access object operator info Point_Get 1.00 root table:t handle:1, lock drop table if exists ta, tb; create table ta (a varchar(20)); create table tb (a varchar(20)); begin; insert tb values ('1'); explain format = 'brief' select * from ta where a = 1; id estRows task access object operator info TableReader 8000.00 root data:Selection └─Selection 8000.00 cop[tikv] eq(cast(test.ta.a, double BINARY), 1) └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo rollback; drop table if exists t1, t2; create table t1(a int, b int, c int, primary key(a, b)); create table t2(a int, b int, c int, primary key(a)); explain format = 'brief' select t1.a, t1.b from t1 left outer join t2 on t1.a = t2.a; id estRows task access object operator info IndexReader 10000.00 root index:IndexFullScan └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(a, b) keep order:false, stats:pseudo explain format = 'brief' select distinct t1.a, t1.b from t1 left outer join t2 on t1.a = t2.a; id estRows task access object operator info IndexReader 10000.00 root index:IndexFullScan └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(a, b) keep order:false, stats:pseudo CREATE TABLE `test01` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `stat_date` int(11) NOT NULL DEFAULT '0', `show_date` varchar(20) NOT NULL DEFAULT '', `region_id` bigint(20) unsigned NOT NULL DEFAULT '0', `period` tinyint(3) unsigned NOT NULL DEFAULT '0', `registration_num` bigint(20) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; CREATE TABLE `test02` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `region_name` varchar(128) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; explain format = 'brief' SELECT COUNT(1) FROM (SELECT COALESCE(b.region_name, '不详') region_name, SUM(a.registration_num) registration_num FROM (SELECT stat_date, show_date, region_id, 0 registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202 UNION ALL SELECT stat_date, show_date, region_id, registration_num registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202) a LEFT JOIN test02 b ON a.region_id = b.id WHERE registration_num > 0 AND a.stat_date >= '20191202' AND a.stat_date <= '20191202' GROUP BY a.stat_date , a.show_date , COALESCE(b.region_name, '不详') ) JLS; id estRows task access object operator info StreamAgg 1.00 root funcs:count(1)->Column#22 └─HashAgg 8000.00 root group by:Column#32, Column#33, Column#34, funcs:count(1)->Column#31 └─Projection 10000.01 root Column#14, Column#15, coalesce(test.test02.region_name, 不详)->Column#34 └─HashJoin 10000.01 root left outer join, equal:[eq(Column#16, test.test02.id)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:b keep order:false, stats:pseudo └─Union(Probe) 8000.01 root ├─TableDual 8000.00 root rows:0 └─Projection 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id └─TableReader 0.01 root data:Selection └─Selection 0.01 cop[tikv] eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), ge(test.test01.stat_date, 20191202), gt(cast(test.test01.registration_num, bigint(20) BINARY), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202) └─TableFullScan 10000.00 cop[tikv] table:test01 keep order:false, stats:pseudo drop table if exists t; create table t(a int, nb int not null, nc int not null); explain format = 'brief' select ifnull(a, 0) from t; id estRows task access object operator info Projection 10000.00 root ifnull(test.t.a, 0)->Column#5 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select ifnull(nb, 0) from t; id estRows task access object operator info TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select ifnull(nb, 0), ifnull(nc, 0) from t; id estRows task access object operator info TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select ifnull(a, 0), ifnull(nb, 0) from t; id estRows task access object operator info Projection 10000.00 root ifnull(test.t.a, 0)->Column#5, test.t.nb └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select ifnull(nb, 0), ifnull(nb, 0) from t; id estRows task access object operator info Projection 10000.00 root test.t.nb, test.t.nb └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select 1+ifnull(nb, 0) from t; id estRows task access object operator info Projection 10000.00 root plus(1, test.t.nb)->Column#5 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select 1+ifnull(a, 0) from t; id estRows task access object operator info Projection 10000.00 root plus(1, ifnull(test.t.a, 0))->Column#5 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select 1+ifnull(nb, 0) from t where nb=1; id estRows task access object operator info Projection 10.00 root plus(1, test.t.nb)->Column#5 └─TableReader 10.00 root data:Selection └─Selection 10.00 cop[tikv] eq(test.t.nb, 1) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t ta left outer join t tb on ta.nb = tb.nb and ta.a > 1 where ifnull(ta.nb, 1) or ta.nb is null; id estRows task access object operator info HashJoin 8320.83 root left outer join, equal:[eq(test.t.nb, test.t.nb)], left cond:[gt(test.t.a, 1)] ├─TableReader(Build) 6656.67 root data:Selection │ └─Selection 6656.67 cop[tikv] or(test.t.nb, 0) │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo └─TableReader(Probe) 6656.67 root data:Selection └─Selection 6656.67 cop[tikv] or(test.t.nb, 0) └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo explain format = 'brief' select * from t ta right outer join t tb on ta.nb = tb.nb and ta.a > 1 where ifnull(tb.nb, 1) or tb.nb is null; id estRows task access object operator info HashJoin 6656.67 root right outer join, equal:[eq(test.t.nb, test.t.nb)] ├─TableReader(Build) 2218.89 root data:Selection │ └─Selection 2218.89 cop[tikv] gt(test.t.a, 1), or(test.t.nb, 0) │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo └─TableReader(Probe) 6656.67 root data:Selection └─Selection 6656.67 cop[tikv] or(test.t.nb, 0) └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain format = 'brief' select * from t ta inner join t tb on ta.nb = tb.nb and ta.a > 1 where ifnull(tb.nb, 1) or tb.nb is null; id estRows task access object operator info HashJoin 2773.61 root inner join, equal:[eq(test.t.nb, test.t.nb)] ├─TableReader(Build) 2218.89 root data:Selection │ └─Selection 2218.89 cop[tikv] gt(test.t.a, 1), or(test.t.nb, 0) │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo └─TableReader(Probe) 6656.67 root data:Selection └─Selection 6656.67 cop[tikv] or(test.t.nb, 0) └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain format = 'brief' select ifnull(t.nc, 1) in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info Projection 10000.00 root Column#22 └─Apply 10000.00 root left outer semi join, equal:[eq(test.t.nc, Column#21)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─HashAgg(Probe) 1.00 root funcs:count(Column#23)->Column#21 └─HashJoin 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] ├─HashAgg(Build) 7.99 root group by:test.t.a, funcs:count(Column#24)->Column#23, funcs:firstrow(test.t.a)->test.t.a │ └─TableReader 7.99 root data:HashAgg │ └─HashAgg 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#24 │ └─Selection 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) 9.99 root data:Selection └─Selection 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) └─TableFullScan 10000.00 cop[tikv] table:s keep order:false, stats:pseudo explain format = 'brief' select * from t ta left outer join t tb on ta.nb = tb.nb and ta.a > 1 where ifnull(tb.a, 1) or tb.a is null; id estRows task access object operator info Selection 10000.00 root or(ifnull(test.t.a, 1), isnull(test.t.a)) └─HashJoin 12500.00 root left outer join, equal:[eq(test.t.nb, test.t.nb)], left cond:[gt(test.t.a, 1)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo explain format = 'brief' select * from t ta right outer join t tb on ta.nb = tb.nb and ta.a > 1 where ifnull(tb.a, 1) or tb.a is null; id estRows task access object operator info HashJoin 8002.00 root right outer join, equal:[eq(test.t.nb, test.t.nb)] ├─TableReader(Build) 3333.33 root data:Selection │ └─Selection 3333.33 cop[tikv] gt(test.t.a, 1) │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo └─TableReader(Probe) 8002.00 root data:Selection └─Selection 8002.00 cop[tikv] or(ifnull(test.t.a, 1), isnull(test.t.a)) └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain format = 'brief' select ifnull(t.a, 1) in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info Projection 10000.00 root Column#22 └─Apply 10000.00 root left outer semi join, equal:[eq(Column#23, Column#21)] ├─Projection(Build) 10000.00 root test.t.a, ifnull(test.t.a, 1)->Column#23 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─HashAgg(Probe) 1.00 root funcs:count(Column#25)->Column#21 └─HashJoin 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] ├─HashAgg(Build) 7.99 root group by:test.t.a, funcs:count(Column#26)->Column#25, funcs:firstrow(test.t.a)->test.t.a │ └─TableReader 7.99 root data:HashAgg │ └─HashAgg 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#26 │ └─Selection 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) 9.99 root data:Selection └─Selection 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) └─TableFullScan 10000.00 cop[tikv] table:s keep order:false, stats:pseudo drop table if exists t; create table t(a int); explain format = 'brief' select * from t where _tidb_rowid = 0; id estRows task access object operator info Point_Get 1.00 root table:t handle:0 explain format = 'brief' select * from t where _tidb_rowid > 0; id estRows task access object operator info Projection 8000.00 root test.t.a └─TableReader 10000.00 root data:TableRangeScan └─TableRangeScan 10000.00 cop[tikv] table:t range:(0,+inf], keep order:false, stats:pseudo explain format = 'brief' select a, _tidb_rowid from t where a > 0; id estRows task access object operator info TableReader 3333.33 root data:Selection └─Selection 3333.33 cop[tikv] gt(test.t.a, 0) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t where _tidb_rowid > 0 and a > 0; id estRows task access object operator info Projection 2666.67 root test.t.a └─TableReader 2666.67 root data:Selection └─Selection 2666.67 cop[tikv] gt(test.t.a, 0) └─TableRangeScan 3333.33 cop[tikv] table:t range:(0,+inf], keep order:false, stats:pseudo drop table if exists t; create table t(a int, b int, c int); explain format = 'brief' select * from (select * from t order by (select 2)) t order by a, b; id estRows task access object operator info Sort 10000.00 root test.t.a, test.t.b └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from (select * from t order by c) t order by a, b; id estRows task access object operator info Sort 10000.00 root test.t.a, test.t.b └─Sort 10000.00 root test.t.c └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; set @@session.tidb_opt_insubq_to_join_and_agg=1; explain format = 'brief' SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a; id estRows task access object operator info Sort 2.00 root Column#3 └─HashAgg 2.00 root group by:Column#3, funcs:firstrow(Column#6)->Column#3 └─Union 2.00 root ├─HashAgg 1.00 root group by:1, funcs:firstrow(0)->Column#6, funcs:firstrow(0)->Column#3 │ └─TableDual 1.00 root rows:1 └─HashAgg 1.00 root group by:1, funcs:firstrow(1)->Column#6, funcs:firstrow(1)->Column#3 └─TableDual 1.00 root rows:1 explain format = 'brief' SELECT 0 AS a FROM dual UNION (SELECT 1 AS a FROM dual ORDER BY a); id estRows task access object operator info HashAgg 2.00 root group by:Column#3, funcs:firstrow(Column#6)->Column#3 └─Union 2.00 root ├─HashAgg 1.00 root group by:1, funcs:firstrow(0)->Column#6, funcs:firstrow(0)->Column#3 │ └─TableDual 1.00 root rows:1 └─StreamAgg 1.00 root group by:Column#2, funcs:firstrow(Column#2)->Column#6, funcs:firstrow(Column#2)->Column#3 └─Projection 1.00 root 1->Column#2 └─TableDual 1.00 root rows:1 create table t (i int key, j int, unique key (i, j)); begin; insert into t values (1, 1); explain format = 'brief' update t set j = -j where i = 1 and j = 1; id estRows task access object operator info Update N/A root N/A └─Selection 1.00 root eq(test.t.j, 1) └─Point_Get 1.00 root table:t handle:1 rollback; drop table if exists t; create table t(a int); begin; insert into t values (1); explain format = 'brief' select * from t left outer join t t1 on t.a = t1.a where t.a not between 1 and 2; id estRows task access object operator info HashJoin 8320.83 root left outer join, equal:[eq(test.t.a, test.t.a)] ├─UnionScan(Build) 6656.67 root not(and(ge(test.t.a, 1), le(test.t.a, 2))), not(isnull(test.t.a)) │ └─TableReader 6656.67 root data:Selection │ └─Selection 6656.67 cop[tikv] not(isnull(test.t.a)), or(lt(test.t.a, 1), gt(test.t.a, 2)) │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─UnionScan(Probe) 6656.67 root not(and(ge(test.t.a, 1), le(test.t.a, 2))) └─TableReader 6656.67 root data:Selection └─Selection 6656.67 cop[tikv] or(lt(test.t.a, 1), gt(test.t.a, 2)) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo rollback; drop table if exists t; create table t(a time, b date); insert into t values (1, "1000-01-01"), (2, "1000-01-02"), (3, "1000-01-03"); analyze table t; explain format = 'brief' select * from t where a = 1; id estRows task access object operator info TableReader 1.00 root data:Selection └─Selection 1.00 cop[tikv] eq(test.t.a, 00:00:01.000000) └─TableFullScan 3.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b = "1000-01-01"; id estRows task access object operator info TableReader 1.00 root data:Selection └─Selection 1.00 cop[tikv] eq(test.t.b, 1000-01-01 00:00:00.000000) └─TableFullScan 3.00 cop[tikv] table:t keep order:false drop table t; create table t(a int); insert into t values (1),(2),(2),(2),(9),(9),(9),(10); analyze table t with 1 buckets; explain format = 'brief' select * from t where a >= 3 and a <= 8; id estRows task access object operator info TableReader 0.00 root data:Selection └─Selection 0.00 cop[tikv] ge(test.t.a, 3), le(test.t.a, 8) └─TableFullScan 8.00 cop[tikv] table:t keep order:false drop table t; create table t(a int, b int, index idx_ab(a, b)); explain format = 'brief' select a, b from t where a in (1) order by b; id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan └─IndexRangeScan 10.00 cop[tikv] table:t, index:idx_ab(a, b) range:[1,1], keep order:true, stats:pseudo explain format = 'brief' select a, b from t where a = 1 order by b; id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan └─IndexRangeScan 10.00 cop[tikv] table:t, index:idx_ab(a, b) range:[1,1], keep order:true, stats:pseudo drop table if exists t; create table t(a int, b int); explain format = 'brief' select a, b from (select a, b, avg(b) over (partition by a)as avg_b from t) as tt where a > 10 and b < 10 and a > avg_b; id estRows task access object operator info Projection 2666.67 root test.t.a, test.t.b └─Selection 2666.67 root gt(cast(test.t.a, decimal(20,0) BINARY), Column#5), lt(test.t.b, 10) └─Window 3333.33 root avg(cast(test.t.b, decimal(15,4) BINARY))->Column#5 over(partition by test.t.a) └─Sort 3333.33 root test.t.a └─TableReader 3333.33 root data:Selection └─Selection 3333.33 cop[tikv] gt(test.t.a, 10) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; create table t(a int, b int); explain format="dot" select * from t where a < 2; dot contents digraph TableReader_7 { subgraph cluster7{ node [style=filled, color=lightgrey] color=black label = "root" "TableReader_7" } subgraph cluster6{ node [style=filled, color=lightgrey] color=black label = "cop" "Selection_6" -> "TableFullScan_5" } "TableReader_7" -> "Selection_6" } drop table if exists t; create table t(a binary(16) not null, b varchar(2) default null, c varchar(100) default 'aaaa', key (a,b)); explain format = 'brief' select * from t where a=x'FA34E1093CB428485734E3917F000000' and b='xb'; id estRows task access object operator info IndexLookUp 0.10 root ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:a(a, b) range:[0xFA34E1093CB428485734E3917F000000 "xb",0xFA34E1093CB428485734E3917F000000 "xb"], keep order:false, stats:pseudo └─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' update t set c = 'ssss' where a=x'FA34E1093CB428485734E3917F000000' and b='xb'; id estRows task access object operator info Update N/A root N/A └─IndexLookUp 0.10 root ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:a(a, b) range:[0xFA34E1093CB428485734E3917F000000 "xb",0xFA34E1093CB428485734E3917F000000 "xb"], keep order:false, stats:pseudo └─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; create table t(a int, b int); explain format = 'brief' select (select count(n.a) from t) from t n; id estRows task access object operator info Projection 1.00 root Column#11 └─Apply 1.00 root CARTESIAN left outer join ├─StreamAgg(Build) 1.00 root funcs:count(test.t.a)->Column#7 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:n keep order:false, stats:pseudo └─MaxOneRow(Probe) 1.00 root └─Projection 2.00 root Column#7 └─TableReader 2.00 root data:TableFullScan └─TableFullScan 2.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select (select sum((select count(a)))) from t; id estRows task access object operator info Projection 1.00 root Column#7 └─Apply 1.00 root CARTESIAN left outer join ├─StreamAgg(Build) 1.00 root funcs:count(test.t.a)->Column#5 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─HashAgg(Probe) 1.00 root funcs:sum(Column#12)->Column#7 └─HashJoin 1.00 root CARTESIAN left outer join ├─HashAgg(Build) 1.00 root group by:1, funcs:sum(Column#14)->Column#12 │ └─Projection 1.00 root cast(Column#6, decimal(42,0) BINARY)->Column#14 │ └─MaxOneRow 1.00 root │ └─Projection 1.00 root Column#5 │ └─TableDual 1.00 root rows:1 └─TableDual(Probe) 1.00 root rows:1 explain format = 'brief' select count(a) from t group by b order by (select count(a)); id estRows task access object operator info Sort 8000.00 root Column#4 └─HashJoin 8000.00 root CARTESIAN left outer join ├─TableDual(Build) 1.00 root rows:1 └─HashAgg(Probe) 8000.00 root group by:test.t.b, funcs:count(Column#8)->Column#4 └─TableReader 8000.00 root data:HashAgg └─HashAgg 8000.00 cop[tikv] group by:test.t.b, funcs:count(test.t.a)->Column#8 └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select (select sum(count(a))) from t; id estRows task access object operator info Projection 1.00 root Column#5 └─Apply 1.00 root CARTESIAN left outer join ├─StreamAgg(Build) 1.00 root funcs:count(test.t.a)->Column#4 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo └─StreamAgg(Probe) 1.00 root funcs:sum(Column#7)->Column#5 └─Projection 1.00 root cast(Column#4, decimal(42,0) BINARY)->Column#7 └─TableDual 1.00 root rows:1 explain format = 'brief' select sum(a), (select sum(a)), count(a) from t group by b order by (select count(a)); id estRows task access object operator info Projection 8000.00 root Column#4, Column#4, Column#5 └─Sort 8000.00 root Column#5 └─HashJoin 8000.00 root CARTESIAN left outer join ├─TableDual(Build) 1.00 root rows:1 └─HashJoin(Probe) 8000.00 root CARTESIAN left outer join ├─TableDual(Build) 1.00 root rows:1 └─HashAgg(Probe) 8000.00 root group by:test.t.b, funcs:sum(Column#13)->Column#4, funcs:count(Column#14)->Column#5 └─TableReader 8000.00 root data:HashAgg └─HashAgg 8000.00 cop[tikv] group by:test.t.b, funcs:sum(test.t.a)->Column#13, funcs:count(test.t.a)->Column#14 └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t;