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

parser, execution: support kill connection_id() #37650

Merged
merged 5 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion executor/simple.go
Expand Up @@ -1554,6 +1554,16 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error
}

func (e *SimpleExec) executeKillStmt(ctx context.Context, s *ast.KillStmt) error {
if x, ok := s.Expr.(*ast.FuncCallExpr); ok {
if x.FnName.L == ast.ConnectionID {
sm := e.ctx.GetSessionManager()
sm.Kill(e.ctx.GetSessionVars().ConnectionID, s.Query)
return nil
}
err := errors.New("Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] [connectionID | CONNECTION_ID()]' instead")
e.ctx.GetSessionVars().StmtCtx.AppendWarning(err)
tangenta marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
if !config.GetGlobalConfig().EnableGlobalKill {
conf := config.GetGlobalConfig()
if s.TiDBExtension || conf.CompatibleKillQuery {
Expand All @@ -1563,7 +1573,7 @@ func (e *SimpleExec) executeKillStmt(ctx context.Context, s *ast.KillStmt) error
}
sm.Kill(s.ConnectionID, s.Query)
} else {
err := errors.New("Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] connectionID' instead")
err := errors.New("Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] [connectionID | CONNECTION_ID()]' instead")
e.ctx.GetSessionVars().StmtCtx.AppendWarning(err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion executor/simple_test.go
Expand Up @@ -52,7 +52,7 @@ func TestKillStmt(t *testing.T) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("kill %d", connID))
result := tk.MustQuery("show warnings")
result.Check(testkit.Rows("Warning 1105 Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] connectionID' instead"))
result.Check(testkit.Rows("Warning 1105 Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] [connectionID | CONNECTION_ID()]' instead"))

newCfg2 := *originCfg
newCfg2.EnableGlobalKill = true
Expand Down
11 changes: 10 additions & 1 deletion parser/ast/misc.go
Expand Up @@ -937,6 +937,8 @@ type KillStmt struct {
// So, "KILL TIDB" grammar is introduced, and it REQUIRES DIRECT client -> TiDB TOPOLOGY.
// TODO: The standard KILL grammar will be supported once we have global connectionID.
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
TiDBExtension bool

Expr ExprNode
}

// Restore implements Node interface.
Expand All @@ -948,7 +950,14 @@ func (n *KillStmt) Restore(ctx *format.RestoreCtx) error {
if n.Query {
ctx.WriteKeyWord(" QUERY")
}
ctx.WritePlainf(" %d", n.ConnectionID)
if n.Expr != nil {
ctx.WriteKeyWord(" ")
if err := n.Expr.Restore(ctx); err != nil {
return errors.Trace(err)
}
} else {
ctx.WritePlainf(" %d", n.ConnectionID)
}
return nil
}

Expand Down