github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/kill.go (about) 1 // Copyright 2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plan 16 17 import ( 18 "fmt" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 "github.com/dolthub/go-mysql-server/sql/types" 22 ) 23 24 type KillType int 25 26 const ( 27 KillType_Query KillType = 0 28 KillType_Connection KillType = 1 29 ) 30 31 func (kt KillType) String() string { 32 if kt == KillType_Query { 33 return "QUERY" 34 } else if kt == KillType_Connection { 35 return "CONNECTION" 36 } 37 panic(fmt.Sprintf("Invalid KillType value %d", kt)) 38 } 39 40 type Kill struct { 41 Kt KillType 42 ConnID uint32 43 } 44 45 var _ sql.Node = (*Kill)(nil) 46 var _ sql.CollationCoercible = (*Kill)(nil) 47 48 func NewKill(kt KillType, connID uint32) *Kill { 49 return &Kill{kt, connID} 50 } 51 52 func (k *Kill) Resolved() bool { 53 return true 54 } 55 56 func (k *Kill) Children() []sql.Node { 57 return nil 58 } 59 60 func (k *Kill) IsReadOnly() bool { 61 return true 62 } 63 64 func (k *Kill) WithChildren(children ...sql.Node) (sql.Node, error) { 65 if len(children) != 0 { 66 return nil, sql.ErrInvalidChildrenNumber.New(k, len(children), 0) 67 } 68 return k, nil 69 } 70 71 // CheckPrivileges implements the interface sql.Node. 72 func (k *Kill) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 73 //TODO: If the user doesn't have the SUPER privilege, they should still be able to kill their own threads 74 return opChecker.UserHasPrivileges(ctx, 75 sql.NewPrivilegedOperation(sql.PrivilegeCheckSubject{}, sql.PrivilegeType_Super)) 76 } 77 78 // CollationCoercibility implements the interface sql.CollationCoercible. 79 func (*Kill) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 80 return sql.Collation_binary, 7 81 } 82 83 func (k *Kill) Schema() sql.Schema { 84 return types.OkResultSchema 85 } 86 87 func (k *Kill) String() string { 88 return fmt.Sprintf("KILL %s %d", k.Kt.String(), k.ConnID) 89 }