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

     1  package plan
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/dolthub/go-mysql-server/sql"
     9  )
    10  
    11  func NewUpdateHistogram(db, table, index string, cols []string, stats sql.Statistic) *UpdateHistogram {
    12  	return &UpdateHistogram{db: db, cols: cols, index: index, table: table, stats: stats}
    13  }
    14  
    15  type UpdateHistogram struct {
    16  	db    string
    17  	table string
    18  	index string
    19  	cols  []string
    20  	stats sql.Statistic
    21  	prov  sql.StatsProvider
    22  }
    23  
    24  var _ sql.Node = (*UpdateHistogram)(nil)
    25  
    26  func (u *UpdateHistogram) Db() string {
    27  	return u.db
    28  }
    29  
    30  func (u *UpdateHistogram) Table() string {
    31  	return u.table
    32  }
    33  
    34  func (u *UpdateHistogram) Index() string {
    35  	return u.index
    36  }
    37  
    38  func (u *UpdateHistogram) Cols() []string {
    39  	return u.cols
    40  }
    41  
    42  func (u *UpdateHistogram) Stats() sql.Statistic {
    43  	return u.stats
    44  }
    45  
    46  func (u *UpdateHistogram) WithProvider(prov sql.StatsProvider) *UpdateHistogram {
    47  	ret := *u
    48  	ret.prov = prov
    49  	return &ret
    50  }
    51  
    52  func (u *UpdateHistogram) StatsProvider() sql.StatsProvider {
    53  	return u.prov
    54  }
    55  
    56  func (u *UpdateHistogram) Resolved() bool {
    57  	return true
    58  }
    59  
    60  func (u *UpdateHistogram) String() string {
    61  	statMap := u.stats.ToInterface()
    62  	statBytes, _ := json.Marshal(statMap)
    63  	return fmt.Sprintf("update histogram  %s.(%s) using %s", u.table, strings.Join(u.cols, ","), statBytes)
    64  }
    65  
    66  func (u *UpdateHistogram) Schema() sql.Schema {
    67  	return analyzeSchema
    68  }
    69  
    70  func (u *UpdateHistogram) Children() []sql.Node {
    71  	return nil
    72  }
    73  
    74  func (u *UpdateHistogram) WithChildren(children ...sql.Node) (sql.Node, error) {
    75  	return u, nil
    76  }
    77  
    78  func (u *UpdateHistogram) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
    79  	return true
    80  }
    81  
    82  func (u *UpdateHistogram) IsReadOnly() bool {
    83  	return false
    84  }
    85  
    86  func NewDropHistogram(db, table string, cols []string) *DropHistogram {
    87  	return &DropHistogram{db: db, cols: cols, table: table}
    88  }
    89  
    90  type DropHistogram struct {
    91  	db    string
    92  	table string
    93  	cols  []string
    94  	prov  sql.StatsProvider
    95  }
    96  
    97  var _ sql.Node = (*DropHistogram)(nil)
    98  
    99  func (d *DropHistogram) StatsProvider() sql.StatsProvider {
   100  	return d.prov
   101  }
   102  
   103  func (d *DropHistogram) WithProvider(prov sql.StatsProvider) *DropHistogram {
   104  	ret := *d
   105  	ret.prov = prov
   106  	return &ret
   107  }
   108  
   109  func (d *DropHistogram) Db() string {
   110  	return d.db
   111  }
   112  
   113  func (d *DropHistogram) Table() string {
   114  	return d.table
   115  }
   116  
   117  func (d *DropHistogram) Cols() []string {
   118  	return d.cols
   119  }
   120  
   121  func (d *DropHistogram) Resolved() bool {
   122  	return true
   123  }
   124  
   125  func (d *DropHistogram) String() string {
   126  	return fmt.Sprintf("drop histogram %s.(%s)", d.table, strings.Join(d.cols, ","))
   127  }
   128  
   129  func (d *DropHistogram) Schema() sql.Schema {
   130  	return analyzeSchema
   131  }
   132  
   133  func (d *DropHistogram) Children() []sql.Node {
   134  	return nil
   135  }
   136  
   137  func (d *DropHistogram) WithChildren(_ ...sql.Node) (sql.Node, error) {
   138  	return d, nil
   139  }
   140  
   141  func (d *DropHistogram) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
   142  	return true
   143  }
   144  
   145  func (d *DropHistogram) IsReadOnly() bool {
   146  	return false
   147  }