Skip to content

Commit

Permalink
planner: add three fields to statement summary table (#39828)
Browse files Browse the repository at this point in the history
ref #39199
  • Loading branch information
fzzf678 authored Dec 13, 2022
1 parent 33e5baa commit 3f86a11
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/explaintest/r/index_merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ c1 c2 c3
///// MEMORY Table
explain select count(c1) from (select /*+ use_index_merge(t_alias), stream_agg() */ count(1) c1 from information_schema.statements_summary where sum_latency >= 0 or max_latency >= 0 order by 1) dt;
id estRows task access object operator info
StreamAgg_10 1.00 root funcs:count(Column#93)->Column#94
└─Sort_11 1.00 root Column#93
└─StreamAgg_14 1.00 root funcs:count(1)->Column#93
StreamAgg_10 1.00 root funcs:count(Column#96)->Column#97
└─Sort_11 1.00 root Column#96
└─StreamAgg_14 1.00 root funcs:count(1)->Column#96
└─MemTableScan_18 10000.00 root table:STATEMENTS_SUMMARY
show warnings;
Level Code Message
Expand Down
3 changes: 3 additions & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,9 @@ var tableStatementsSummaryCols = []columnInfo{
{name: stmtsummary.PlanDigestStr, tp: mysql.TypeVarchar, size: 64, comment: "Digest of its execution plan"},
{name: stmtsummary.PlanStr, tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "Sampled execution plan"},
{name: stmtsummary.BinaryPlan, tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "Sampled binary plan"},
{name: stmtsummary.Charset, tp: mysql.TypeVarchar, size: 64, comment: "Sampled charset"},
{name: stmtsummary.Collation, tp: mysql.TypeVarchar, size: 64, comment: "Sampled collation"},
{name: stmtsummary.PlanHint, tp: mysql.TypeVarchar, size: 64, comment: "Sampled plan hint"},
}

var tableStorageStatsCols = []columnInfo{
Expand Down
30 changes: 30 additions & 0 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,33 @@ func TestMemoryUsageAndOpsHistory(t *testing.T) {
require.Equal(t, row[10], "e3237ec256015a3566757e0c2742507cd30ae04e4cac2fbc14d269eafe7b067b") // SQL_DIGEST
require.Equal(t, row[11], "explain analyze select * from t t1 join t t2 join t t3 on t1.a=t2.a and t1.a=t3.a order by t1.a") // SQL_TEXT
}

func TestAddFieldsForBinding(t *testing.T) {
s := new(clusterTablesSuite)
s.store, s.dom = testkit.CreateMockStoreAndDomain(t)
s.rpcserver, s.listenAddr = s.setUpRPCService(t, "127.0.0.1:0", nil)
s.httpServer, s.mockAddr = s.setUpMockPDHTTPServer()
s.startTime = time.Now()
defer s.httpServer.Close()
defer s.rpcserver.Stop()
tk := s.newTestKitWithRoot(t)

require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil))
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, key(a))")
tk.MustExec("select /*+ ignore_index(t, a)*/ * from t where a = 1")
planDigest := "4e3159169cc63c14b139a4e7d72eae1759875c9a9581f94bb2079aae961189cb"
rows := tk.MustQuery(fmt.Sprintf("select stmt_type, prepared, sample_user, schema_name, query_sample_text, charset, collation, plan_hint, digest_text "+
"from information_schema.cluster_statements_summary where plan_digest = '%s'", planDigest)).Rows()

require.Equal(t, rows[0][0], "Select")
require.Equal(t, rows[0][1], "0")
require.Equal(t, rows[0][2], "root")
require.Equal(t, rows[0][3], "test")
require.Equal(t, rows[0][4], "select /*+ ignore_index(t, a)*/ * from t where a = 1")
require.Equal(t, rows[0][5], "utf8mb4")
require.Equal(t, rows[0][6], "utf8mb4_bin")
require.Equal(t, rows[0][7], "use_index(@`sel_1` `test`.`t` ), ignore_index(`t` `a`)")
require.Equal(t, rows[0][8], "select * from `t` where `a` = ?")
}
12 changes: 12 additions & 0 deletions util/stmtsummary/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ const (
PlanDigestStr = "PLAN_DIGEST"
PlanStr = "PLAN"
BinaryPlan = "BINARY_PLAN"
Charset = "CHARSET"
Collation = "COLLATION"
PlanHint = "PLAN_HINT"
)

type columnValueFactory func(reader *stmtSummaryReader, ssElement *stmtSummaryByDigestElement, ssbd *stmtSummaryByDigest) interface{}
Expand Down Expand Up @@ -620,4 +623,13 @@ var columnValueFactoryMap = map[string]columnValueFactory{
BinaryPlan: func(_ *stmtSummaryReader, ssElement *stmtSummaryByDigestElement, _ *stmtSummaryByDigest) interface{} {
return ssElement.sampleBinaryPlan
},
Charset: func(_ *stmtSummaryReader, ssElement *stmtSummaryByDigestElement, _ *stmtSummaryByDigest) interface{} {
return ssElement.charset
},
Collation: func(_ *stmtSummaryReader, ssElement *stmtSummaryByDigestElement, _ *stmtSummaryByDigest) interface{} {
return ssElement.collation
},
PlanHint: func(_ *stmtSummaryReader, ssElement *stmtSummaryByDigestElement, _ *stmtSummaryByDigest) interface{} {
return ssElement.planHint
},
}

0 comments on commit 3f86a11

Please sign in to comment.