Files
tidb/cmd/explaintest/r/explain_easy.result
2020-01-06 11:28:02 +08:00

775 lines
45 KiB
Plaintext

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));
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;
explain select * from t3 where exists (select s.a from t3 s having sum(s.a) = t3.a );
id count task operator info
Projection_11 8000.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d
└─HashLeftJoin_12 8000.00 root semi join, inner:StreamAgg_27, equal:[eq(Column#13, Column#11)]
├─Projection_13 10000.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d, cast(test.t3.a)->Column#13
│ └─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t3, range:[-inf,+inf], keep order:false, stats:pseudo
└─StreamAgg_27 1.00 root funcs:sum(Column#16)->Column#11
└─TableReader_28 1.00 root data:StreamAgg_19
└─StreamAgg_19 1.00 cop[tikv] funcs:sum(test.t3.a)->Column#16
└─TableScan_26 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t1;
id count task operator info
TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t1 order by c2;
id count task operator info
IndexLookUp_12 10000.00 root
├─IndexScan_10 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:true, stats:pseudo
└─TableScan_11 10000.00 cop[tikv] table:t1, keep order:false, stats:pseudo
explain select * from t2 order by c2;
id count task operator info
Sort_4 10000.00 root test.t2.c2:asc
└─TableReader_8 10000.00 root data:TableScan_7
└─TableScan_7 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t1 where t1.c1 > 0;
id count task operator info
TableReader_6 3333.33 root data:TableScan_5
└─TableScan_5 3333.33 cop[tikv] table:t1, range:(0,+inf], keep order:false, stats:pseudo
explain select t1.c1, t1.c2 from t1 where t1.c2 = 1;
id count task operator info
IndexReader_6 10.00 root index:IndexScan_5
└─IndexScan_5 10.00 cop[tikv] table:t1, index:c2, range:[1,1], keep order:false, stats:pseudo
explain select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1;
id count task operator info
HashLeftJoin_23 4166.67 root left outer join, inner:TableReader_33 (REVERSED), equal:[eq(test.t1.c2, test.t2.c1)]
├─TableReader_33 3333.33 root data:TableScan_32
│ └─TableScan_32 3333.33 cop[tikv] table:t1, range:(1,+inf], keep order:false, stats:pseudo
└─TableReader_36 9990.00 root data:Selection_35
└─Selection_35 9990.00 cop[tikv] not(isnull(test.t2.c1))
└─TableScan_34 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain update t1 set t1.c2 = 2 where t1.c1 = 1;
id count task operator info
Update_2 N/A root N/A
└─Point_Get_1 1.00 root table:t1, handle:1
explain delete from t1 where t1.c2 = 1;
id count task operator info
Delete_4 N/A root N/A
└─IndexLookUp_11 10.00 root
├─IndexScan_9 10.00 cop[tikv] table:t1, index:c2, range:[1,1], keep order:false, stats:pseudo
└─TableScan_10 10.00 cop[tikv] table:t1, keep order:false, stats:pseudo
explain select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1;
id count task operator info
Projection_11 9990.00 root cast(Column#8)->Column#7
└─HashLeftJoin_21 9990.00 root inner join, inner:HashAgg_28, equal:[eq(test.t1.c1, test.t2.c2)]
├─TableReader_34 10000.00 root data:TableScan_33
│ └─TableScan_33 10000.00 cop[tikv] table:a, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashAgg_28 7992.00 root group by:test.t2.c2, funcs:count(Column#9)->Column#8, funcs:firstrow(test.t2.c2)->test.t2.c2
└─TableReader_29 7992.00 root data:HashAgg_23
└─HashAgg_23 7992.00 cop[tikv] group by:test.t2.c2, funcs:count(test.t2.c2)->Column#9
└─Selection_27 9990.00 cop[tikv] not(isnull(test.t2.c2))
└─TableScan_26 10000.00 cop[tikv] table:b, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t2 order by t2.c2 limit 0, 1;
id count task operator info
TopN_7 1.00 root test.t2.c2:asc, offset:0, count:1
└─TableReader_15 1.00 root data:TopN_14
└─TopN_14 1.00 cop[tikv] test.t2.c2:asc, offset:0, count:1
└─TableScan_13 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t1 where c1 > 1 and c2 = 1 and c3 < 1;
id count task operator info
IndexLookUp_11 11.08 root
├─IndexScan_8 33.33 cop[tikv] table:t1, index:c2, range:(1 1,1 +inf], keep order:false, stats:pseudo
└─Selection_10 11.08 cop[tikv] lt(test.t1.c3, 1)
└─TableScan_9 33.33 cop[tikv] table:t1, keep order:false, stats:pseudo
explain select * from t1 where c1 = 1 and c2 > 1;
id count task operator info
TableReader_7 0.33 root data:Selection_6
└─Selection_6 0.33 cop[tikv] gt(test.t1.c2, 1)
└─TableScan_5 1.00 cop[tikv] table:t1, range:[1,1], keep order:false, stats:pseudo
explain select sum(t1.c1 in (select c1 from t2)) from t1;
id count task operator info
StreamAgg_12 1.00 root funcs:sum(Column#10)->Column#8
└─Projection_23 10000.00 root cast(Column#7)->Column#10
└─HashLeftJoin_22 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_21, other cond:eq(test.t1.c1, test.t2.c1)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexReader_21 10000.00 root index:IndexScan_20
└─IndexScan_20 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:false, stats:pseudo
explain select c1 from t1 where c1 in (select c2 from t2);
id count task operator info
Projection_9 9990.00 root test.t1.c1
└─HashLeftJoin_19 9990.00 root inner join, inner:HashAgg_23, equal:[eq(test.t1.c1, test.t2.c2)]
├─TableReader_32 10000.00 root data:TableScan_31
│ └─TableScan_31 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashAgg_23 7992.00 root group by:test.t2.c2, funcs:firstrow(test.t2.c2)->test.t2.c2
└─TableReader_30 9990.00 root data:Selection_29
└─Selection_29 9990.00 cop[tikv] not(isnull(test.t2.c2))
└─TableScan_28 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) from t1;
id count task operator info
Projection_12 10000.00 root ifnull(Column#7, 0)->Column#7
└─MergeJoin_13 10000.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1
├─TableReader_17 10000.00 root data:TableScan_16
│ └─TableScan_16 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:true, stats:pseudo
└─Projection_18 8000.00 root 1->Column#7, test.t1.c1
└─TableReader_20 10000.00 root data:TableScan_19
└─TableScan_19 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:true, stats:pseudo
explain select * from information_schema.columns;
id count task operator info
MemTableScan_4 10000.00 root
explain select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1;
id count task operator info
Projection_12 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#8
└─Apply_14 10000.00 root CARTESIAN left outer join, inner:Projection_43
├─TableReader_16 10000.00 root data:TableScan_15
│ └─TableScan_15 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─Projection_43 1.00 root test.t2.c1, test.t2.c2
└─IndexLookUp_42 1.00 root limit embedded(offset:0, count:1)
├─Limit_41 1.00 cop[tikv] offset:0, count:1
│ └─IndexScan_39 1.00 cop[tikv] table:t2, index:c1, range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true, stats:pseudo
└─TableScan_40 1.00 cop[tikv] table:t2, keep order:false, stats:pseudo
explain select * from t1 order by c1 desc limit 1;
id count task operator info
Limit_10 1.00 root offset:0, count:1
└─TableReader_20 1.00 root data:Limit_19
└─Limit_19 1.00 cop[tikv] offset:0, count:1
└─TableScan_18 1.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:true, desc, stats:pseudo
explain select * from t4 use index(idx) where a > 1 and b > 1 and c > 1 limit 1;
id count task operator info
Limit_9 1.00 root offset:0, count:1
└─IndexLookUp_16 1.00 root
├─Selection_13 3.00 cop[tikv] gt(test.t4.b, 1)
│ └─IndexScan_11 9.00 cop[tikv] table:t4, index:a, b, range:(1,+inf], keep order:false, stats:pseudo
└─Limit_15 1.00 cop[tikv] offset:0, count:1
└─Selection_14 1.00 cop[tikv] gt(test.t4.c, 1)
└─TableScan_12 3.00 cop[tikv] table:t4, keep order:false, stats:pseudo
explain select * from t4 where a > 1 and c > 1 limit 1;
id count task operator info
Limit_8 1.00 root offset:0, count:1
└─TableReader_14 1.00 root data:Limit_13
└─Limit_13 1.00 cop[tikv] offset:0, count:1
└─Selection_12 1.00 cop[tikv] gt(test.t4.c, 1)
└─TableScan_11 3.00 cop[tikv] table:t4, range:(1,+inf], keep order:false, stats:pseudo
explain select ifnull(null, t1.c1) from t1;
id count task operator info
TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select if(10, t1.c1, t1.c2) from t1;
id count task operator info
TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select c1 from t2 union select c1 from t2 union all select c1 from t2;
id count task operator info
Union_17 26000.00 root
├─HashAgg_21 16000.00 root group by:Column#10, funcs:firstrow(Column#12)->Column#10
│ └─Union_22 16000.00 root
│ ├─StreamAgg_27 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#12, funcs:firstrow(test.t2.c1)->Column#10
│ │ └─IndexReader_40 10000.00 root index:IndexScan_39
│ │ └─IndexScan_39 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
│ └─StreamAgg_45 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#12, funcs:firstrow(test.t2.c1)->Column#10
│ └─IndexReader_58 10000.00 root index:IndexScan_57
│ └─IndexScan_57 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
└─IndexReader_63 10000.00 root index:IndexScan_62
└─IndexScan_62 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:false, stats:pseudo
explain select c1 from t2 union all select c1 from t2 union select c1 from t2;
id count task operator info
HashAgg_18 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#10
└─Union_19 24000.00 root
├─StreamAgg_24 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10
│ └─IndexReader_37 10000.00 root index:IndexScan_36
│ └─IndexScan_36 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
├─StreamAgg_42 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10
│ └─IndexReader_55 10000.00 root index:IndexScan_54
│ └─IndexScan_54 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
└─StreamAgg_60 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10
└─IndexReader_73 10000.00 root index:IndexScan_72
└─IndexScan_72 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
explain select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2;
id count task operator info
StreamAgg_13 1.00 root funcs:count(1)->Column#5
└─StreamAgg_28 1.00 root funcs:firstrow(Column#8)->Column#6
└─TableReader_29 1.00 root data:StreamAgg_17
└─StreamAgg_17 1.00 cop[tikv] funcs:firstrow(1)->Column#8
└─Selection_27 10.00 cop[tikv] eq(test.t1.c3, 100)
└─TableScan_26 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select 1 from (select count(c2), count(c3) from t1) k;
id count task operator info
Projection_5 1.00 root 1->Column#6
└─StreamAgg_21 1.00 root funcs:firstrow(Column#13)->Column#7
└─TableReader_22 1.00 root data:StreamAgg_9
└─StreamAgg_9 1.00 cop[tikv] funcs:firstrow(1)->Column#13
└─TableScan_19 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select count(1) from (select max(c2), count(c3) as m from t1) k;
id count task operator info
StreamAgg_11 1.00 root funcs:count(1)->Column#6
└─StreamAgg_27 1.00 root funcs:firstrow(Column#12)->Column#7
└─TableReader_28 1.00 root data:StreamAgg_15
└─StreamAgg_15 1.00 cop[tikv] funcs:firstrow(1)->Column#12
└─TableScan_25 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select count(1) from (select count(c2) from t1 group by c3) k;
id count task operator info
StreamAgg_11 1.00 root funcs:count(1)->Column#5
└─HashAgg_22 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#6
└─TableReader_19 10000.00 root data:TableScan_18
└─TableScan_18 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
set @@session.tidb_opt_insubq_to_join_and_agg=0;
explain select sum(t1.c1 in (select c1 from t2)) from t1;
id count task operator info
StreamAgg_12 1.00 root funcs:sum(Column#10)->Column#8
└─Projection_23 10000.00 root cast(Column#7)->Column#10
└─HashLeftJoin_22 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_21, other cond:eq(test.t1.c1, test.t2.c1)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexReader_21 10000.00 root index:IndexScan_20
└─IndexScan_20 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:false, stats:pseudo
explain select 1 in (select c2 from t2) from t1;
id count task operator info
Projection_6 10000.00 root Column#7
└─HashLeftJoin_7 10000.00 root CARTESIAN left outer semi join, inner:TableReader_14
├─TableReader_9 10000.00 root data:TableScan_8
│ └─TableScan_8 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_14 10.00 root data:Selection_13
└─Selection_13 10.00 cop[tikv] eq(1, test.t2.c2)
└─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain select sum(6 in (select c2 from t2)) from t1;
id count task operator info
StreamAgg_12 1.00 root funcs:sum(Column#10)->Column#8
└─Projection_22 10000.00 root cast(Column#7)->Column#10
└─HashLeftJoin_21 10000.00 root CARTESIAN left outer semi join, inner:TableReader_20
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_20 10.00 root data:Selection_19
└─Selection_19 10.00 cop[tikv] eq(6, test.t2.c2)
└─TableScan_18 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain format="dot" select sum(t1.c1 in (select c1 from t2)) from t1;
dot contents
digraph StreamAgg_12 {
subgraph cluster12{
node [style=filled, color=lightgrey]
color=black
label = "root"
"StreamAgg_12" -> "Projection_23"
"Projection_23" -> "HashLeftJoin_22"
"HashLeftJoin_22" -> "TableReader_15"
"HashLeftJoin_22" -> "IndexReader_21"
}
subgraph cluster14{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_14"
}
subgraph cluster20{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"IndexScan_20"
}
"TableReader_15" -> "TableScan_14"
"IndexReader_21" -> "IndexScan_20"
}
explain format="dot" select 1 in (select c2 from t2) from t1;
dot contents
digraph Projection_6 {
subgraph cluster6{
node [style=filled, color=lightgrey]
color=black
label = "root"
"Projection_6" -> "HashLeftJoin_7"
"HashLeftJoin_7" -> "TableReader_9"
"HashLeftJoin_7" -> "TableReader_14"
}
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_8"
}
subgraph cluster13{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_13" -> "TableScan_12"
}
"TableReader_9" -> "TableScan_8"
"TableReader_14" -> "Selection_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 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 count task operator info
Projection_11 10000.00 root Column#11
└─Apply_13 10000.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(test.t.c, Column#10)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─StreamAgg_20 1.00 root funcs:count(1)->Column#10
└─MergeJoin_54 12.50 root inner join, left key:test.t.a, right key:test.t.a
├─TableReader_47 1.00 root data:TableScan_46
│ └─TableScan_46 1.00 cop[tikv] table:s, range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo
└─TableReader_49 1.00 root data:TableScan_48
└─TableScan_48 1.00 cop[tikv] table:t1, range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo
explain 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 count task operator info
Projection_11 10000.00 root Column#11
└─Apply_13 10000.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(test.t.c, Column#10)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─StreamAgg_20 1.00 root funcs:count(1)->Column#10
└─IndexMergeJoin_44 12.50 root inner join, inner:TableReader_42, outer key:test.t.a, inner key:test.t.a
├─IndexReader_33 10.00 root index:IndexScan_32
│ └─IndexScan_32 10.00 cop[tikv] table:s, index:b, range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo
└─TableReader_42 1.00 root data:TableScan_41
└─TableScan_41 1.00 cop[tikv] table:t1, range: decided by [test.t.a], keep order:true, stats:pseudo
explain 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 count task operator info
Projection_11 10000.00 root Column#11
└─Apply_13 10000.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(test.t.c, Column#10)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─StreamAgg_20 1.00 root funcs:count(1)->Column#10
└─IndexMergeJoin_46 12.49 root inner join, inner:TableReader_44, outer key:test.t.c, inner key:test.t.a
├─IndexLookUp_35 9.99 root
│ ├─IndexScan_32 10.00 cop[tikv] table:s, index:b, range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo
│ └─Selection_34 9.99 cop[tikv] not(isnull(test.t.c))
│ └─TableScan_33 10.00 cop[tikv] table:s, keep order:false, stats:pseudo
└─TableReader_44 1.00 root data:TableScan_43
└─TableScan_43 1.00 cop[tikv] table:t1, range: decided by [test.t.c], keep order:true, 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 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 count task operator info
Projection_11 5.00 root Column#11
└─Apply_13 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(test.t.c, Column#10)
├─TableReader_15 5.00 root data:TableScan_14
│ └─TableScan_14 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false
└─StreamAgg_20 1.00 root funcs:count(1)->Column#10
└─MergeJoin_62 2.40 root inner join, left key:test.t.a, right key:test.t.a
├─IndexReader_49 2.40 root index:Selection_48
│ └─Selection_48 2.40 cop[tikv] eq(3, test.t.a)
│ └─IndexScan_47 3.00 cop[tikv] table:s, index:b, range:[3,3], keep order:true
└─TableReader_52 4.00 root data:Selection_51
└─Selection_51 4.00 cop[tikv] eq(3, test.t.a)
└─TableScan_50 5.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:true
explain 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 count task operator info
Projection_10 5.00 root Column#11
└─Apply_12 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_19, other cond:eq(test.t.c, Column#10)
├─TableReader_14 5.00 root data:TableScan_13
│ └─TableScan_13 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false
└─StreamAgg_19 1.00 root funcs:count(1)->Column#10
└─MergeJoin_50 2.40 root left outer join, left key:test.t.a, right key:test.t.a
├─IndexReader_37 2.40 root index:Selection_36
│ └─Selection_36 2.40 cop[tikv] eq(3, test.t.a)
│ └─IndexScan_35 3.00 cop[tikv] table:s, index:b, range:[3,3], keep order:true
└─TableReader_40 4.00 root data:Selection_39
└─Selection_39 4.00 cop[tikv] eq(3, test.t.a)
└─TableScan_38 5.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:true
explain 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 count task operator info
Projection_10 5.00 root Column#11
└─Apply_12 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_19, other cond:eq(test.t.c, Column#10)
├─TableReader_14 5.00 root data:TableScan_13
│ └─TableScan_13 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false
└─StreamAgg_19 1.00 root funcs:count(1)->Column#10
└─MergeJoin_49 2.40 root right outer join, left key:test.t.a, right key:test.t.a
├─TableReader_36 4.00 root data:Selection_35
│ └─Selection_35 4.00 cop[tikv] eq(3, test.t.a)
│ └─TableScan_34 5.00 cop[tikv] table:s, range:[-inf,+inf], keep order:true
└─IndexReader_39 2.40 root index:Selection_38
└─Selection_38 2.40 cop[tikv] eq(3, test.t.a)
└─IndexScan_37 3.00 cop[tikv] table:t1, index:b, range:[3,3], keep order:true
drop table if exists t;
create table t(a int unsigned);
explain select t.a = '123455' from t;
id count task operator info
Projection_3 10000.00 root eq(test.t.a, 123455)->Column#3
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select t.a > '123455' from t;
id count task operator info
Projection_3 10000.00 root gt(test.t.a, 123455)->Column#3
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select t.a != '123455' from t;
id count task operator info
Projection_3 10000.00 root ne(test.t.a, 123455)->Column#3
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select t.a = 12345678912345678998789678687678.111 from t;
id count task operator info
Projection_3 10000.00 root 0->Column#3
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
create table t(a bigint, b bigint, index idx(a, b));
explain select * from t where a in (1, 2) and a in (1, 3);
id count task operator info
IndexReader_6 10.00 root index:IndexScan_5
└─IndexScan_5 10.00 cop[tikv] table:t, index:a, b, range:[1,1], keep order:false, stats:pseudo
explain select * from t where b in (1, 2) and b in (1, 3);
id count task operator info
TableReader_7 10.00 root data:Selection_6
└─Selection_6 10.00 cop[tikv] in(test.t.b, 1, 2), in(test.t.b, 1, 3)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t where a = 1 and a = 1;
id count task operator info
IndexReader_6 10.00 root index:IndexScan_5
└─IndexScan_5 10.00 cop[tikv] table:t, index:a, b, range:[1,1], keep order:false, stats:pseudo
explain select * from t where a = 1 and a = 2;
id count task operator info
TableDual_5 0.00 root rows:0
explain select * from t where b = 1 and b = 2;
id count task operator info
TableDual_5 0.00 root rows:0
explain select * from t t1 join t t2 where t1.b = t2.b and t2.b is null;
id count task operator info
Projection_7 0.00 root test.t.a, test.t.b, test.t.a, test.t.b
└─HashRightJoin_9 0.00 root inner join, inner:TableReader_12, equal:[eq(test.t.b, test.t.b)]
├─TableReader_12 0.00 root data:Selection_11
│ └─Selection_11 0.00 cop[tikv] isnull(test.t.b), not(isnull(test.t.b))
│ └─TableScan_10 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_18 9990.00 root data:Selection_17
└─Selection_17 9990.00 cop[tikv] not(isnull(test.t.b))
└─TableScan_16 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t t1 where not exists (select * from t t2 where t1.b = t2.b);
id count task operator info
HashLeftJoin_9 8000.00 root anti semi join, inner:TableReader_15, equal:[eq(test.t.b, test.t.b)]
├─TableReader_11 10000.00 root data:TableScan_10
│ └─TableScan_10 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_15 10000.00 root data:TableScan_14
└─TableScan_14 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
create table t(a bigint primary key);
explain select * from t where a = 1 and a = 2;
id count task operator info
TableDual_5 0.00 root rows:0
explain select null or a > 1 from t;
id count task operator info
Projection_3 10000.00 root or(<nil>, gt(test.t.a, 1))->Column#2
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t where a = 1 for update;
id count task operator info
Point_Get_1 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 select * from ta where a = 1;
id count task operator info
TableReader_7 8000.00 root data:Selection_6
└─Selection_6 8000.00 cop[tikv] eq(cast(test.ta.a), 1)
└─TableScan_5 10000.00 cop[tikv] table:ta, range:[-inf,+inf], 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 select t1.a, t1.b from t1 left outer join t2 on t1.a = t2.a;
id count task operator info
IndexReader_9 10000.00 root index:IndexScan_8
└─IndexScan_8 10000.00 cop[tikv] table:t1, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
explain select distinct t1.a, t1.b from t1 left outer join t2 on t1.a = t2.a;
id count task operator info
IndexReader_11 10000.00 root index:IndexScan_10
└─IndexScan_10 10000.00 cop[tikv] table:t1, index:a, b, range:[NULL,+inf], 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 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 count task operator info
StreamAgg_22 1.00 root funcs:count(1)->Column#22
└─HashAgg_25 1.00 root group by:Column#31, Column#32, Column#33, funcs:firstrow(1)->Column#23
└─Projection_48 0.02 root Column#14, Column#15, coalesce(test.test02.region_name, 不详)->Column#33
└─IndexMergeJoin_32 0.02 root left outer join, inner:TableReader_30, outer key:Column#16, inner key:test.test02.id
├─Union_37 0.02 root
│ ├─Projection_38 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id, cast(0)->Column#17
│ │ └─TableReader_41 0.01 root data:Selection_40
│ │ └─Selection_40 0.01 cop[tikv] eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), ge(test.test01.stat_date, 20191202), gt(cast(0), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202)
│ │ └─TableScan_39 10000.00 cop[tikv] table:test01, range:[-inf,+inf], keep order:false, stats:pseudo
│ └─Projection_42 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id, cast(test.test01.registration_num)->Column#17
│ └─TableReader_45 0.01 root data:Selection_44
│ └─Selection_44 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), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202)
│ └─TableScan_43 10000.00 cop[tikv] table:test01, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_30 1.00 root data:TableScan_29
└─TableScan_29 1.00 cop[tikv] table:b, range: decided by [Column#16], keep order:true, stats:pseudo
drop table if exists t;
create table t(a int, nb int not null, nc int not null);
explain select ifnull(a, 0) from t;
id count task operator info
Projection_3 10000.00 root ifnull(test.t.a, 0)->Column#5
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select ifnull(nb, 0) from t;
id count task operator info
TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select ifnull(nb, 0), ifnull(nc, 0) from t;
id count task operator info
TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select ifnull(a, 0), ifnull(nb, 0) from t;
id count task operator info
Projection_3 10000.00 root ifnull(test.t.a, 0)->Column#5, test.t.nb
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select ifnull(nb, 0), ifnull(nb, 0) from t;
id count task operator info
Projection_3 10000.00 root test.t.nb, test.t.nb
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select 1+ifnull(nb, 0) from t;
id count task operator info
Projection_3 10000.00 root plus(1, test.t.nb)->Column#5
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select 1+ifnull(a, 0) from t;
id count task operator info
Projection_3 10000.00 root plus(1, ifnull(test.t.a, 0))->Column#5
└─TableReader_5 10000.00 root data:TableScan_4
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select 1+ifnull(nb, 0) from t where nb=1;
id count task operator info
Projection_4 10.00 root plus(1, test.t.nb)->Column#5
└─TableReader_7 10.00 root data:Selection_6
└─Selection_6 10.00 cop[tikv] eq(test.t.nb, 1)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
HashLeftJoin_7 8320.83 root left outer join, inner:TableReader_13, equal:[eq(test.t.nb, test.t.nb)], left cond:[gt(test.t.a, 1)]
├─TableReader_11 6656.67 root data:Selection_10
│ └─Selection_10 6656.67 cop[tikv] or(test.t.nb, isnull(test.t.nb))
│ └─TableScan_9 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_13 10000.00 root data:TableScan_12
└─TableScan_12 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
HashRightJoin_7 6656.67 root right outer join, inner:TableReader_11, equal:[eq(test.t.nb, test.t.nb)]
├─TableReader_11 3333.33 root data:Selection_10
│ └─Selection_10 3333.33 cop[tikv] gt(test.t.a, 1)
│ └─TableScan_9 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_14 6656.67 root data:Selection_13
└─Selection_13 6656.67 cop[tikv] or(test.t.nb, isnull(test.t.nb))
└─TableScan_12 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
HashRightJoin_9 4166.67 root inner join, inner:TableReader_12, equal:[eq(test.t.nb, test.t.nb)]
├─TableReader_12 3333.33 root data:Selection_11
│ └─Selection_11 3333.33 cop[tikv] gt(test.t.a, 1)
│ └─TableScan_10 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_15 6656.67 root data:Selection_14
└─Selection_14 6656.67 cop[tikv] or(test.t.nb, isnull(test.t.nb))
└─TableScan_13 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
Projection_12 10000.00 root Column#14
└─Apply_14 10000.00 root CARTESIAN left outer semi join, inner:HashAgg_19, other cond:eq(test.t.nc, Column#13)
├─TableReader_16 10000.00 root data:TableScan_15
│ └─TableScan_15 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashAgg_19 1.00 root funcs:count(Column#15)->Column#13
└─HashLeftJoin_20 9.99 root inner join, inner:HashAgg_30, equal:[eq(test.t.a, test.t.a)]
├─TableReader_24 9.99 root data:Selection_23
│ └─Selection_23 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))
│ └─TableScan_22 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashAgg_30 7.99 root group by:test.t.a, funcs:count(Column#16)->Column#15, funcs:firstrow(test.t.a)->test.t.a
└─TableReader_31 7.99 root data:HashAgg_25
└─HashAgg_25 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#16
└─Selection_29 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))
└─TableScan_28 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
Selection_7 10000.00 root or(ifnull(test.t.a, 1), isnull(test.t.a))
└─HashLeftJoin_8 12500.00 root left outer join, inner:TableReader_13, equal:[eq(test.t.nb, test.t.nb)], left cond:[gt(test.t.a, 1)]
├─TableReader_11 10000.00 root data:TableScan_10
│ └─TableScan_10 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_13 10000.00 root data:TableScan_12
└─TableScan_12 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
HashRightJoin_7 8000.00 root right outer join, inner:TableReader_11, equal:[eq(test.t.nb, test.t.nb)]
├─TableReader_11 3333.33 root data:Selection_10
│ └─Selection_10 3333.33 cop[tikv] gt(test.t.a, 1)
│ └─TableScan_9 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_14 8000.00 root data:Selection_13
└─Selection_13 8000.00 cop[tikv] or(ifnull(test.t.a, 1), isnull(test.t.a))
└─TableScan_12 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo
explain 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 count task operator info
Projection_12 10000.00 root Column#14
└─Apply_14 10000.00 root CARTESIAN left outer semi join, inner:HashAgg_19, other cond:eq(ifnull(test.t.a, 1), Column#13)
├─TableReader_16 10000.00 root data:TableScan_15
│ └─TableScan_15 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashAgg_19 1.00 root funcs:count(Column#15)->Column#13
└─HashLeftJoin_20 9.99 root inner join, inner:HashAgg_30, equal:[eq(test.t.a, test.t.a)]
├─TableReader_24 9.99 root data:Selection_23
│ └─Selection_23 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))
│ └─TableScan_22 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashAgg_30 7.99 root group by:test.t.a, funcs:count(Column#16)->Column#15, funcs:firstrow(test.t.a)->test.t.a
└─TableReader_31 7.99 root data:HashAgg_25
└─HashAgg_25 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#16
└─Selection_29 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))
└─TableScan_28 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
create table t(a int);
explain select * from t where _tidb_rowid = 0;
id count task operator info
Point_Get_1 1.00 root table:t, handle:0
explain select * from t where _tidb_rowid > 0;
id count task operator info
Projection_4 8000.00 root test.t.a
└─TableReader_6 10000.00 root data:TableScan_5
└─TableScan_5 10000.00 cop[tikv] table:t, range:(0,+inf], keep order:false, stats:pseudo
explain select a, _tidb_rowid from t where a > 0;
id count task operator info
TableReader_7 3333.33 root data:Selection_6
└─Selection_6 3333.33 cop[tikv] gt(test.t.a, 0)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t where _tidb_rowid > 0 and a > 0;
id count task operator info
Projection_4 2666.67 root test.t.a
└─TableReader_7 2666.67 root data:Selection_6
└─Selection_6 2666.67 cop[tikv] gt(test.t.a, 0)
└─TableScan_5 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 select * from (select * from t order by (select 2)) t order by a, b;
id count task operator info
Sort_12 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_18 10000.00 root data:TableScan_17
└─TableScan_17 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from (select * from t order by c) t order by a, b;
id count task operator info
Sort_6 10000.00 root test.t.a:asc, test.t.b:asc
└─Sort_9 10000.00 root test.t.c:asc
└─TableReader_12 10000.00 root data:TableScan_11
└─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
set @@session.tidb_opt_insubq_to_join_and_agg=1;
explain SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a;
id count task operator info
Sort_13 2.00 root Column#3:asc
└─HashAgg_17 2.00 root group by:Column#3, funcs:firstrow(Column#6)->Column#3
└─Union_18 2.00 root
├─HashAgg_19 1.00 root group by:0, funcs:firstrow(0)->Column#6, funcs:firstrow(0)->Column#3
│ └─TableDual_22 1.00 root rows:1
└─HashAgg_25 1.00 root group by:1, funcs:firstrow(1)->Column#6, funcs:firstrow(1)->Column#3
└─TableDual_28 1.00 root rows:1
explain SELECT 0 AS a FROM dual UNION (SELECT 1 AS a FROM dual ORDER BY a);
id count task operator info
HashAgg_15 2.00 root group by:Column#3, funcs:firstrow(Column#6)->Column#3
└─Union_16 2.00 root
├─HashAgg_17 1.00 root group by:0, funcs:firstrow(0)->Column#6, funcs:firstrow(0)->Column#3
│ └─TableDual_20 1.00 root rows:1
└─StreamAgg_27 1.00 root group by:Column#1, funcs:firstrow(Column#1)->Column#6, funcs:firstrow(Column#1)->Column#3
└─Projection_32 1.00 root 1->Column#1
└─TableDual_33 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 update t set j = -j where i = 1 and j = 1;
id count task operator info
Update_2 N/A root N/A
└─Point_Get_1 1.00 root table:t, index:i j
rollback;
drop table if exists t;
create table t(a int);
begin;
insert into t values (1);
explain select * from t left outer join t t1 on t.a = t1.a where t.a not between 1 and 2;
id count task operator info
Projection_8 8320.83 root test.t.a, test.t.a
└─HashLeftJoin_9 8320.83 root left outer join, inner:UnionScan_15, equal:[eq(test.t.a, test.t.a)]
├─UnionScan_11 6656.67 root not(and(ge(test.t.a, 1), le(test.t.a, 2)))
│ └─TableReader_14 6656.67 root data:Selection_13
│ └─Selection_13 6656.67 cop[tikv] or(lt(test.t.a, 1), gt(test.t.a, 2))
│ └─TableScan_12 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─UnionScan_15 6656.67 root not(and(ge(test.t.a, 1), le(test.t.a, 2))), not(isnull(test.t.a))
└─TableReader_18 6656.67 root data:Selection_17
└─Selection_17 6656.67 cop[tikv] not(isnull(test.t.a)), or(lt(test.t.a, 1), gt(test.t.a, 2))
└─TableScan_16 10000.00 cop[tikv] table:t1, range:[-inf,+inf], 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 select * from t where a = 1;
id count task operator info
TableReader_7 1.00 root data:Selection_6
└─Selection_6 1.00 cop[tikv] eq(test.t.a, 00:00:01.000000)
└─TableScan_5 3.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false
explain select * from t where b = "1000-01-01";
id count task operator info
TableReader_7 1.00 root data:Selection_6
└─Selection_6 1.00 cop[tikv] eq(test.t.b, 1000-01-01 00:00:00.000000)
└─TableScan_5 3.00 cop[tikv] table:t, range:[-inf,+inf], 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 select * from t where a >= 3 and a <= 8;
id count task operator info
TableReader_7 0.00 root data:Selection_6
└─Selection_6 0.00 cop[tikv] ge(test.t.a, 3), le(test.t.a, 8)
└─TableScan_5 8.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false
drop table t;
create table t(a int, b int, index idx_ab(a, b));
explain select a, b from t where a in (1) order by b;
id count task operator info
IndexReader_12 10.00 root index:IndexScan_11
└─IndexScan_11 10.00 cop[tikv] table:t, index:a, b, range:[1,1], keep order:true, stats:pseudo
explain select a, b from t where a = 1 order by b;
id count task operator info
IndexReader_12 10.00 root index:IndexScan_11
└─IndexScan_11 10.00 cop[tikv] table:t, index:a, b, range:[1,1], keep order:true, stats:pseudo
drop table if exists t;
create table t(a int, b int);
explain 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 count task operator info
Projection_8 2666.67 root test.t.a, test.t.b
└─Selection_9 2666.67 root gt(cast(test.t.a), Column#5), lt(test.t.b, 10)
└─Window_10 3333.33 root avg(cast(test.t.b))->Column#5 over(partition by test.t.a)
└─Sort_14 3333.33 root test.t.a:asc
└─TableReader_13 3333.33 root data:Selection_12
└─Selection_12 3333.33 cop[tikv] gt(test.t.a, 10)
└─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], 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" -> "TableScan_5"
}
"TableReader_7" -> "Selection_6"
}
drop table if exists t;