Skip to content

Commit

Permalink
release 3.1: port tiflash support from master to release3.1 (#14537)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored Feb 14, 2020
1 parent 1516653 commit 1bea8ee
Show file tree
Hide file tree
Showing 133 changed files with 7,213 additions and 3,213 deletions.
56 changes: 28 additions & 28 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,23 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
tk.MustQuery("explain SELECT * from t1,t2 where t1.id = t2.id").Check(testkit.Rows(
"HashLeftJoin_8 12487.50 root inner join, inner:TableReader_15, equal:[eq(test.t1.id, test.t2.id)]",
"├─TableReader_12 9990.00 root data:Selection_11",
"│ └─Selection_11 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_10 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_11 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_10 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─TableReader_15 9990.00 root data:Selection_14",
" └─Selection_14 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_13 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_14 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_13 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))

tk.MustQuery("explain SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id").Check(testkit.Rows(
"MergeJoin_7 12487.50 root inner join, left key:test.t1.id, right key:test.t2.id",
"├─Sort_11 9990.00 root test.t1.id:asc",
"│ └─TableReader_10 9990.00 root data:Selection_9",
"│ └─Selection_9 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_9 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─Sort_15 9990.00 root test.t2.id:asc",
" └─TableReader_14 9990.00 root data:Selection_13",
" └─Selection_13 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_13 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))

tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id")
Expand All @@ -356,12 +356,12 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
"MergeJoin_7 12487.50 root inner join, left key:test.t1.id, right key:test.t2.id",
"├─Sort_11 9990.00 root test.t1.id:asc",
"│ └─TableReader_10 9990.00 root data:Selection_9",
"│ └─Selection_9 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_9 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─Sort_15 9990.00 root test.t2.id:asc",
" └─TableReader_14 9990.00 root data:Selection_13",
" └─Selection_13 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_13 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))
pb := &dto.Metric{}
metrics.BindUsageCounter.WithLabelValues(metrics.ScopeGlobal).Write(pb)
Expand All @@ -372,11 +372,11 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
tk.MustQuery("explain SELECT * from t1,t2 where t1.id = t2.id").Check(testkit.Rows(
"HashLeftJoin_8 12487.50 root inner join, inner:TableReader_15, equal:[eq(test.t1.id, test.t2.id)]",
"├─TableReader_12 9990.00 root data:Selection_11",
"│ └─Selection_11 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_10 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_11 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_10 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─TableReader_15 9990.00 root data:Selection_14",
" └─Selection_14 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_13 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_14 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_13 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))
}

Expand All @@ -392,23 +392,23 @@ func (s *testSuite) TestExplain(c *C) {
tk.MustQuery("explain SELECT * from t1,t2 where t1.id = t2.id;").Check(testkit.Rows(
"HashLeftJoin_8 12487.50 root inner join, inner:TableReader_15, equal:[eq(test.t1.id, test.t2.id)]",
"├─TableReader_12 9990.00 root data:Selection_11",
"│ └─Selection_11 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_10 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_11 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_10 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─TableReader_15 9990.00 root data:Selection_14",
" └─Selection_14 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_13 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_14 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_13 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))

tk.MustQuery("explain SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id;").Check(testkit.Rows(
"MergeJoin_7 12487.50 root inner join, left key:test.t1.id, right key:test.t2.id",
"├─Sort_11 9990.00 root test.t1.id:asc",
"│ └─TableReader_10 9990.00 root data:Selection_9",
"│ └─Selection_9 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_9 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─Sort_15 9990.00 root test.t2.id:asc",
" └─TableReader_14 9990.00 root data:Selection_13",
" └─Selection_13 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_13 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))

tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id")
Expand All @@ -417,12 +417,12 @@ func (s *testSuite) TestExplain(c *C) {
"MergeJoin_7 12487.50 root inner join, left key:test.t1.id, right key:test.t2.id",
"├─Sort_11 9990.00 root test.t1.id:asc",
"│ └─TableReader_10 9990.00 root data:Selection_9",
"│ └─Selection_9 9990.00 cop not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"│ └─Selection_9 9990.00 cop[tikv] not(isnull(test.t1.id))",
"│ └─TableScan_8 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo",
"└─Sort_15 9990.00 root test.t2.id:asc",
" └─TableReader_14 9990.00 root data:Selection_13",
" └─Selection_13 9990.00 cop not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Selection_13 9990.00 cop[tikv] not(isnull(test.t2.id))",
" └─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo",
))

tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id")
Expand Down
27 changes: 13 additions & 14 deletions cmd/explaintest/r/access_path_selection.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ KEY `IDX_ab` (`a`, `b`)
explain select a from access_path_selection where a < 3;
id count task operator info
IndexReader_6 3323.33 root index:IndexScan_5
└─IndexScan_5 3323.33 cop table:access_path_selection, index:a, range:[-inf,3), keep order:false, stats:pseudo
└─IndexScan_5 3323.33 cop[tikv] table:access_path_selection, index:a, range:[-inf,3), keep order:false, stats:pseudo
explain select a, b from access_path_selection where a < 3;
id count task operator info
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
└─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
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
IndexReader_10 3323.33 root index:Selection_9
└─Selection_9 3323.33 cop[tikv] lt(test.access_path_selection.b, 3)
└─IndexScan_8 10000.00 cop[tikv] table:access_path_selection, index:a, b, range:[NULL,+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
└─Selection_10 1104.45 cop lt(test.access_path_selection.b, 3)
└─IndexScan_9 3323.33 cop table:access_path_selection, index:a, b, range:[-inf,3), keep order:false, stats:pseudo
└─Selection_10 1104.45 cop[tikv] lt(test.access_path_selection.b, 3)
└─IndexScan_9 3323.33 cop[tikv] table:access_path_selection, index:a, b, range:[-inf,3), keep order:false, stats:pseudo
CREATE TABLE `outdated_statistics` (
`a` int,
`b` int,
Expand All @@ -40,19 +40,18 @@ insert into outdated_statistics values (1, 3, 3);
analyze table outdated_statistics index idx_ab;
explain select * from outdated_statistics where a=1 and b=1 and c=1;
id count task operator info
IndexLookUp_11 0.00 root
├─IndexScan_8 1.00 cop table:outdated_statistics, index:a, b, range:[1 1,1 1], keep order:false
└─Selection_10 0.00 cop eq(test.outdated_statistics.c, 1)
└─TableScan_9 1.00 cop table:outdated_statistics, keep order:false
TableReader_7 0.00 root data:Selection_6
└─Selection_6 0.00 cop[tikv] eq(test.outdated_statistics.a, 1), eq(test.outdated_statistics.b, 1), eq(test.outdated_statistics.c, 1)
└─TableScan_5 6.00 cop[tikv] table:outdated_statistics, range:[-inf,+inf], keep order:false
explain select a, b from access_path_selection order by _tidb_rowid;
id count task operator info
Projection_5 10000.00 root test.access_path_selection.a, test.access_path_selection.b
└─TableReader_11 10000.00 root data:TableScan_10
└─TableScan_10 10000.00 cop table:access_path_selection, range:[-inf,+inf], keep order:true, stats:pseudo
└─TableScan_10 10000.00 cop[tikv] table:access_path_selection, range:[-inf,+inf], keep order:true, stats:pseudo
explain select max(_tidb_rowid) from access_path_selection;
id count task operator info
StreamAgg_13 1.00 root funcs:max(test.access_path_selection._tidb_rowid)
└─Limit_17 1.00 root offset:0, count:1
└─TableReader_42 1.00 root data:Limit_41
└─Limit_41 1.00 cop offset:0, count:1
└─TableScan_40 1.25 cop table:access_path_selection, range:[-inf,+inf], keep order:true, desc, stats:pseudo
└─Limit_41 1.00 cop[tikv] offset:0, count:1
└─TableScan_40 1.25 cop[tikv] table:access_path_selection, range:[-inf,+inf], keep order:true, desc, stats:pseudo
57 changes: 57 additions & 0 deletions cmd/explaintest/r/access_tiflash.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
drop table if exists t, tt;
create table t(a int, b int, index ia(a));
desc select avg(a) from t;
id count task operator info
StreamAgg_16 1.00 root funcs:avg(col_0, col_1)
└─IndexReader_17 1.00 root index:StreamAgg_8
└─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)
└─IndexScan_15 10000.00 cop[tikv] table:t, index:a, range:[NULL,+inf], keep order:false, stats:pseudo
desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t;
id count task operator info
StreamAgg_16 1.00 root funcs:avg(col_0, col_1)
└─TableReader_17 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tiflash] funcs:count(test.t.a), sum(test.t.a)
└─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t;
id count task operator info
StreamAgg_16 1.00 root funcs:sum(col_0)
└─TableReader_17 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tiflash] funcs:sum(test.t.a)
└─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t;
id count task operator info
StreamAgg_16 1.00 root funcs:sum(col_0)
└─TableReader_17 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tiflash] funcs:sum(plus(test.t.a, 1))
└─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t;
id count task operator info
StreamAgg_16 1.00 root funcs:sum(col_0)
└─TableReader_17 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tiflash] funcs:sum(isnull(test.t.a))
└─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
create table tt(a int, b int, primary key(a));
desc select * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55);
id count task operator info
TableReader_6 44.00 root data:TableScan_5
└─TableScan_5 44.00 cop[tikv] table:tt, range:(1,20), [30,55), keep order:false, stats:pseudo
desc select /*+ read_from_storage(tiflash[tt]) */ * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55);
id count task operator info
TableReader_7 44.00 root data:Selection_6
└─Selection_6 44.00 cop[tiflash] or(and(gt(test.tt.a, 1), lt(test.tt.a, 20)), and(ge(test.tt.a, 30), lt(test.tt.a, 55)))
└─TableScan_5 44.00 cop[tiflash] table:tt, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists ttt;
create table ttt (a int, primary key (a desc));
desc select * from ttt order by ttt.a desc;
id count task operator info
TableReader_11 10000.00 root data:TableScan_10
└─TableScan_10 10000.00 cop[tikv] table:ttt, range:[-inf,+inf], keep order:true, desc, stats:pseudo
desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a desc;
id count task operator info
Sort_4 10000.00 root test.ttt.a:desc
└─TableReader_8 10000.00 root data:TableScan_7
└─TableScan_7 10000.00 cop[tiflash] table:ttt, range:[-inf,+inf], keep order:false, stats:pseudo
desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a;
id count task operator info
TableReader_11 10000.00 root data:TableScan_10
└─TableScan_10 10000.00 cop[tiflash] table:ttt, range:[-inf,+inf], keep order:true, stats:pseudo
22 changes: 11 additions & 11 deletions cmd/explaintest/r/black_list.result
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,53 @@ create table t (a int);
explain select * from t where a < 1;
id count task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop lt(test.t.a, 1)
└─TableScan_5 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
insert into mysql.opt_rule_blacklist values('predicate_push_down');
admin reload opt_rule_blacklist;

explain select * from t where a < 1;
id count task operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
delete from mysql.opt_rule_blacklist where name='predicate_push_down';
admin reload opt_rule_blacklist;

explain select * from t where a < 1;
id count task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop lt(test.t.a, 1)
└─TableScan_5 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
insert into mysql.expr_pushdown_blacklist values('<');
admin reload expr_pushdown_blacklist;

explain select * from t where a < 1;
id count task operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
delete from mysql.expr_pushdown_blacklist where name='<';
admin reload expr_pushdown_blacklist;

explain select * from t where a < 1;
id count task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop lt(test.t.a, 1)
└─TableScan_5 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
insert into mysql.expr_pushdown_blacklist values('lt');
admin reload expr_pushdown_blacklist;

explain select * from t where a < 1;
id count task operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
delete from mysql.expr_pushdown_blacklist where name='lt';
admin reload expr_pushdown_blacklist;

explain select * from t where a < 1;
id count task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop lt(test.t.a, 1)
└─TableScan_5 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableScan_5 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
29 changes: 29 additions & 0 deletions cmd/explaintest/r/explain-non-select-stmt.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use test;
drop table if exists t;
create table t(a bigint, b bigint);
explain insert into t values(1, 1);
id count task operator info
Insert_1 N/A root N/A
explain insert into t select * from t;
id count task operator info
Insert_1 N/A root N/A
└─TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain delete from t where a > 100;
id count task operator info
Delete_3 N/A root N/A
└─TableReader_6 3333.33 root data:Selection_5
└─Selection_5 3333.33 cop[tikv] gt(Column#1, 100)
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain update t set b = 100 where a = 200;
id count task operator info
Update_3 N/A root N/A
└─TableReader_6 10.00 root data:Selection_5
└─Selection_5 10.00 cop[tikv] eq(Column#1, 200)
└─TableScan_4 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain replace into t select a, 100 from t;
id count task operator info
Insert_1 N/A root N/A
└─Projection_5 10000.00 root Column#3, 100
└─TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo
Loading

0 comments on commit 1bea8ee

Please sign in to comment.