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

*: add a column describing memory usage for table information_schema.processlist #10837

Merged
merged 8 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 13 additions & 2 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -275,17 +276,27 @@ 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",
Host: "localhost",
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"))
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion util/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down