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

infoschema: add digest for process list (#19622) #19829

Merged
merged 4 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ var tableProcesslistCols = []columnInfo{
{name: "TIME", tp: mysql.TypeLong, size: 7, flag: mysql.NotNullFlag, deflt: 0},
{name: "STATE", tp: mysql.TypeVarchar, size: 7},
{name: "INFO", tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
{name: "DIGEST", tp: mysql.TypeVarchar, size: 64, deflt: ""},
{name: "MEM", tp: mysql.TypeLonglong, size: 21, flag: mysql.UnsignedFlag},
{name: "TxnStart", tp: mysql.TypeVarchar, size: 64, flag: mysql.NotNullFlag, deflt: ""},
}
Expand Down
21 changes: 13 additions & 8 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (s *testTableSuite) TestInfoschemaFieldValue(c *C) {
" `TIME` int(7) NOT NULL DEFAULT 0,\n" +
" `STATE` varchar(7) DEFAULT NULL,\n" +
" `INFO` longtext DEFAULT NULL,\n" +
" `DIGEST` varchar(64) DEFAULT '',\n" +
" `MEM` bigint(21) unsigned DEFAULT NULL,\n" +
" `TxnStart` varchar(64) NOT NULL DEFAULT ''\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
Expand Down Expand Up @@ -457,6 +458,7 @@ func (s *testTableSuite) TestSomeTables(c *C) {
Host: "localhost",
DB: "information_schema",
Command: byte(1),
Digest: "abc1",
State: 1,
Info: "do something",
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
Expand All @@ -467,15 +469,16 @@ func (s *testTableSuite) TestSomeTables(c *C) {
Host: "localhost",
DB: "test",
Command: byte(2),
Digest: "abc2",
State: 2,
Info: strings.Repeat("x", 101),
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
}
tk.Se.SetSessionManager(sm)
tk.MustQuery("select * from information_schema.PROCESSLIST order by ID;").Sort().Check(
testkit.Rows(
fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s 0 ", "do something"),
fmt.Sprintf("2 user-2 localhost test Init DB 9223372036 2 %s 0 ", strings.Repeat("x", 101)),
fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s abc1 0 ", "do something"),
fmt.Sprintf("2 user-2 localhost test Init DB 9223372036 2 %s abc2 0 ", strings.Repeat("x", 101)),
))
tk.MustQuery("SHOW PROCESSLIST;").Sort().Check(
testkit.Rows(
Expand All @@ -495,6 +498,7 @@ func (s *testTableSuite) TestSomeTables(c *C) {
Host: "localhost",
DB: "information_schema",
Command: byte(1),
Digest: "abc1",
State: 1,
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
}
Expand All @@ -503,6 +507,7 @@ func (s *testTableSuite) TestSomeTables(c *C) {
User: "user-2",
Host: "localhost",
Command: byte(2),
Digest: "abc2",
State: 2,
Info: strings.Repeat("x", 101),
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
Expand All @@ -512,8 +517,8 @@ func (s *testTableSuite) TestSomeTables(c *C) {
tk.Se.GetSessionVars().TimeZone = time.UTC
tk.MustQuery("select * from information_schema.PROCESSLIST order by ID;").Check(
testkit.Rows(
fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s 0 ", "<nil>"),
fmt.Sprintf("2 user-2 localhost <nil> Init DB 9223372036 2 %s 0 07-29 03:26:05.158(410090409861578752)", strings.Repeat("x", 101)),
fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s abc1 0 ", "<nil>"),
fmt.Sprintf("2 user-2 localhost <nil> Init DB 9223372036 2 %s abc2 0 07-29 03:26:05.158(410090409861578752)", strings.Repeat("x", 101)),
))
tk.MustQuery("SHOW PROCESSLIST;").Sort().Check(
testkit.Rows(
Expand All @@ -527,11 +532,11 @@ func (s *testTableSuite) TestSomeTables(c *C) {
))
tk.MustQuery("select * from information_schema.PROCESSLIST where db is null;").Check(
testkit.Rows(
fmt.Sprintf("2 user-2 localhost <nil> Init DB 9223372036 2 %s 0 07-29 03:26:05.158(410090409861578752)", strings.Repeat("x", 101)),
fmt.Sprintf("2 user-2 localhost <nil> Init DB 9223372036 2 %s abc2 0 07-29 03:26:05.158(410090409861578752)", strings.Repeat("x", 101)),
))
tk.MustQuery("select * from information_schema.PROCESSLIST where Info is null;").Check(
testkit.Rows(
fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s 0 ", "<nil>"),
fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s abc1 0 ", "<nil>"),
))
}

Expand Down Expand Up @@ -789,7 +794,7 @@ func (s *testClusterTableSuite) TestSelectClusterTable(c *C) {
tk.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY`").Check(testkit.Rows("1"))
tk.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY` where time='2019-02-12 19:33:56.571953'").Check(testkit.Rows("1"))
tk.MustQuery("select count(*) from `CLUSTER_PROCESSLIST`").Check(testkit.Rows("1"))
tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 <nil> Query 9223372036 0 <nil> 0 "))
tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 <nil> Query 9223372036 0 <nil> 0 "))
tk.MustQuery("select query_time, conn_id from `CLUSTER_SLOW_QUERY` order by time limit 1").Check(testkit.Rows("4.895492 6"))
tk.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY` group by digest").Check(testkit.Rows("1"))
tk.MustQuery("select digest, count(*) from `CLUSTER_SLOW_QUERY` group by digest").Check(testkit.Rows("42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772 1"))
Expand Down Expand Up @@ -839,7 +844,7 @@ select * from t3;
tk.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY`").Check(testkit.Rows("4"))
tk.MustQuery("select count(*) from `SLOW_QUERY`").Check(testkit.Rows("4"))
tk.MustQuery("select count(*) from `CLUSTER_PROCESSLIST`").Check(testkit.Rows("1"))
tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 <nil> Query 9223372036 0 <nil> 0 "))
tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 <nil> Query 9223372036 0 <nil> 0 "))
tk.MustExec("create user user1")
tk.MustExec("create user user2")
user1 := testkit.NewTestKit(c, s.store)
Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte, maxExecu
StatsInfo: plannercore.GetStatsInfo,
MaxExecutionTime: maxExecutionTime,
}
_, pi.Digest = s.sessionVars.StmtCtx.SQLDigest()
if s.sessionVars.User != nil {
pi.User = s.sessionVars.User.Username
pi.Host = s.sessionVars.User.Hostname
Expand Down
2 changes: 1 addition & 1 deletion util/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (s *testMiscSuite) TestBasicFunc(c *C) {

row3 := pi.ToRow(time.UTC)
c.Assert(row3[:8], DeepEquals, row)
c.Assert(row3[8], Equals, int64(0))
c.Assert(row3[9], Equals, int64(0))

// Test for RandomBuf.
buf := fastrand.Buf(5)
Expand Down
3 changes: 2 additions & 1 deletion util/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ProcessInfo struct {
User string
Host string
DB string
Digest string
Plan interface{}
PlanExplainRows [][]string
Time time.Time
Expand Down Expand Up @@ -87,7 +88,7 @@ func (pi *ProcessInfo) ToRow(tz *time.Location) []interface{} {
if pi.StmtCtx != nil && pi.StmtCtx.MemTracker != nil {
bytesConsumed = pi.StmtCtx.MemTracker.BytesConsumed()
}
return append(pi.ToRowForShow(true), bytesConsumed, pi.txnStartTs(tz))
return append(pi.ToRowForShow(true), pi.Digest, bytesConsumed, pi.txnStartTs(tz))
}

// SessionManager is an interface for session manage. Show processlist and
Expand Down