Skip to content

Commit e1374ff

Browse files
committed
*: add a column describing memory usage for table information_schema.processlist
Closes pingcap#10199
1 parent 1983b54 commit e1374ff

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

infoschema/tables.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ var tableProcesslistCols = []columnInfo{
543543
{"TIME", mysql.TypeLong, 7, mysql.NotNullFlag, 0, nil},
544544
{"STATE", mysql.TypeVarchar, 7, 0, nil, nil},
545545
{"INFO", mysql.TypeString, 512, 0, nil, nil},
546+
{"MEM", mysql.TypeLonglong, 21, 0, nil, nil},
546547
}
547548

548549
var tableTiDBIndexesCols = []columnInfo{
@@ -862,7 +863,7 @@ func dataForProcesslist(ctx sessionctx.Context) [][]types.Datum {
862863
continue
863864
}
864865

865-
rows := pi.ToRow(true)
866+
rows := pi.ToRowWithMem(true)
866867
record := types.MakeDatums(rows...)
867868
records = append(records, record)
868869
}

infoschema/tables_test.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func (s *testTableSuite) TestInfoschemaFieldValue(c *C) {
131131
User: "root",
132132
Host: "127.0.0.1",
133133
Command: mysql.ComQuery,
134+
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
134135
}
135136
tk.Se.SetSessionManager(sm)
136137
tk.MustQuery("SELECT user,host,command FROM information_schema.processlist;").Check(testkit.Rows("root 127.0.0.1 Query"))
@@ -342,17 +343,27 @@ func (s *testTableSuite) TestSomeTables(c *C) {
342343
DB: "information_schema",
343344
Command: byte(1),
344345
State: 1,
345-
Info: "do something"}
346+
Info: "do something",
347+
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
348+
}
346349
sm.processInfoMap[2] = &util.ProcessInfo{
347350
ID: 2,
348351
User: "user-2",
349352
Host: "localhost",
350353
DB: "test",
351354
Command: byte(2),
352355
State: 2,
353-
Info: "do something"}
356+
Info: "do something",
357+
StmtCtx: tk.Se.GetSessionVars().StmtCtx,
358+
}
354359
tk.Se.SetSessionManager(sm)
355360
tk.MustQuery("select * from information_schema.PROCESSLIST order by ID;").Check(
361+
testkit.Rows("1 user-1 localhost information_schema Quit 9223372036 1 do something 0",
362+
"2 user-2 localhost test Init DB 9223372036 2 do something 0"))
363+
tk.MustQuery("SHOW PROCESSLIST;").Check(
364+
testkit.Rows("1 user-1 localhost information_schema Quit 9223372036 1 do something",
365+
"2 user-2 localhost test Init DB 9223372036 2 do something"))
366+
tk.MustQuery("SHOW FULL PROCESSLIST;").Check(
356367
testkit.Rows("1 user-1 localhost information_schema Quit 9223372036 1 do something",
357368
"2 user-2 localhost test Init DB 9223372036 2 do something"))
358369

planner/core/logical_plans.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ type LogicalUnionScan struct {
327327
conditions []expression.Expression
328328
}
329329

330-
// DataSource represents a tablescan without condition push down.
330+
// DataSource represents a tableScan without condition push down.
331331
type DataSource struct {
332332
logicalSchemaProducer
333333

session/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var (
9898
sessionExecuteParseDurationGeneral = metrics.SessionExecuteParseDuration.WithLabelValues(metrics.LblGeneral)
9999
)
100100

101-
// Session context
101+
// Session context, it is consistent with the lifecycle of a client connection.
102102
type Session interface {
103103
sessionctx.Context
104104
Status() uint16 // Flag of current status, such as autocommit.

util/processinfo.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ProcessInfo struct {
4141
MaxExecutionTime uint64
4242
}
4343

44-
// ToRow returns []interface{} for the row data of "show processlist" and "select * from infoschema.processlist".
44+
// ToRow returns []interface{} for the row data of "show processlist".
4545
func (pi *ProcessInfo) ToRow(full bool) []interface{} {
4646
var info interface{}
4747
if pi.Info != nil {
@@ -64,6 +64,12 @@ func (pi *ProcessInfo) ToRow(full bool) []interface{} {
6464
}
6565
}
6666

67+
// ToRowWithMem returns []interface{} for the row data of
68+
// "select * from information_schema.processlist".
69+
func (pi *ProcessInfo) ToRowWithMem(full bool) []interface{} {
70+
return append(pi.ToRow(full), pi.StmtCtx.MemTracker.BytesConsumed())
71+
}
72+
6773
// SessionManager is an interface for session manage. Show processlist and
6874
// kill statement rely on this interface.
6975
type SessionManager interface {

0 commit comments

Comments
 (0)