github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/analyze.go (about)

     1  package plan
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/dolthub/go-mysql-server/sql"
     8  	"github.com/dolthub/go-mysql-server/sql/types"
     9  )
    10  
    11  type AnalyzeTable struct {
    12  	Db     string
    13  	Stats  sql.StatsProvider
    14  	Tables []sql.Table
    15  }
    16  
    17  var _ sql.Node = (*AnalyzeTable)(nil)
    18  var _ sql.CollationCoercible = (*AnalyzeTable)(nil)
    19  
    20  var analyzeSchema = sql.Schema{
    21  	{Name: "Table", Type: types.LongText},
    22  	{Name: "Op", Type: types.LongText},
    23  	{Name: "Msg_type", Type: types.LongText},
    24  	{Name: "Msg_text", Type: types.LongText},
    25  }
    26  
    27  func NewAnalyze(names []sql.Table) *AnalyzeTable {
    28  	return &AnalyzeTable{
    29  		Tables: names,
    30  	}
    31  }
    32  
    33  // Schema implements the interface sql.Node.
    34  // TODO: should be |Tables|Op|Msg_type|Msg_text|
    35  func (n *AnalyzeTable) Schema() sql.Schema {
    36  	return analyzeSchema
    37  }
    38  
    39  func (n *AnalyzeTable) WithCatalog(cat sql.Catalog) *AnalyzeTable {
    40  	ret := *n
    41  	return &ret
    42  }
    43  
    44  func (n *AnalyzeTable) WithTables(tables []sql.Table) *AnalyzeTable {
    45  	n.Tables = tables
    46  	return n
    47  }
    48  
    49  func (n *AnalyzeTable) WithDb(db string) *AnalyzeTable {
    50  	n.Db = db
    51  	return n
    52  }
    53  
    54  func (n *AnalyzeTable) WithStats(stats sql.StatsProvider) *AnalyzeTable {
    55  	n.Stats = stats
    56  	return n
    57  }
    58  
    59  func (n *AnalyzeTable) IsReadOnly() bool {
    60  	return true
    61  }
    62  
    63  // String implements the interface sql.Node.
    64  func (n *AnalyzeTable) String() string {
    65  	tblNames := make([]string, len(n.Tables))
    66  	for i, t := range n.Tables {
    67  		tblNames[i] = t.String()
    68  	}
    69  	return fmt.Sprintf("AnalyzeTable table %s", strings.Join(tblNames, ", "))
    70  }
    71  
    72  // Resolved implements the Resolvable interface.
    73  func (n *AnalyzeTable) Resolved() bool {
    74  	return n.Stats != nil
    75  }
    76  
    77  // Children implements the interface sql.Node.
    78  func (n *AnalyzeTable) Children() []sql.Node {
    79  	return nil
    80  }
    81  
    82  // WithChildren implements the interface sql.Node.
    83  func (n *AnalyzeTable) WithChildren(_ ...sql.Node) (sql.Node, error) {
    84  	return n, nil
    85  }
    86  
    87  // CheckPrivileges implements the interface sql.Node.
    88  func (n *AnalyzeTable) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
    89  	return true
    90  }
    91  
    92  // CollationCoercibility implements the interface sql.CollationCoercible.
    93  func (*AnalyzeTable) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
    94  	return sql.Collation_binary, 7
    95  }