Skip to content

Commit

Permalink
*: Refine Explain's format. (#15507)
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFall authored Mar 23, 2020
1 parent 981abb4 commit 21ee980
Show file tree
Hide file tree
Showing 56 changed files with 6,548 additions and 6,487 deletions.
12 changes: 6 additions & 6 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t1(id int)")
tk.MustExec("create table t2(id int)")
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue)

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 @@ -345,11 +345,11 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
metrics.BindUsageCounter.WithLabelValues(metrics.ScopeGlobal).Write(pb)
c.Assert(pb.GetCounter().GetValue(), Equals, float64(1))
tk.MustExec("set @@tidb_use_plan_baselines = 0")
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)

tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id")
tk.MustExec("set @@tidb_use_plan_baselines = 1")
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)
}

func (s *testSuite) TestExplain(c *C) {
Expand All @@ -361,7 +361,7 @@ func (s *testSuite) TestExplain(c *C) {
tk.MustExec("create table t1(id int)")
tk.MustExec("create table t2(id int)")

c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue)

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 @@ -383,14 +383,14 @@ func (s *testSuite) TestBindingSymbolList(c *C) {
// before binding
tk.MustQuery("select a, b from t where a = 3 limit 1, 100")
c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:ia")
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "a"), IsTrue)
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "ia(a)"), IsTrue)

tk.MustExec(`create global binding for select a, b from t where a = 1 limit 0, 1 using select a, b from t use index (ib) where a = 1 limit 0, 1`)

// after binding
tk.MustQuery("select a, b from t where a = 3 limit 1, 100")
c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:ib")
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "b"), IsTrue)
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "ib(b)"), IsTrue)

