github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/showtablestatus.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  	"github.com/dolthub/go-mysql-server/sql"
    19  	"github.com/dolthub/go-mysql-server/sql/types"
    20  )
    21  
    22  // ShowTableStatus returns the status of the tables in a database.
    23  type ShowTableStatus struct {
    24  	db      sql.Database
    25  	Catalog sql.Catalog
    26  }
    27  
    28  var _ sql.Node = (*ShowTableStatus)(nil)
    29  var _ sql.Databaser = (*ShowTableStatus)(nil)
    30  var _ sql.CollationCoercible = (*ShowTableStatus)(nil)
    31  
    32  // NewShowTableStatus creates a new ShowTableStatus node.
    33  func NewShowTableStatus(db sql.Database) *ShowTableStatus {
    34  	return &ShowTableStatus{db: db}
    35  }
    36  
    37  func (s *ShowTableStatus) Database() sql.Database {
    38  	return s.db
    39  }
    40  
    41  func (s *ShowTableStatus) WithDatabase(db sql.Database) (sql.Node, error) {
    42  	ns := *s
    43  	ns.db = db
    44  	return &ns, nil
    45  }
    46  
    47  var showTableStatusSchema = sql.Schema{
    48  	{Name: "Name", Type: types.LongText},
    49  	{Name: "Engine", Type: types.LongText},
    50  	{Name: "Version", Type: types.LongText},
    51  	{Name: "Row_format", Type: types.LongText},
    52  	{Name: "Rows", Type: types.Uint64},
    53  	{Name: "Avg_row_length", Type: types.Uint64},
    54  	{Name: "Data_length", Type: types.Uint64},
    55  	{Name: "Max_data_length", Type: types.Uint64},
    56  	{Name: "Index_length", Type: types.Int64},
    57  	{Name: "Data_free", Type: types.Int64},
    58  	{Name: "Auto_increment", Type: types.Int64},
    59  	{Name: "Create_time", Type: types.Datetime, Nullable: true},
    60  	{Name: "Update_time", Type: types.Datetime, Nullable: true},
    61  	{Name: "Check_time", Type: types.Datetime, Nullable: true},
    62  	{Name: "Collation", Type: types.LongText},
    63  	{Name: "Checksum", Type: types.LongText, Nullable: true},
    64  	{Name: "Create_options", Type: types.LongText, Nullable: true},
    65  	{Name: "Comments", Type: types.LongText, Nullable: true},
    66  }
    67  
    68  // Children implements the sql.Node interface.
    69  func (s *ShowTableStatus) Children() []sql.Node { return nil }
    70  
    71  // Resolved implements the sql.Node interface.
    72  func (s *ShowTableStatus) Resolved() bool { return true }
    73  
    74  // Schema implements the sql.Node interface.
    75  func (s *ShowTableStatus) Schema() sql.Schema { return showTableStatusSchema }
    76  
    77  func (s *ShowTableStatus) String() string {
    78  	return "SHOW TABLE STATUS"
    79  }
    80  
    81  func (s *ShowTableStatus) IsReadOnly() bool {
    82  	return true
    83  }
    84  
    85  // WithChildren implements the Node interface.
    86  func (s *ShowTableStatus) WithChildren(children ...sql.Node) (sql.Node, error) {
    87  	if len(children) != 0 {
    88  		return nil, sql.ErrInvalidChildrenNumber.New(s, len(children), 0)
    89  	}
    90  
    91  	return s, nil
    92  }
    93  
    94  // CheckPrivileges implements the interface sql.Node.
    95  func (s *ShowTableStatus) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
    96  	// Some tables won't be visible in RowIter if the user doesn't have the correct privileges
    97  	return true
    98  }
    99  
   100  // CollationCoercibility implements the interface sql.CollationCoercible.
   101  func (*ShowTableStatus) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
   102  	return sql.Collation_binary, 7
   103  }