Skip to content

Commit

Permalink
parser, executor: support show/set session_states (#35263)
Browse files Browse the repository at this point in the history
close #35259
  • Loading branch information
djshow832 authored Jun 10, 2022
1 parent fb67ee4 commit 5d4745e
Show file tree
Hide file tree
Showing 10 changed files with 8,949 additions and 8,862 deletions.
9 changes: 9 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6070,3 +6070,12 @@ func TestIsFastPlan(t *testing.T) {
require.Equal(t, ca.isFastPlan, ok)
}
}

func TestShowSessionStates(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustQuery("show session_states").Check(testkit.Rows())
tk.MustExec("set session_states 'x'")
tk.MustGetErrCode("set session_states 1", errno.ErrParse)
}
6 changes: 6 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ func (e *ShowExec) fetchAll(ctx context.Context) error {
return e.fetchShowPlacementForTable(ctx)
case ast.ShowPlacementForPartition:
return e.fetchShowPlacementForPartition(ctx)
case ast.ShowSessionStates:
return e.fetchShowSessionStates(ctx)
}
return nil
}
Expand Down Expand Up @@ -1927,6 +1929,10 @@ func (e *ShowExec) fetchShowBuiltins() error {
return nil
}

func (e *ShowExec) fetchShowSessionStates(ctx context.Context) error {
return nil
}

// tryFillViewColumnType fill the columns type info of a view.
// Because view's underlying table's column could change or recreate, so view's column type may change over time.
// To avoid this situation we need to generate a logical plan and extract current column types from Schema.
Expand Down
6 changes: 6 additions & 0 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func (e *SimpleExec) Next(ctx context.Context, req *chunk.Chunk) (err error) {
err = e.executeRenameUser(x)
case *ast.SetPwdStmt:
err = e.executeSetPwd(ctx, x)
case *ast.SetSessionStatesStmt:
err = e.executeSetSessionStates(ctx, x)
case *ast.KillStmt:
err = e.executeKillStmt(ctx, x)
case *ast.BinlogStmt:
Expand Down Expand Up @@ -1684,6 +1686,10 @@ func asyncDelayShutdown(p *os.Process, delay time.Duration) {
}
}

func (e *SimpleExec) executeSetSessionStates(ctx context.Context, s *ast.SetSessionStatesStmt) error {
return nil
}

func (e *SimpleExec) executeAdmin(s *ast.AdminStmt) error {
switch s.Tp {
case ast.AdminReloadStatistics:
Expand Down
3 changes: 3 additions & 0 deletions parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,7 @@ const (
ShowPlacementForTable
ShowPlacementForPartition
ShowPlacementLabels
ShowSessionStates
)

const (
Expand Down Expand Up @@ -3025,6 +3026,8 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("PLACEMENT")
case ShowPlacementLabels:
ctx.WriteKeyWord("PLACEMENT LABELS")
case ShowSessionStates:
ctx.WriteKeyWord("SESSION_STATES")
default:
return errors.New("Unknown ShowStmt type")
}
Expand Down
23 changes: 23 additions & 0 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
_ StmtNode = &SetRoleStmt{}
_ StmtNode = &SetDefaultRoleStmt{}
_ StmtNode = &SetStmt{}
_ StmtNode = &SetSessionStatesStmt{}
_ StmtNode = &UseStmt{}
_ StmtNode = &FlushStmt{}
_ StmtNode = &KillStmt{}
Expand Down Expand Up @@ -1055,6 +1056,28 @@ func (n *SetConfigStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// SetSessionStatesStmt is a statement to restore session states.
type SetSessionStatesStmt struct {
stmtNode

SessionStates string
}

func (n *SetSessionStatesStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("SET SESSION_STATES ")
ctx.WriteString(n.SessionStates)
return nil
}

func (n *SetSessionStatesStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*SetSessionStatesStmt)
return v.Leave(n)
}

/*
// SetCharsetStmt is a statement to assign values to character and collation variables.
// See https://dev.mysql.com/doc/refman/5.7/en/set-statement.html
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ var tokenMap = map[string]int{
"SERIAL": serial,
"SERIALIZABLE": serializable,
"SESSION": session,
"SESSION_STATES": sessionStates,
"SET": set,
"SETVAL": setval,
"SHARD_ROW_ID_BITS": shardRowIDBits,
Expand Down
Loading

0 comments on commit 5d4745e

Please sign in to comment.