Skip to content

Commit

Permalink
planner: generate index path as candidate when it is a single scan (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
francis0407 authored and zz-jason committed Sep 10, 2019
1 parent 7f1f66e commit 78ed282
Show file tree
Hide file tree
Showing 20 changed files with 937 additions and 910 deletions.
6 changes: 3 additions & 3 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 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
IndexLookUp_10 3323.33 root
├─IndexScan_8 3323.33 cop table:access_path_selection, index:b, range:[-inf,3), keep order:false, stats:pseudo
└─TableScan_9 3323.33 cop table:access_path_selection, keep order:false, stats:pseudo
IndexLookUp_7 3323.33 root
├─IndexScan_5 3323.33 cop table:access_path_selection, index:b, range:[-inf,3), keep order:false, stats:pseudo
└─TableScan_6 3323.33 cop table:access_path_selection, 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 Down
104 changes: 52 additions & 52 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ explain select sum(t1.c1 in (select c1 from t2)) from t1;
id count task operator info
StreamAgg_12 1.00 root funcs:sum(col_0)
└─Projection_19 10000.00 root cast(5_aux_0)
└─HashLeftJoin_18 10000.00 root CARTESIAN left outer semi join, inner:TableReader_17, other cond:eq(test.t1.c1, test.t2.c1)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_17 10000.00 root data:TableScan_16
└─TableScan_16 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashLeftJoin_18 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_17, other cond:eq(test.t1.c1, test.t2.c1)
├─IndexReader_15 10000.00 root index:IndexScan_14
│ └─IndexScan_14 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_17 10000.00 root index:IndexScan_16
└─IndexScan_16 10000.00 cop 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
Expand Down Expand Up @@ -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(test.t1.c2, test.t2.c2)
└─Apply_14 10000.00 root CARTESIAN left outer join, inner:Limit_21
├─TableReader_16 10000.00 root data:TableScan_15
│ └─TableScan_15 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
├─IndexReader_16 10000.00 root index:IndexScan_15
│ └─IndexScan_15 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─Limit_21 1.00 root offset:0, count:1
└─Projection_41 1.00 root test.t2.c1, test.t2.c2
└─IndexLookUp_40 1.00 root
Expand Down Expand Up @@ -155,12 +155,12 @@ Limit_8 1.00 root offset:0, count:1
└─TableScan_11 3.00 cop 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 table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
IndexReader_5 10000.00 root index:IndexScan_4
└─IndexScan_4 10000.00 cop table:t1, index:c2, range:[NULL,+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 table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
IndexReader_5 10000.00 root index:IndexScan_4
└─IndexScan_4 10000.00 cop table:t1, index:c2, range:[NULL,+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 All @@ -174,8 +174,8 @@ Union_17 26000.00 root
│ └─IndexReader_50 8000.00 root index:StreamAgg_41
│ └─StreamAgg_41 8000.00 cop group by:test.t2.c1, funcs:firstrow(test.t2.c1), firstrow(test.t2.c1)
│ └─IndexScan_48 10000.00 cop table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
└─TableReader_55 10000.00 root data:TableScan_54
└─TableScan_54 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexReader_55 10000.00 root index:IndexScan_54
└─IndexScan_54 10000.00 cop 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:c1, funcs:firstrow(join_agg_0)
Expand Down Expand Up @@ -204,16 +204,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_17 1.00 root funcs:firstrow(col_0)
└─TableReader_18 1.00 root data:StreamAgg_9
└─IndexReader_18 1.00 root index:StreamAgg_9
└─StreamAgg_9 1.00 cop funcs:firstrow(1)
└─TableScan_16 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexScan_16 10000.00 cop table:t1, index:c2, range:[NULL,+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_23 1.00 root funcs:firstrow(col_0)
└─TableReader_24 1.00 root data:StreamAgg_15
└─IndexReader_24 1.00 root index:StreamAgg_15
└─StreamAgg_15 1.00 cop funcs:firstrow(1)
└─TableScan_22 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexScan_22 10000.00 cop table:t1, index:c2, range:[NULL,+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 @@ -226,17 +226,17 @@ explain select sum(t1.c1 in (select c1 from t2)) from t1;
id count task operator info
StreamAgg_12 1.00 root funcs:sum(col_0)
└─Projection_19 10000.00 root cast(5_aux_0)
└─HashLeftJoin_18 10000.00 root CARTESIAN left outer semi join, inner:TableReader_17, other cond:eq(test.t1.c1, test.t2.c1)
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_17 10000.00 root data:TableScan_16
└─TableScan_16 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
└─HashLeftJoin_18 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_17, other cond:eq(test.t1.c1, test.t2.c1)
├─IndexReader_15 10000.00 root index:IndexScan_14
│ └─IndexScan_14 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_17 10000.00 root index:IndexScan_16
└─IndexScan_16 10000.00 cop 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 5_aux_0
└─HashLeftJoin_7 10000.00 root CARTESIAN left outer semi join, inner:TableReader_12
├─TableReader_9 10000.00 root data:TableScan_8
│ └─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
├─IndexReader_9 10000.00 root index:IndexScan_8
│ └─IndexScan_8 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─TableReader_12 10.00 root data:Selection_11
└─Selection_11 10.00 cop eq(1, test.t2.c2)
└─TableScan_10 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
Expand All @@ -245,8 +245,8 @@ id count task operator info
StreamAgg_12 1.00 root funcs:sum(col_0)
└─Projection_20 10000.00 root cast(5_aux_0)
└─HashLeftJoin_19 10000.00 root CARTESIAN left outer semi join, inner:TableReader_18
├─TableReader_15 10000.00 root data:TableScan_14
│ └─TableScan_14 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
├─IndexReader_15 10000.00 root index:IndexScan_14
│ └─IndexScan_14 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo
└─TableReader_18 10.00 root data:Selection_17
└─Selection_17 10.00 cop eq(6, test.t2.c2)
└─TableScan_16 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
Expand All @@ -260,23 +260,23 @@ color=black
label = "root"
"StreamAgg_12" -> "Projection_19"
"Projection_19" -> "HashLeftJoin_18"
"HashLeftJoin_18" -> "TableReader_15"
"HashLeftJoin_18" -> "TableReader_17"
"HashLeftJoin_18" -> "IndexReader_15"
"HashLeftJoin_18" -> "IndexReader_17"
}
subgraph cluster14{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_14"
"IndexScan_14"
}
subgraph cluster16{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_16"
"IndexScan_16"
}
"TableReader_15" -> "TableScan_14"
"TableReader_17" -> "TableScan_16"
"IndexReader_15" -> "IndexScan_14"
"IndexReader_17" -> "IndexScan_16"
}

explain format="dot" select 1 in (select c2 from t2) from t1;
Expand All @@ -288,22 +288,22 @@ node [style=filled, color=lightgrey]
color=black
label = "root"
"Projection_6" -> "HashLeftJoin_7"
"HashLeftJoin_7" -> "TableReader_9"
"HashLeftJoin_7" -> "IndexReader_9"
"HashLeftJoin_7" -> "TableReader_12"
}
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_8"
"IndexScan_8"
}
subgraph cluster11{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_11" -> "TableScan_10"
}
"TableReader_9" -> "TableScan_8"
"IndexReader_9" -> "IndexScan_8"
"TableReader_12" -> "Selection_11"
}

