Skip to content

Commit

Permalink
parser,ast: parse admin show slow statement (#7688)
Browse files Browse the repository at this point in the history
Add the following new syntax:
* admin show slow top [internal | all] N
* admin show slow recent N
  • Loading branch information
tiancaiamao authored Sep 26, 2018
1 parent f387dff commit b098b47
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
33 changes: 33 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ const (
AdminCheckIndexRange
AdminShowDDLJobQueries
AdminChecksumTable
AdminShowSlow
)

// HandleRange represents a range where handle value >= Begin and < End.
Expand All @@ -626,6 +627,37 @@ type HandleRange struct {
End int64
}

// ShowSlowType defines the type for SlowSlow statement.
type ShowSlowType int

const (
// ShowSlowTop is a ShowSlowType constant.
ShowSlowTop ShowSlowType = iota
// ShowSlowRecent is a ShowSlowType constant.
ShowSlowRecent
)

// ShowSlowKind defines the kind for SlowSlow statement when the type is ShowSlowTop.
type ShowSlowKind int

const (
// ShowSlowKindDefault is a ShowSlowKind constant.
ShowSlowKindDefault ShowSlowKind = iota
// ShowSlowKindInternal is a ShowSlowKind constant.
ShowSlowKindInternal
// ShowSlowKindAll is a ShowSlowKind constant.
ShowSlowKindAll
)

// ShowSlow is used for the following command:
// admin show slow top [ internal | all] N
// admin show slow recent N
type ShowSlow struct {
Tp ShowSlowType
Count uint64
Kind ShowSlowKind
}

// AdminStmt is the struct for Admin statement.
type AdminStmt struct {
stmtNode
Expand All @@ -637,6 +669,7 @@ type AdminStmt struct {
JobNumber int64

HandleRanges []HandleRange
ShowSlow *ShowSlow
}

// Accept implements Node Accept interface.
Expand Down
4 changes: 4 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ var tokenMap = map[string]int{
"INT8": int8Type,
"INTEGER": integerType,
"INTERVAL": interval,
"INTERNAL": internal,
"INTO": into,
"INVOKER": invoker,
"IS": is,
Expand Down Expand Up @@ -392,6 +393,7 @@ var tokenMap = map[string]int{
"RECOVER": recover,
"READ": read,
"REAL": realType,
"RECENT": recent,
"REDUNDANT": redundant,
"REFERENCES": references,
"REGEXP": regexpKwd,
Expand Down Expand Up @@ -426,6 +428,7 @@ var tokenMap = map[string]int{
"SHOW": show,
"SIGNED": signed,
"SLAVE": slave,
"SLOW": slow,
"SMALLINT": smallIntType,
"SNAPSHOT": snapshot,
"SOME": some,
Expand Down Expand Up @@ -472,6 +475,7 @@ var tokenMap = map[string]int{
"TINYINT": tinyIntType,
"TINYTEXT": tinytextType,
"TO": to,
"TOP": top,
"TRACE": trace,
"TRAILING": trailing,
"TRANSACTION": transaction,
Expand Down
51 changes: 48 additions & 3 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ import (
shared "SHARED"
signed "SIGNED"
slave "SLAVE"
slow "SLOW"
snapshot "SNAPSHOT"
sqlCache "SQL_CACHE"
sqlNoCache "SQL_NO_CACHE"
Expand Down Expand Up @@ -420,16 +421,19 @@ import (
getFormat "GET_FORMAT"
groupConcat "GROUP_CONCAT"
inplace "INPLACE"
internal "INTERNAL"
min "MIN"
max "MAX"
maxExecutionTime "MAX_EXECUTION_TIME"
now "NOW"
position "POSITION"
recent "RECENT"
subDate "SUBDATE"
sum "SUM"
substring "SUBSTRING"
timestampAdd "TIMESTAMPADD"
timestampDiff "TIMESTAMPDIFF"
top "TOP"
trim "TRIM"

/* The following tokens belong to TiDBKeyword. */
Expand Down Expand Up @@ -575,6 +579,7 @@ import (
UseStmt "USE statement"

%type <item>
AdminShowSlow "Admin Show Slow statement"
AlterTableOptionListOpt "alter table option list opt"
AlterTableSpec "Alter table specification"
AlterTableSpecList "Alter table specification list"
Expand Down Expand Up @@ -2815,7 +2820,7 @@ UnReservedKeyword:
| "REPEATABLE" | "COMMITTED" | "UNCOMMITTED" | "ONLY" | "SERIALIZABLE" | "LEVEL" | "VARIABLES" | "SQL_CACHE" | "INDEXES" | "PROCESSLIST"
| "SQL_NO_CACHE" | "DISABLE" | "ENABLE" | "REVERSE" | "PRIVILEGES" | "NO" | "BINLOG" | "FUNCTION" | "VIEW" | "MODIFY" | "EVENTS" | "PARTITIONS"
| "NONE" | "SUPER" | "EXCLUSIVE" | "STATS_PERSISTENT" | "ROW_COUNT" | "COALESCE" | "MONTH" | "PROCESS" | "PROFILES"
| "MICROSECOND" | "MINUTE" | "PLUGINS" | "QUERY" | "QUERIES" | "SECOND" | "SEPARATOR" | "SHARE" | "SHARED" | "MAX_CONNECTIONS_PER_HOUR" | "MAX_QUERIES_PER_HOUR" | "MAX_UPDATES_PER_HOUR"
| "MICROSECOND" | "MINUTE" | "PLUGINS" | "QUERY" | "QUERIES" | "SECOND" | "SEPARATOR" | "SHARE" | "SHARED" | "SLOW" | "MAX_CONNECTIONS_PER_HOUR" | "MAX_QUERIES_PER_HOUR" | "MAX_UPDATES_PER_HOUR"
| "MAX_USER_CONNECTIONS" | "REPLICATION" | "CLIENT" | "SLAVE" | "RELOAD" | "TEMPORARY" | "ROUTINE" | "EVENT" | "ALGORITHM" | "DEFINER" | "INVOKER" | "MERGE" | "TEMPTABLE" | "UNDEFINED" | "SECURITY" | "CASCADED" | "RECOVER"


Expand All @@ -2824,8 +2829,8 @@ TiDBKeyword:
"ADMIN" | "BUCKETS" | "CANCEL" | "DDL" | "JOBS" | "JOB" | "STATS" | "STATS_META" | "STATS_HISTOGRAMS" | "STATS_BUCKETS" | "STATS_HEALTHY" | "TIDB" | "TIDB_HJ" | "TIDB_SMJ" | "TIDB_INLJ"

NotKeywordToken:
"ADDDATE" | "BIT_AND" | "BIT_OR" | "BIT_XOR" | "CAST" | "COPY" | "COUNT" | "CURTIME" | "DATE_ADD" | "DATE_SUB" | "EXTRACT" | "GET_FORMAT" | "GROUP_CONCAT"
| "INPLACE" |"MIN" | "MAX" | "MAX_EXECUTION_TIME" | "NOW" | "POSITION" | "SUBDATE" | "SUBSTRING" | "SUM" | "TIMESTAMPADD" | "TIMESTAMPDIFF" | "TRIM"
"ADDDATE" | "BIT_AND" | "BIT_OR" | "BIT_XOR" | "CAST" | "COPY" | "COUNT" | "CURTIME" | "DATE_ADD" | "DATE_SUB" | "EXTRACT" | "GET_FORMAT" | "GROUP_CONCAT" | "INPLACE" | "INTERNAL"
|"MIN" | "MAX" | "MAX_EXECUTION_TIME" | "NOW" | "RECENT" | "POSITION" | "SUBDATE" | "SUBSTRING" | "SUM" | "TIMESTAMPADD" | "TIMESTAMPDIFF" | "TOP" | "TRIM"

/************************************************************************************
*
Expand Down Expand Up @@ -5221,6 +5226,46 @@ AdminStmt:
JobIDs: $6.([]int64),
}
}
| "ADMIN" "SHOW" "SLOW" AdminShowSlow
{
$$ = &ast.AdminStmt{
Tp: ast.AdminShowSlow,
ShowSlow: $4.(*ast.ShowSlow),
}
}

AdminShowSlow:
"RECENT" NUM
{
$$ = &ast.ShowSlow{
Tp: ast.ShowSlowRecent,
Count: getUint64FromNUM($2),
}
}
| "TOP" NUM
{
$$ = &ast.ShowSlow{
Tp: ast.ShowSlowTop,
Kind: ast.ShowSlowKindDefault,
Count: getUint64FromNUM($2),
}
}
| "TOP" "INTERNAL" NUM
{
$$ = &ast.ShowSlow{
Tp: ast.ShowSlowTop,
Kind: ast.ShowSlowKindInternal,
Count: getUint64FromNUM($3),
}
}
| "TOP" "ALL" NUM
{
$$ = &ast.ShowSlow{
Tp: ast.ShowSlowTop,
Kind: ast.ShowSlowKindAll,
Count: getUint64FromNUM($3),
}
}

HandleRangeList:
HandleRange
Expand Down
4 changes: 4 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ func (s *testParserSuite) TestDMLStmt(c *C) {
{"admin cancel ddl jobs 1, 2", true},
{"admin recover index t1 idx_a", true},
{"admin cleanup index t1 idx_a", true},
{"admin show slow top 3", true},
{"admin show slow top internal 7", true},
{"admin show slow top all 9", true},
{"admin show slow recent 11", true},

// for on duplicate key update
{"INSERT INTO t (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);", true},
Expand Down

0 comments on commit b098b47

Please sign in to comment.