Skip to content

Commit

Permalink
planner: support cost model for tiflash table scan (#12868)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored and sre-bot committed Oct 29, 2019
1 parent 36f0f37 commit 6fd74f3
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 107 deletions.
10 changes: 5 additions & 5 deletions cmd/explaintest/r/access_path_selection.result
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ IndexReader_6 3323.33 root index:IndexScan_5
└─IndexScan_5 3323.33 cop[tikv] table:access_path_selection, index:a, b, range:[-inf,3), keep order:false, stats:pseudo
explain select a, b from access_path_selection where b < 3;
id count task operator info
IndexReader_13 3323.33 root index:Selection_12
└─Selection_12 3323.33 cop[tikv] lt(Column#2, 3)
└─IndexScan_11 10000.00 cop[tikv] table:access_path_selection, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(Column#2, 3)
└─TableScan_5 10000.00 cop[tikv] table:access_path_selection, range:[-inf,+inf], keep order:false, stats:pseudo
explain select a, b from access_path_selection where a < 3 and b < 3;
id count task operator info
IndexReader_11 1104.45 root index:Selection_10
Expand All @@ -39,6 +39,6 @@ StreamAgg_13 1.00 root funcs:max(Column#3)
explain select count(1) from access_path_selection;
id count task operator info
StreamAgg_28 1.00 root funcs:count(Column#19)
└─IndexReader_29 1.00 root index:StreamAgg_8
└─TableReader_29 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tikv] funcs:count(1)
└─IndexScan_25 10000.00 cop[tikv] table:access_path_selection, index:a, range:[NULL,+inf], keep order:false, stats:pseudo
└─TableScan_24 10000.00 cop[tikv] table:access_path_selection, range:[-inf,+inf], keep order:false, stats:pseudo
90 changes: 45 additions & 45 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ 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#9)
└─HashLeftJoin_21 9990.00 root inner join, inner:HashAgg_28, equal:[eq(Column#1, Column#5)]
├─IndexReader_36 10000.00 root index:IndexScan_35
│ └─IndexScan_35 10000.00 cop[tikv] table:a, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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:Column#12, funcs:count(Column#10), firstrow(Column#12)
└─TableReader_29 7992.00 root data:HashAgg_23
└─HashAgg_23 7992.00 cop[tikv] group by:Column#5, funcs:count(Column#5)
Expand Down Expand Up @@ -93,16 +93,16 @@ id count task operator info
StreamAgg_12 1.00 root funcs:sum(Column#12)
└─Projection_23 10000.00 root cast(Column#8)
└─HashLeftJoin_22 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_21, other cond:eq(Column#1, Column#4)
├─IndexReader_17 10000.00 root index:IndexScan_16
│ └─IndexScan_16 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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 Column#1
└─HashLeftJoin_19 9990.00 root inner join, inner:HashAgg_23, equal:[eq(Column#1, Column#5)]
├─IndexReader_34 10000.00 root index:IndexScan_33
│ └─IndexScan_33 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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:Column#5, funcs:firstrow(Column#5)
└─TableReader_30 9990.00 root data:Selection_29
└─Selection_29 9990.00 cop[tikv] not(isnull(Column#5))
Expand All @@ -123,8 +123,8 @@ explain select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1)
id count task operator info
Projection_12 10000.00 root eq(Column#2, Column#5)
└─Apply_14 10000.00 root CARTESIAN left outer join, inner:Projection_43
├─IndexReader_18 10000.00 root index:IndexScan_17
│ └─IndexScan_17 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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 Column#4, Column#5
└─IndexLookUp_42 1.00 root limit embedded(offset:0, count:1)
├─Limit_41 1.00 cop[tikv] offset:0, count:1
Expand Down Expand Up @@ -154,12 +154,12 @@ Limit_8 1.00 root offset:0, count: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
IndexReader_7 10000.00 root index:IndexScan_6
└─IndexScan_6 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
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
IndexReader_7 10000.00 root index:IndexScan_6
└─IndexScan_6 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
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
Expand Down Expand Up @@ -198,16 +198,16 @@ explain select 1 from (select count(c2), count(c3) from t1) k;
id count task operator info
Projection_5 1.00 root 1
└─StreamAgg_21 1.00 root funcs:firstrow(Column#15)
└─IndexReader_22 1.00 root index:StreamAgg_9
└─TableReader_22 1.00 root data:StreamAgg_9
└─StreamAgg_9 1.00 cop[tikv] funcs:firstrow(1)
└─IndexScan_20 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─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)
└─StreamAgg_27 1.00 root funcs:firstrow(Column#15)
└─IndexReader_28 1.00 root index:StreamAgg_15
└─TableReader_28 1.00 root data:StreamAgg_15
└─StreamAgg_15 1.00 cop[tikv] funcs:firstrow(1)
└─IndexScan_26 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─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)
Expand All @@ -220,16 +220,16 @@ id count task operator info
StreamAgg_12 1.00 root funcs:sum(Column#12)
└─Projection_23 10000.00 root cast(Column#8)
└─HashLeftJoin_22 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_21, other cond:eq(Column#1, Column#4)
├─IndexReader_17 10000.00 root index:IndexScan_16
│ └─IndexScan_16 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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#8
└─HashLeftJoin_7 10000.00 root CARTESIAN left outer semi join, inner:TableReader_14
├─IndexReader_11 10000.00 root index:IndexScan_10
│ └─IndexScan_10 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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, Column#5)
└─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
Expand All @@ -238,8 +238,8 @@ id count task operator info
StreamAgg_12 1.00 root funcs:sum(Column#12)
└─Projection_22 10000.00 root cast(Column#8)
└─HashLeftJoin_21 10000.00 root CARTESIAN left outer semi join, inner:TableReader_20
├─IndexReader_17 10000.00 root index:IndexScan_16
│ └─IndexScan_16 10000.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
├─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, Column#5)
└─TableScan_18 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
Expand All @@ -253,22 +253,22 @@ color=black
label = "root"
"StreamAgg_12" -> "Projection_23"
"Projection_23" -> "HashLeftJoin_22"
"HashLeftJoin_22" -> "IndexReader_17"
"HashLeftJoin_22" -> "TableReader_15"
"HashLeftJoin_22" -> "IndexReader_21"
}
subgraph cluster16{
subgraph cluster14{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"IndexScan_16"
"TableScan_14"
}
subgraph cluster20{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"IndexScan_20"
}
"IndexReader_17" -> "IndexScan_16"
"TableReader_15" -> "TableScan_14"
"IndexReader_21" -> "IndexScan_20"
}

Expand All @@ -281,22 +281,22 @@ node [style=filled, color=lightgrey]
color=black
label = "root"
"Projection_6" -> "HashLeftJoin_7"
"HashLeftJoin_7" -> "IndexReader_11"
"HashLeftJoin_7" -> "TableReader_9"
"HashLeftJoin_7" -> "TableReader_14"
}
subgraph cluster10{
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"IndexScan_10"
"TableScan_8"
}
subgraph cluster13{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_13" -> "TableScan_12"
}
"IndexReader_11" -> "IndexScan_10"
"TableReader_9" -> "TableScan_8"
"TableReader_14" -> "Selection_13"
}

Expand Down Expand Up @@ -415,9 +415,9 @@ 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
IndexReader_10 10.00 root index:Selection_9
└─Selection_9 10.00 cop[tikv] eq(Column#2, 1)
└─IndexScan_8 10000.00 cop[tikv] table:t, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
TableReader_7 10.00 root data:Selection_6
└─Selection_6 10.00 cop[tikv] in(Column#2, 1, 2), in(Column#2, 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
Expand All @@ -431,20 +431,20 @@ 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 Column#1, Column#2, Column#4, Column#5
└─HashRightJoin_9 0.00 root inner join, inner:IndexReader_15, equal:[eq(Column#5, Column#2)]
├─IndexReader_15 0.00 root index:Selection_14
│ └─Selection_14 0.00 cop[tikv] isnull(Column#5), not(isnull(Column#5))
│ └─IndexScan_13 10000.00 cop[tikv] table:t2, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_21 9990.00 root index:Selection_20
└─Selection_20 9990.00 cop[tikv] not(isnull(Column#2))
└─IndexScan_19 10000.00 cop[tikv] table:t1, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
└─HashRightJoin_9 0.00 root inner join, inner:TableReader_12, equal:[eq(Column#5, Column#2)]
├─TableReader_12 0.00 root data:Selection_11
│ └─Selection_11 0.00 cop[tikv] isnull(Column#5), not(isnull(Column#5))
│ └─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(Column#2))
└─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:IndexReader_17, equal:[eq(Column#2, Column#5)]
├─IndexReader_13 10000.00 root index:IndexScan_12
│ └─IndexScan_12 10000.00 cop[tikv] table:t1, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_17 10000.00 root index:IndexScan_16
└─IndexScan_16 10000.00 cop[tikv] table:t2, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
HashLeftJoin_9 8000.00 root anti semi join, inner:TableReader_15, equal:[eq(Column#2, Column#5)]
├─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;
Expand Down
24 changes: 12 additions & 12 deletions cmd/explaintest/r/explain_easy_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ 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 1985.00 root cast(Column#9)
└─HashLeftJoin_21 1985.00 root inner join, inner:HashAgg_25, equal:[eq(Column#1, Column#5)]
├─IndexReader_36 1999.00 root index:IndexScan_35
│ └─IndexScan_35 1999.00 cop[tikv] table:a, index:c2, range:[NULL,+inf], keep order:false
├─TableReader_34 1999.00 root data:TableScan_33
│ └─TableScan_33 1999.00 cop[tikv] table:a, range:[-inf,+inf], keep order:false
└─HashAgg_25 1985.00 root group by:Column#5, funcs:count(Column#5), firstrow(Column#5)
└─TableReader_32 1985.00 root data:Selection_31
└─Selection_31 1985.00 cop[tikv] not(isnull(Column#5))
Expand All @@ -94,8 +94,8 @@ explain select c1 from t1 where c1 in (select c2 from t2);
id count task operator info
Projection_9 1985.00 root Column#1
└─HashLeftJoin_19 1985.00 root inner join, inner:HashAgg_23, equal:[eq(Column#1, Column#5)]
├─IndexReader_34 1999.00 root index:IndexScan_33
│ └─IndexScan_33 1999.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false
├─TableReader_32 1999.00 root data:TableScan_31
│ └─TableScan_31 1999.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false
└─HashAgg_23 1985.00 root group by:Column#5, funcs:firstrow(Column#5)
└─TableReader_30 1985.00 root data:Selection_29
└─Selection_29 1985.00 cop[tikv] not(isnull(Column#5))
Expand All @@ -107,8 +107,8 @@ explain select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1)
id count task operator info
Projection_12 1999.00 root eq(Column#2, Column#5)
└─Apply_14 1999.00 root CARTESIAN left outer join, inner:Projection_43
├─IndexReader_18 1999.00 root index:IndexScan_17
│ └─IndexScan_17 1999.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false
├─TableReader_16 1999.00 root data:TableScan_15
│ └─TableScan_15 1999.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false
└─Projection_43 1.00 root Column#4, Column#5
└─IndexLookUp_42 1.00 root limit embedded(offset:0, count:1)
├─Limit_41 1.00 cop[tikv] offset:0, count:1
Expand All @@ -125,8 +125,8 @@ explain select 1 in (select c2 from t2) from t1;
id count task operator info
Projection_6 1999.00 root Column#8
└─HashLeftJoin_7 1999.00 root CARTESIAN left outer semi join, inner:TableReader_14
├─IndexReader_11 1999.00 root index:IndexScan_10
│ └─IndexScan_10 1999.00 cop[tikv] table:t1, index:c2, range:[NULL,+inf], keep order:false
├─TableReader_9 1999.00 root data:TableScan_8
│ └─TableScan_8 1999.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false
└─TableReader_14 0.00 root data:Selection_13
└─Selection_13 0.00 cop[tikv] eq(1, Column#5)
└─TableScan_12 1985.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false
Expand All @@ -139,22 +139,22 @@ node [style=filled, color=lightgrey]
color=black
label = "root"
"Projection_6" -> "HashLeftJoin_7"
"HashLeftJoin_7" -> "IndexReader_11"
"HashLeftJoin_7" -> "TableReader_9"
"HashLeftJoin_7" -> "TableReader_14"
}
subgraph cluster10{
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"IndexScan_10"
"TableScan_8"
}
subgraph cluster13{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_13" -> "TableScan_12"
}
"IndexReader_11" -> "IndexScan_10"
"TableReader_9" -> "TableScan_8"
"TableReader_14" -> "Selection_13"
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ create table t (a int, b int, c int, key idx(a, b, c));
explain select count(a) from t;
id count task operator info
StreamAgg_20 1.00 root funcs:count(Column#14)
└─IndexReader_21 1.00 root index:StreamAgg_8
└─TableReader_21 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tikv] funcs:count(Column#1)
└─IndexScan_19 10000.00 cop[tikv] table:t, index:a, b, c, range:[NULL,+inf], keep order:false, stats:pseudo
└─TableScan_18 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
select count(a) from t;
count(a)
0
Expand Down
Loading

0 comments on commit 6fd74f3

Please sign in to comment.