Expand Down Expand Up @@ -423,9 +423,9 @@ IndexReader_6 10.00 root index:IndexScan_5
└─IndexScan_5 10.00 cop 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 in(test.t.b, 1, 2), in(test.t.b, 1, 3)
└─TableScan_5 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
IndexReader_7 10.00 root index:Selection_6
└─Selection_6 10.00 cop eq(test.t.b, 1)
└─IndexScan_5 10000.00 cop table:t, index:a, b, range:[NULL,+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 @@ -439,20 +439,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 test.t1.a, test.t1.b, test.t2.a, test.t2.b
└─HashRightJoin_9 0.00 root inner join, inner:TableReader_12, equal:[eq(test.t2.b, test.t1.b)]
├─TableReader_12 0.00 root data:Selection_11
└─HashRightJoin_9 0.00 root inner join, inner:IndexReader_12, equal:[eq(test.t2.b, test.t1.b)]
├─IndexReader_12 0.00 root index:Selection_11
│ └─Selection_11 0.00 cop isnull(test.t2.b), not(isnull(test.t2.b))
│ └─TableScan_10 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_15 9990.00 root data:Selection_14
│ └─IndexScan_10 10000.00 cop table:t2, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_15 9990.00 root index:Selection_14
└─Selection_14 9990.00 cop not(isnull(test.t1.b))
└─TableScan_13 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexScan_13 10000.00 cop table:t1, index:a, b, range:[NULL,+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_13, equal:[eq(test.t1.b, test.t2.b)]
├─TableReader_11 10000.00 root data:TableScan_10
│ └─TableScan_10 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_13 10000.00 root data:TableScan_12
└─TableScan_12 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
HashLeftJoin_9 8000.00 root anti semi join, inner:IndexReader_13, equal:[eq(test.t1.b, test.t2.b)]
├─IndexReader_11 10000.00 root index:IndexScan_10
│ └─IndexScan_10 10000.00 cop table:t1, index:a, b, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_13 10000.00 root index:IndexScan_12
└─IndexScan_12 10000.00 cop table:t2, index:a, b, range:[NULL,+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 Expand Up @@ -484,12 +484,12 @@ 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
TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
IndexReader_7 10000.00 root index:IndexScan_6
└─IndexScan_6 10000.00 cop 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
TableReader_9 10000.00 root data:TableScan_8
└─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
IndexReader_9 10000.00 root index:IndexScan_8
└─IndexScan_8 10000.00 cop table:t1, index:a, b, range:[NULL,+inf], keep order:false, 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;
Expand Down
14 changes: 7 additions & 7 deletions cmd/explaintest/r/explain_easy_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,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(test.t1.c2, test.t2.c2)
└─Apply_14 1999.00 root CARTESIAN left outer join, inner:Limit_21
├─TableReader_16 1999.00 root data:TableScan_15
│ └─TableScan_15 1999.00 cop table:t1, range:[-inf,+inf], keep order:false
├─IndexReader_16 1999.00 root index:IndexScan_15
│ └─IndexScan_15 1999.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false
└─Limit_21 1.00 root offset:0, count:1
└─Projection_41 1.00 root test.t2.c1, test.t2.c2
└─IndexLookUp_40 1.00 root
Expand All @@ -128,8 +128,8 @@ explain select 1 in (select c2 from t2) from t1;
id count task operator info
Projection_6 1999.00 root 5_aux_0
└─HashLeftJoin_7 1999.00 root CARTESIAN left outer semi join, inner:TableReader_12
├─TableReader_9 1999.00 root data:TableScan_8
│ └─TableScan_8 1999.00 cop table:t1, range:[-inf,+inf], keep order:false
├─IndexReader_9 1999.00 root index:IndexScan_8
│ └─IndexScan_8 1999.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false
└─TableReader_12 0.00 root data:Selection_11
└─Selection_11 0.00 cop eq(1, test.t2.c2)
└─TableScan_10 1985.00 cop table:t2, range:[-inf,+inf], keep order:false
Expand All @@ -142,22 +142,22 @@ node [style=filled, color=lightgrey]
color=black
label = "root"
"Projection_6" -> "HashLeftJoin_7"
"HashLeftJoin_7" -> "TableReader_9"
"HashLeftJoin_7" -> "IndexReader_9"
"HashLeftJoin_7" -> "TableReader_12"
}
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_8"
"IndexScan_8"
}
subgraph cluster11{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_11" -> "TableScan_10"
}
"TableReader_9" -> "TableScan_8"
"IndexReader_9" -> "IndexScan_8"
"TableReader_12" -> "Selection_11"
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/explaintest/r/generated_columns.result
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ IndexReader_6 3323.33 root index:IndexScan_5
└─IndexScan_5 3323.33 cop table:sgc, index:a, b, range:[-inf,3), keep order:false, stats:pseudo
EXPLAIN SELECT a, b from sgc where b < 3;
id count task operator info
IndexLookUp_10 3323.33 root
├─IndexScan_8 3323.33 cop table:sgc, index:b, range:[-inf,3), keep order:false, stats:pseudo
└─TableScan_9 3323.33 cop table:sgc, keep order:false, stats:pseudo
IndexLookUp_7 3323.33 root
├─IndexScan_5 3323.33 cop table:sgc, index:b, range:[-inf,3), keep order:false, stats:pseudo
└─TableScan_6 3323.33 cop table:sgc, keep order:false, stats:pseudo
EXPLAIN SELECT a, b from sgc where a < 3 and b < 3;
id count task operator info
IndexReader_11 1104.45 root index:Selection_10
Expand Down
Loading

0 comments on commit 78ed282

Please sign in to comment.