Skip to content

Commit

Permalink
parser: support 'set binding status for stmt' (#32661)
Browse files Browse the repository at this point in the history
ref #32466
  • Loading branch information
Reminiscent authored Mar 2, 2022
1 parent c7d87bd commit 3ac831f
Show file tree
Hide file tree
Showing 4 changed files with 6,680 additions and 6,507 deletions.
62 changes: 62 additions & 0 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
_ StmtNode = &KillStmt{}
_ StmtNode = &CreateBindingStmt{}
_ StmtNode = &DropBindingStmt{}
_ StmtNode = &SetBindingStmt{}
_ StmtNode = &ShutdownStmt{}
_ StmtNode = &RestartStmt{}
_ StmtNode = &RenameUserStmt{}
Expand Down Expand Up @@ -1681,6 +1682,67 @@ func (n *DropBindingStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// BindingStatusType defines the status type for the binding
type BindingStatusType int8

// Binding status types.
const (
BindingStatusTypeEnable BindingStatusType = iota
BindingStatusTypeDisable
)

// SetBindingStmt sets sql binding status.
type SetBindingStmt struct {
stmtNode

BindingStatusType BindingStatusType
OriginNode StmtNode
HintedNode StmtNode
}

func (n *SetBindingStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("SET ")
ctx.WriteKeyWord("BINDING ")
switch n.BindingStatusType {
case BindingStatusTypeEnable:
ctx.WriteKeyWord("ENABLE ")
case BindingStatusTypeDisable:
ctx.WriteKeyWord("DISABLE ")
}
ctx.WriteKeyWord("FOR ")
if err := n.OriginNode.Restore(ctx); err != nil {
return errors.Trace(err)
}
if n.HintedNode != nil {
ctx.WriteKeyWord(" USING ")
if err := n.HintedNode.Restore(ctx); err != nil {
return errors.Trace(err)
}
}
return nil
}

func (n *SetBindingStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*SetBindingStmt)
origNode, ok := n.OriginNode.Accept(v)
if !ok {
return n, false
}
n.OriginNode = origNode.(StmtNode)
if n.HintedNode != nil {
hintedNode, ok := n.HintedNode.Accept(v)
if !ok {
return n, false
}
n.HintedNode = hintedNode.(StmtNode)
}
return v.Leave(n)
}

// Extended statistics types.
const (
StatsTypeCardinality uint8 = iota
Expand Down
Loading

0 comments on commit 3ac831f

Please sign in to comment.