github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/show_indexes.go (about) 1 // Copyright 2020-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 // ShowIndexes is a node that shows the indexes on a table. 25 type ShowIndexes struct { 26 UnaryNode 27 IndexesToShow []sql.Index 28 } 29 30 // NewShowIndexes creates a new ShowIndexes node. The node must represent a table. 31 func NewShowIndexes(table sql.Node) *ShowIndexes { 32 return &ShowIndexes{ 33 UnaryNode: UnaryNode{table}, 34 } 35 } 36 37 var _ sql.Node = (*ShowIndexes)(nil) 38 var _ sql.CollationCoercible = (*ShowIndexes)(nil) 39 40 // WithChildren implements the Node interface. 41 func (n *ShowIndexes) WithChildren(children ...sql.Node) (sql.Node, error) { 42 if len(children) != 1 { 43 return nil, sql.ErrInvalidChildrenNumber.New(n, len(children), 1) 44 } 45 46 return &ShowIndexes{ 47 UnaryNode: UnaryNode{children[0]}, 48 IndexesToShow: n.IndexesToShow, 49 }, nil 50 } 51 52 // CheckPrivileges implements the interface sql.Node. 53 func (n *ShowIndexes) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 54 //TODO: figure out what privileges are required 55 return true 56 } 57 58 // CollationCoercibility implements the interface sql.CollationCoercible. 59 func (*ShowIndexes) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 60 return sql.Collation_binary, 7 61 } 62 63 // String implements the fmt.Stringer interface. 64 func (n *ShowIndexes) String() string { 65 return fmt.Sprintf("ShowIndexes(%s)", n.Child) 66 } 67 68 func (n *ShowIndexes) IsReadOnly() bool { 69 return true 70 } 71 72 // Schema implements the Node interface. 73 func (n *ShowIndexes) Schema() sql.Schema { 74 return sql.Schema{ 75 &sql.Column{Name: "Table", Type: types.LongText}, 76 &sql.Column{Name: "Non_unique", Type: types.Int32}, 77 &sql.Column{Name: "Key_name", Type: types.LongText}, 78 &sql.Column{Name: "Seq_in_index", Type: types.Int32}, 79 &sql.Column{Name: "Column_name", Type: types.LongText, Nullable: true}, 80 &sql.Column{Name: "Collation", Type: types.LongText, Nullable: true}, 81 &sql.Column{Name: "Cardinality", Type: types.Int64}, 82 &sql.Column{Name: "Sub_part", Type: types.Int64, Nullable: true}, 83 &sql.Column{Name: "Packed", Type: types.LongText, Nullable: true}, 84 &sql.Column{Name: "Null", Type: types.LongText}, 85 &sql.Column{Name: "Index_type", Type: types.LongText}, 86 &sql.Column{Name: "Comment", Type: types.LongText}, 87 &sql.Column{Name: "Index_comment", Type: types.LongText}, 88 &sql.Column{Name: "Visible", Type: types.LongText}, 89 &sql.Column{Name: "Expression", Type: types.LongText, Nullable: true}, 90 } 91 }