Skip to content

Commit

Permalink
parser: support admin flush plan_cache (#30747)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reminiscent authored Dec 17, 2021
1 parent 93f21b9 commit dd95dd6
Show file tree
Hide file tree
Showing 5 changed files with 8,931 additions and 8,837 deletions.
27 changes: 23 additions & 4 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,7 @@ const (
AdminShowTelemetry
AdminResetTelemetryID
AdminReloadStatistics
AdminFlushPlanCache
)

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

type StatementScope int

const (
StatementScopeNone StatementScope = iota
StatementScopeSession
StatementScopeInstance
StatementScopeGlobal
)

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

Expand Down Expand Up @@ -1929,10 +1939,11 @@ type AdminStmt struct {
JobIDs []int64
JobNumber int64

HandleRanges []HandleRange
ShowSlow *ShowSlow
Plugins []string
Where ExprNode
HandleRanges []HandleRange
ShowSlow *ShowSlow
Plugins []string
Where ExprNode
StatementScope StatementScope
}

// Restore implements Node interface.
Expand Down Expand Up @@ -2070,6 +2081,14 @@ func (n *AdminStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("RESET TELEMETRY_ID")
case AdminReloadStatistics:
ctx.WriteKeyWord("RELOAD STATS_EXTENDED")
case AdminFlushPlanCache:
if n.StatementScope == StatementScopeSession {
ctx.WriteKeyWord("FLUSH SESSION PLAN_CACHE")
} else if n.StatementScope == StatementScopeInstance {
ctx.WriteKeyWord("FLUSH INSTANCE PLAN_CACHE")
} else if n.StatementScope == StatementScopeGlobal {
ctx.WriteKeyWord("FLUSH GLOBAL PLAN_CACHE")
}
default:
return errors.New("Unsupported AdminStmt type")
}
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ var tokenMap = map[string]int{
"PESSIMISTIC": pessimistic,
"PLACEMENT": placement,
"PLAN": plan,
"PLAN_CACHE": planCache,
"PLUGINS": plugins,
"POLICY": policy,
"POSITION": position,
Expand Down
Loading

0 comments on commit dd95dd6

Please sign in to comment.