// Normalize
sql, hash := parser.NormalizeDigest("select a, b from t where a = 1 limit 0, 1")
Expand Down
60 changes: 30 additions & 30 deletions cmd/explaintest/r/access_path_selection.result
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ KEY `IDX_b` (`b`),
KEY `IDX_ab` (`a`, `b`)
);
explain select a from access_path_selection where a < 3;
id estRows task operator info
IndexReader_6 3323.33 root index:IndexRangeScan_5
└─IndexRangeScan_5 3323.33 cop[tikv] table:access_path_selection, index:a, range:[-inf,3), keep order:false, stats:pseudo
id estRows task access object operator info
IndexReader_6 3323.33 root index:IndexRangeScan_5
└─IndexRangeScan_5 3323.33 cop[tikv] table:access_path_selection, index:IDX_a(a) range:[-inf,3), keep order:false, stats:pseudo
explain select a, b from access_path_selection where a < 3;
id estRows task operator info
IndexReader_6 3323.33 root index:IndexRangeScan_5
└─IndexRangeScan_5 3323.33 cop[tikv] table:access_path_selection, index:a, b, range:[-inf,3), keep order:false, stats:pseudo
id estRows task access object operator info
IndexReader_6 3323.33 root index:IndexRangeScan_5
└─IndexRangeScan_5 3323.33 cop[tikv] table:access_path_selection, index:IDX_ab(a, b) range:[-inf,3), keep order:false, stats:pseudo
explain select a, b from access_path_selection where b < 3;
id estRows task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.access_path_selection.b, 3)
└─TableFullScan_5 10000.00 cop[tikv] table:access_path_selection, keep order:false, stats:pseudo
id estRows task access object operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.access_path_selection.b, 3)
└─TableFullScan_5 10000.00 cop[tikv] table:access_path_selection keep order:false, stats:pseudo
explain select a, b from access_path_selection where a < 3 and b < 3;
id estRows task operator info
IndexReader_11 1104.45 root index:Selection_10
└─Selection_10 1104.45 cop[tikv] lt(test.access_path_selection.b, 3)
└─IndexRangeScan_9 3323.33 cop[tikv] table:access_path_selection, index:a, b, range:[-inf,3), keep order:false, stats:pseudo
id estRows task access object operator info
IndexReader_11 1104.45 root index:Selection_10
└─Selection_10 1104.45 cop[tikv] lt(test.access_path_selection.b, 3)
└─IndexRangeScan_9 3323.33 cop[tikv] table:access_path_selection, index:IDX_ab(a, b) range:[-inf,3), keep order:false, stats:pseudo
explain select a, b from access_path_selection where a > 10 order by _tidb_rowid;
id estRows task operator info
Projection_6 3333.33 root test.access_path_selection.a, test.access_path_selection.b
└─TableReader_13 3333.33 root data:Selection_12
└─Selection_12 3333.33 cop[tikv] gt(test.access_path_selection.a, 10)
└─TableFullScan_11 10000.00 cop[tikv] table:access_path_selection, keep order:true, stats:pseudo
id estRows task access object operator info
Projection_6 3333.33 root test.access_path_selection.a, test.access_path_selection.b
└─TableReader_13 3333.33 root data:Selection_12
└─Selection_12 3333.33 cop[tikv] gt(test.access_path_selection.a, 10)
└─TableFullScan_11 10000.00 cop[tikv] table:access_path_selection keep order:true, stats:pseudo
explain select max(_tidb_rowid) from access_path_selection;
id estRows task operator info
StreamAgg_13 1.00 root funcs:max(test.access_path_selection._tidb_rowid)->Column#4
└─Limit_17 1.00 root offset:0, count:1
└─TableReader_27 1.00 root data:Limit_26
└─Limit_26 1.00 cop[tikv] offset:0, count:1
└─TableFullScan_25 1.25 cop[tikv] table:access_path_selection, keep order:true, desc, stats:pseudo
id estRows task access object operator info
StreamAgg_13 1.00 root funcs:max(test.access_path_selection._tidb_rowid)->Column#4
└─Limit_17 1.00 root offset:0, count:1
└─TableReader_27 1.00 root data:Limit_26
└─Limit_26 1.00 cop[tikv] offset:0, count:1
└─TableFullScan_25 1.25 cop[tikv] table:access_path_selection keep order:true, desc, stats:pseudo
explain select count(1) from access_path_selection;
id estRows task operator info
StreamAgg_28 1.00 root funcs:count(Column#18)->Column#4
└─TableReader_29 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tikv] funcs:count(1)->Column#18
└─TableFullScan_24 10000.00 cop[tikv] table:access_path_selection, keep order:false, stats:pseudo
id estRows task access object operator info
StreamAgg_28 1.00 root funcs:count(Column#18)->Column#4
└─TableReader_29 1.00 root data:StreamAgg_8
└─StreamAgg_8 1.00 cop[tikv] funcs:count(1)->Column#18
└─TableFullScan_24 10000.00 cop[tikv] table:access_path_selection keep order:false, stats:pseudo
56 changes: 28 additions & 28 deletions cmd/explaintest/r/black_list.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,55 @@ use test;
drop table if exists t;
create table t (a int);
explain select * from t where a < 1;
id estRows task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t 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 estRows task operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t 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 estRows task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t 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 estRows task operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t 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 estRows task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t 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 estRows task operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Selection_5 8000.00 root lt(test.t.a, 1)
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t 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 estRows task operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
TableReader_7 3323.33 root data:Selection_6
└─Selection_6 3323.33 cop[tikv] lt(test.t.a, 1)
└─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
42 changes: 21 additions & 21 deletions cmd/explaintest/r/explain-non-select-stmt.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ use test;
drop table if exists t;
create table t(a bigint, b bigint);
explain insert into t values(1, 1);
id estRows task operator info
Insert_1 N/A root N/A
id estRows task access object operator info
Insert_1 N/A root N/A
explain insert into t select * from t;
id estRows task operator info
Insert_1 N/A root N/A
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Insert_1 N/A root N/A
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain delete from t where a > 100;
id estRows task operator info
Delete_4 N/A root N/A
└─TableReader_8 3333.33 root data:Selection_7
└─Selection_7 3333.33 cop[tikv] gt(test.t.a, 100)
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Delete_4 N/A root N/A
└─TableReader_8 3333.33 root data:Selection_7
└─Selection_7 3333.33 cop[tikv] gt(test.t.a, 100)
└─TableFullScan_6 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain update t set b = 100 where a = 200;
id estRows task operator info
Update_4 N/A root N/A
└─TableReader_8 10.00 root data:Selection_7
└─Selection_7 10.00 cop[tikv] eq(test.t.a, 200)
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Update_4 N/A root N/A
└─TableReader_8 10.00 root data:Selection_7
└─Selection_7 10.00 cop[tikv] eq(test.t.a, 200)
└─TableFullScan_6 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain replace into t select a, 100 from t;
id estRows task operator info
Insert_1 N/A root N/A
└─Projection_5 10000.00 root test.t.a, 100->Column#6
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t, keep order:false, stats:pseudo
id estRows task access object operator info
Insert_1 N/A root N/A
└─Projection_5 10000.00 root test.t.a, 100->Column#6
└─TableReader_7 10000.00 root data:TableFullScan_6
└─TableFullScan_6 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
20 changes: 10 additions & 10 deletions cmd/explaintest/r/explain.result
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ create table t(id int primary key, a int, b int);
set session tidb_hashagg_partial_concurrency = 1;
set session tidb_hashagg_final_concurrency = 1;
explain select group_concat(a) from t group by id;
id estRows task operator info
StreamAgg_8 8000.00 root group by:Column#6, funcs:group_concat(Column#5, ",")->Column#4
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, test.t.id
└─TableReader_15 10000.00 root data:TableFullScan_14
└─TableFullScan_14 10000.00 cop[tikv] table:t, keep order:true, stats:pseudo
id estRows task access object operator info
StreamAgg_8 8000.00 root group by:Column#6, funcs:group_concat(Column#5, ",")->Column#4
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, test.t.id
└─TableReader_15 10000.00 root data:TableFullScan_14
└─TableFullScan_14 10000.00 cop[tikv] table:t keep order:true, stats:pseudo
explain select group_concat(a, b) from t group by id;
id estRows task operator info
StreamAgg_8 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6, ",")->Column#4
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id
└─TableReader_15 10000.00 root data:TableFullScan_14
└─TableFullScan_14 10000.00 cop[tikv] table:t, keep order:true, stats:pseudo
id estRows task access object operator info
StreamAgg_8 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6, ",")->Column#4
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id
└─TableReader_15 10000.00 root data:TableFullScan_14
└─TableFullScan_14 10000.00 cop[tikv] table:t keep order:true, stats:pseudo
drop table t;
Loading

0 comments on commit 21ee980

Please sign in to comment.