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,executor: add PROCESSLIST table to INFORMMATION_SCHEMA database #7236

Merged
merged 3 commits into from
Aug 1, 2018
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
2 changes: 1 addition & 1 deletion executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (s *testSuite) TestAggregation(c *C) {

result = tk.MustQuery("select count(*) from information_schema.columns")
// When adding new memory columns in information_schema, please update this variable.
columnCountOfAllInformationSchemaTables := "749"
columnCountOfAllInformationSchemaTables := "757"
result.Check(testkit.Rows(columnCountOfAllInformationSchemaTables))

tk.MustExec("drop table if exists t1")
Expand Down
1 change: 1 addition & 0 deletions infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (*testSuite) TestInfoTables(c *C) {
"OPTIMIZER_TRACE",
"TABLESPACES",
"COLLATION_CHARACTER_SET_APPLICABILITY",
"PROCESSLIST",
}
for _, t := range info_tables {
tb, err1 := is.TableByName(model.NewCIStr(infoschema.Name), model.NewCIStr(t))
Expand Down
44 changes: 44 additions & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package infoschema
import (
"fmt"
"sort"
"time"

"github.com/juju/errors"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -63,6 +64,7 @@ const (
tableOptimizerTrace = "OPTIMIZER_TRACE"
tableTableSpaces = "TABLESPACES"
tableCollationCharacterSetApplicability = "COLLATION_CHARACTER_SET_APPLICABILITY"
tableProcesslist = "PROCESSLIST"
)

type columnInfo struct {
Expand Down Expand Up @@ -516,6 +518,17 @@ var tableCollationCharacterSetApplicabilityCols = []columnInfo{
{"CHARACTER_SET_NAME", mysql.TypeVarchar, 32, mysql.NotNullFlag, nil, nil},
}

var tableProcesslistCols = []columnInfo{
{"ID", mysql.TypeLonglong, 21, mysql.NotNullFlag, 0, nil},
{"USER", mysql.TypeVarchar, 16, mysql.NotNullFlag, "", nil},
{"HOST", mysql.TypeVarchar, 64, mysql.NotNullFlag, "", nil},
{"DB", mysql.TypeVarchar, 64, mysql.NotNullFlag, "", nil},
{"COMMAND", mysql.TypeVarchar, 16, mysql.NotNullFlag, "", nil},
{"TIME", mysql.TypeLong, 7, mysql.NotNullFlag, 0, nil},
{"STATE", mysql.TypeVarchar, 7, 0, nil, nil},
{"Info", mysql.TypeString, 512, 0, nil, nil},
}

func dataForCharacterSets() (records [][]types.Datum) {
records = append(records,
types.MakeDatums("ascii", "ascii_general_ci", "US ASCII", 1),
Expand Down Expand Up @@ -569,6 +582,34 @@ func dataForUserPrivileges(ctx sessionctx.Context) [][]types.Datum {
return pm.UserPrivilegesTable()
}

func dataForProcesslist(ctx sessionctx.Context) [][]types.Datum {
sm := ctx.GetSessionManager()
if sm == nil {
return nil
}

var records [][]types.Datum
pl := sm.ShowProcessList()
for _, pi := range pl {
var t uint64
if len(pi.Info) != 0 {
t = uint64(time.Since(pi.Time) / time.Second)
}
record := types.MakeDatums(
pi.ID,
pi.User,
pi.Host,
pi.DB,
pi.Command,
t,
fmt.Sprintf("%d", pi.State),
pi.Info,
)
records = append(records, record)
}
return records
}

func dataForEngines() (records [][]types.Datum) {
records = append(records,
types.MakeDatums("InnoDB", "DEFAULT", "Supports transactions, row-level locking, and foreign keys", "YES", "YES", "YES"),
Expand Down Expand Up @@ -1079,6 +1120,7 @@ var tableNameToColumns = map[string][]columnInfo{
tableOptimizerTrace: tableOptimizerTraceCols,
tableTableSpaces: tableTableSpacesCols,
tableCollationCharacterSetApplicability: tableCollationCharacterSetApplicabilityCols,
tableProcesslist: tableProcesslistCols,
}

func createInfoSchemaTable(handle *Handle, meta *model.TableInfo) *infoschemaTable {
Expand Down Expand Up @@ -1165,6 +1207,8 @@ func (it *infoschemaTable) getRows(ctx sessionctx.Context, cols []*table.Column)
case tableTableSpaces:
case tableCollationCharacterSetApplicability:
fullRows = dataForCollationCharacterSetApplicability()
case tableProcesslist:
fullRows = dataForProcesslist(ctx)
}
if err != nil {
return nil, errors.Trace(err)
Expand Down