From 75dd1c62a42f77217374927a31ce1539ac7b624a Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Tue, 18 Jun 2019 18:55:54 +0800 Subject: [PATCH] *: add a column describing memory usage for table information_schema.processlist Closes #10199 --- infoschema/tables.go | 3 ++- infoschema/tables_test.go | 15 +++++++++++++-- planner/core/logical_plans.go | 2 +- session/session.go | 2 +- util/processinfo.go | 8 +++++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index 697a68a7d1997..c79e489fa5bcf 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -543,6 +543,7 @@ var tableProcesslistCols = []columnInfo{ {"TIME", mysql.TypeLong, 7, mysql.NotNullFlag, 0, nil}, {"STATE", mysql.TypeVarchar, 7, 0, nil, nil}, {"INFO", mysql.TypeString, 512, 0, nil, nil}, + {"MEM", mysql.TypeLonglong, 21, 0, nil, nil}, } var tableTiDBIndexesCols = []columnInfo{ @@ -861,7 +862,7 @@ func dataForProcesslist(ctx sessionctx.Context) [][]types.Datum { continue } - rows := pi.ToRow(true) + rows := pi.ToRowWithMem(true) record := types.MakeDatums(rows...) records = append(records, record) } diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 6788d585656d3..71fd684744504 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -114,6 +114,7 @@ func (s *testTableSuite) TestInfoschemaFieldValue(c *C) { User: "root", Host: "127.0.0.1", Command: mysql.ComQuery, + StmtCtx: tk.Se.GetSessionVars().StmtCtx, } tk.Se.SetSessionManager(sm) tk.MustQuery("SELECT user,host,command FROM information_schema.processlist;").Check(testkit.Rows("root 127.0.0.1 Query")) @@ -275,7 +276,9 @@ func (s *testTableSuite) TestSomeTables(c *C) { DB: "information_schema", Command: byte(1), State: 1, - Info: "do something"} + Info: "do something", + StmtCtx: tk.Se.GetSessionVars().StmtCtx, + } sm.processInfoMap[2] = &util.ProcessInfo{ ID: 2, User: "user-2", @@ -283,9 +286,17 @@ func (s *testTableSuite) TestSomeTables(c *C) { DB: "test", Command: byte(2), State: 2, - Info: "do something"} + Info: "do something", + StmtCtx: tk.Se.GetSessionVars().StmtCtx, + } tk.Se.SetSessionManager(sm) tk.MustQuery("select * from information_schema.PROCESSLIST order by ID;").Check( + testkit.Rows("1 user-1 localhost information_schema Quit 9223372036 1 do something 0", + "2 user-2 localhost test Init DB 9223372036 2 do something 0")) + tk.MustQuery("SHOW PROCESSLIST;").Check( + testkit.Rows("1 user-1 localhost information_schema Quit 9223372036 1 do something", + "2 user-2 localhost test Init DB 9223372036 2 do something")) + tk.MustQuery("SHOW FULL PROCESSLIST;").Check( testkit.Rows("1 user-1 localhost information_schema Quit 9223372036 1 do something", "2 user-2 localhost test Init DB 9223372036 2 do something")) } diff --git a/planner/core/logical_plans.go b/planner/core/logical_plans.go index 578a7789839f5..d4b97e274e09f 100644 --- a/planner/core/logical_plans.go +++ b/planner/core/logical_plans.go @@ -318,7 +318,7 @@ type LogicalUnionScan struct { conditions []expression.Expression } -// DataSource represents a tablescan without condition push down. +// DataSource represents a tableScan without condition push down. type DataSource struct { logicalSchemaProducer diff --git a/session/session.go b/session/session.go index f4ceac566ae62..9882fffb85e11 100644 --- a/session/session.go +++ b/session/session.go @@ -97,7 +97,7 @@ var ( sessionExecuteParseDurationGeneral = metrics.SessionExecuteParseDuration.WithLabelValues(metrics.LblGeneral) ) -// Session context +// Session context, it is consistent with the lifecycle of a client connection. type Session interface { sessionctx.Context Status() uint16 // Flag of current status, such as autocommit. diff --git a/util/processinfo.go b/util/processinfo.go index 956196cdfdb42..313d9c762caa0 100644 --- a/util/processinfo.go +++ b/util/processinfo.go @@ -38,7 +38,7 @@ type ProcessInfo struct { ExceedExpensiveTimeThresh bool } -// ToRow returns []interface{} for the row data of "show processlist" and "select * from infoschema.processlist". +// ToRow returns []interface{} for the row data of "show processlist". func (pi *ProcessInfo) ToRow(full bool) []interface{} { var info string if full { @@ -59,6 +59,12 @@ func (pi *ProcessInfo) ToRow(full bool) []interface{} { } } +// ToRowWithMem returns []interface{} for the row data of +// "select * from information_schema.processlist". +func (pi *ProcessInfo) ToRowWithMem(full bool) []interface{} { + return append(pi.ToRow(full), pi.StmtCtx.MemTracker.BytesConsumed()) +} + // SessionManager is an interface for session manage. Show processlist and // kill statement rely on this interface. type SessionManager interface {