From d5defa04d9c8ba981fafdfcff92d1889f2187b6a Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Mon, 7 Sep 2020 13:23:39 +0800 Subject: [PATCH 1/2] cherry pick #19622 to release-4.0 Signed-off-by: ti-srebot --- infoschema/tables.go | 1 + infoschema/tables_test.go | 31 +++++++++++++++++++++++++++++++ session/session.go | 1 + util/misc_test.go | 2 +- util/processinfo.go | 3 ++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index ce2afb4954f65..a6c1881d56d03 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -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: ""}, } diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 91f75be8425c7..09ee65b6975ca 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -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")) @@ -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, @@ -467,6 +469,7 @@ 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, @@ -474,8 +477,13 @@ func (s *testTableSuite) TestSomeTables(c *C) { tk.Se.SetSessionManager(sm) tk.MustQuery("select * from information_schema.PROCESSLIST order by ID;").Sort().Check( testkit.Rows( +<<<<<<< HEAD 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 %s %s abc1 0 ", "in transaction", "do something"), + fmt.Sprintf("2 user-2 localhost test Init DB 9223372036 %s %s abc2 0 ", "autocommit", strings.Repeat("x", 101)), +>>>>>>> 4f9b350... infoschema: add digest for process list (#19622) )) tk.MustQuery("SHOW PROCESSLIST;").Sort().Check( testkit.Rows( @@ -495,6 +503,7 @@ func (s *testTableSuite) TestSomeTables(c *C) { Host: "localhost", DB: "information_schema", Command: byte(1), + Digest: "abc1", State: 1, StmtCtx: tk.Se.GetSessionVars().StmtCtx, } @@ -503,6 +512,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, @@ -512,8 +522,13 @@ 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( +<<<<<<< HEAD fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s 0 ", ""), fmt.Sprintf("2 user-2 localhost 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 %s %s abc1 0 ", "in transaction", ""), + fmt.Sprintf("2 user-2 localhost Init DB 9223372036 %s %s abc2 0 07-29 03:26:05.158(410090409861578752)", "autocommit", strings.Repeat("x", 101)), +>>>>>>> 4f9b350... infoschema: add digest for process list (#19622) )) tk.MustQuery("SHOW PROCESSLIST;").Sort().Check( testkit.Rows( @@ -527,11 +542,19 @@ func (s *testTableSuite) TestSomeTables(c *C) { )) tk.MustQuery("select * from information_schema.PROCESSLIST where db is null;").Check( testkit.Rows( +<<<<<<< HEAD fmt.Sprintf("2 user-2 localhost Init DB 9223372036 2 %s 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 ", ""), +======= + fmt.Sprintf("2 user-2 localhost Init DB 9223372036 %s %s abc2 0 07-29 03:26:05.158(410090409861578752)", "autocommit", 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 %s %s abc1 0 ", "in transaction", ""), +>>>>>>> 4f9b350... infoschema: add digest for process list (#19622) )) } @@ -789,7 +812,11 @@ 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")) +<<<<<<< HEAD tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 Query 9223372036 0 0 ")) +======= + tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(fmt.Sprintf(":10080 1 root 127.0.0.1 Query 9223372036 %s 0 ", ""))) +>>>>>>> 4f9b350... infoschema: add digest for process list (#19622) 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")) @@ -839,7 +866,11 @@ 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")) +<<<<<<< HEAD tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 Query 9223372036 0 0 ")) +======= + tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(fmt.Sprintf(":10080 1 root 127.0.0.1 Query 9223372036 %s 0 ", ""))) +>>>>>>> 4f9b350... infoschema: add digest for process list (#19622) tk.MustExec("create user user1") tk.MustExec("create user user2") user1 := testkit.NewTestKit(c, s.store) diff --git a/session/session.go b/session/session.go index 926677fa5fb3b..29ddd9b975d75 100644 --- a/session/session.go +++ b/session/session.go @@ -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 diff --git a/util/misc_test.go b/util/misc_test.go index cc379ca94d201..599c3df6fa730 100644 --- a/util/misc_test.go +++ b/util/misc_test.go @@ -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) diff --git a/util/processinfo.go b/util/processinfo.go index 982b741db1f04..c7614ad798175 100644 --- a/util/processinfo.go +++ b/util/processinfo.go @@ -29,6 +29,7 @@ type ProcessInfo struct { User string Host string DB string + Digest string Plan interface{} PlanExplainRows [][]string Time time.Time @@ -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 From 900bdf3f1e7556e25f639f74afa535b52490add6 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Mon, 7 Sep 2020 14:36:15 +0800 Subject: [PATCH 2/2] fix conflicts --- infoschema/tables_test.go | 42 ++++++++------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 09ee65b6975ca..b3c20948611a6 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -477,13 +477,8 @@ func (s *testTableSuite) TestSomeTables(c *C) { tk.Se.SetSessionManager(sm) tk.MustQuery("select * from information_schema.PROCESSLIST order by ID;").Sort().Check( testkit.Rows( -<<<<<<< HEAD - 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 %s %s abc1 0 ", "in transaction", "do something"), - fmt.Sprintf("2 user-2 localhost test Init DB 9223372036 %s %s abc2 0 ", "autocommit", strings.Repeat("x", 101)), ->>>>>>> 4f9b350... infoschema: add digest for process list (#19622) + 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( @@ -522,13 +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( -<<<<<<< HEAD - fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s 0 ", ""), - fmt.Sprintf("2 user-2 localhost 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 %s %s abc1 0 ", "in transaction", ""), - fmt.Sprintf("2 user-2 localhost Init DB 9223372036 %s %s abc2 0 07-29 03:26:05.158(410090409861578752)", "autocommit", strings.Repeat("x", 101)), ->>>>>>> 4f9b350... infoschema: add digest for process list (#19622) + fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s abc1 0 ", ""), + fmt.Sprintf("2 user-2 localhost 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( @@ -542,19 +532,11 @@ func (s *testTableSuite) TestSomeTables(c *C) { )) tk.MustQuery("select * from information_schema.PROCESSLIST where db is null;").Check( testkit.Rows( -<<<<<<< HEAD - fmt.Sprintf("2 user-2 localhost Init DB 9223372036 2 %s 0 07-29 03:26:05.158(410090409861578752)", strings.Repeat("x", 101)), + fmt.Sprintf("2 user-2 localhost 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 ", ""), -======= - fmt.Sprintf("2 user-2 localhost Init DB 9223372036 %s %s abc2 0 07-29 03:26:05.158(410090409861578752)", "autocommit", 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 %s %s abc1 0 ", "in transaction", ""), ->>>>>>> 4f9b350... infoschema: add digest for process list (#19622) + fmt.Sprintf("1 user-1 localhost information_schema Quit 9223372036 1 %s abc1 0 ", ""), )) } @@ -812,11 +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")) -<<<<<<< HEAD - tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 Query 9223372036 0 0 ")) -======= - tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(fmt.Sprintf(":10080 1 root 127.0.0.1 Query 9223372036 %s 0 ", ""))) ->>>>>>> 4f9b350... infoschema: add digest for process list (#19622) + tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 Query 9223372036 0 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")) @@ -866,11 +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")) -<<<<<<< HEAD - tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 Query 9223372036 0 0 ")) -======= - tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(fmt.Sprintf(":10080 1 root 127.0.0.1 Query 9223372036 %s 0 ", ""))) ->>>>>>> 4f9b350... infoschema: add digest for process list (#19622) + tk.MustQuery("select * from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(":10080 1 root 127.0.0.1 Query 9223372036 0 0 ")) tk.MustExec("create user user1") tk.MustExec("create user user2") user1 := testkit.NewTestKit(c, s.store)