Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: add three fields to statement summary table #39828

Merged
merged 29 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2e499f8
commit
fzzf678 Dec 7, 2022
11bdb75
Merge branch 'master' into add_field_stmtSummary
fzzf678 Dec 7, 2022
d7db77c
Merge branch 'master' into add_field_stmtSummary
fzzf678 Dec 8, 2022
c1682ac
Update tables.go
fzzf678 Dec 8, 2022
c5f158f
Merge branch 'master' into add_field_stmtSummary
fzzf678 Dec 8, 2022
c6c1fce
Update index_merge.result
fzzf678 Dec 8, 2022
f00de6b
Merge branch 'add_field_stmtSummary' of https://github.com/fzzf678/ti…
fzzf678 Dec 8, 2022
39b6a2d
ut
fzzf678 Dec 8, 2022
51e0423
Merge branch 'master' into add_field_stmtSummary
fzzf678 Dec 8, 2022
c07c34c
cluster
fzzf678 Dec 8, 2022
f849759
Merge branch 'add_field_stmtSummary' of https://github.com/fzzf678/ti…
fzzf678 Dec 8, 2022
0affe2a
fix ut
fzzf678 Dec 8, 2022
468da50
Merge remote-tracking branch 'upstream/master' into add_field_stmtSum…
fzzf678 Dec 9, 2022
dddf480
bazel
fzzf678 Dec 9, 2022
107d649
order by length(plan_hint)
fzzf678 Dec 9, 2022
ca5a094
Update planbuilder.go
fzzf678 Dec 12, 2022
102270b
Revert "Update planbuilder.go"
fzzf678 Dec 12, 2022
b58a0b6
Merge branch 'master' into add_field_stmt
fzzf678 Dec 12, 2022
44b7926
commit
fzzf678 Dec 12, 2022
99ff24f
commit
fzzf678 Dec 12, 2022
f65c0e5
Update tiflash_test.go
fzzf678 Dec 12, 2022
708d1ec
Update tables_test.go
fzzf678 Dec 12, 2022
8068b8b
Merge branch 'master' into add_field_stmt
fzzf678 Dec 12, 2022
23c3fab
Merge branch 'master' into add_field_stmt
hawkingrei Dec 12, 2022
08ca1ea
Update tables_test.go
fzzf678 Dec 12, 2022
4de5160
Merge branch 'add_field_stmt' of https://github.com/fzzf678/tidb into…
fzzf678 Dec 12, 2022
251dfe4
Update index_merge.result
fzzf678 Dec 12, 2022
edfebae
Merge branch 'master' into add_field_stmt
fzzf678 Dec 13, 2022
b9108c2
Merge branch 'master' into add_field_stmt
hawkingrei Dec 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
},
}