github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/table_count.go (about) 1 package plan 2 3 import ( 4 "fmt" 5 6 "github.com/dolthub/go-mysql-server/sql" 7 "github.com/dolthub/go-mysql-server/sql/types" 8 ) 9 10 // TableCountLookup short-circuits `select count(*) from table` 11 // using the sql.StatisticsTable interface. 12 type TableCountLookup struct { 13 aliasName string 14 db sql.Database 15 table sql.StatisticsTable 16 cnt uint64 17 id sql.ColumnId 18 } 19 20 func NewTableCount(aliasName string, db sql.Database, table sql.StatisticsTable, cnt uint64, id sql.ColumnId) sql.Node { 21 return &TableCountLookup{aliasName: aliasName, db: db, table: table, cnt: cnt, id: id} 22 } 23 24 var _ sql.Node = (*TableCountLookup)(nil) 25 26 func (t *TableCountLookup) Id() sql.ColumnId { 27 return t.id 28 } 29 30 func (t *TableCountLookup) WithId(id sql.ColumnId) *TableCountLookup { 31 ret := *t 32 ret.id = t.id 33 return &ret 34 } 35 36 func (t *TableCountLookup) Name() string { 37 return t.aliasName 38 } 39 40 func (t *TableCountLookup) Count() uint64 { 41 return t.cnt 42 } 43 44 func (t *TableCountLookup) Resolved() bool { 45 return true 46 } 47 48 func (t *TableCountLookup) Table() sql.Table { 49 return t.table 50 } 51 52 func (t *TableCountLookup) IsReadOnly() bool { 53 return true 54 } 55 56 func (t *TableCountLookup) Db() sql.Database { 57 return t.db 58 } 59 60 func (t *TableCountLookup) String() string { 61 return fmt.Sprintf("table_count(%s) as %s", t.table.Name(), t.aliasName) 62 } 63 64 func (t *TableCountLookup) Schema() sql.Schema { 65 return sql.Schema{{ 66 Name: t.aliasName, 67 Type: types.Int64, 68 Nullable: false, 69 Source: t.table.Name(), 70 }} 71 } 72 73 func (t *TableCountLookup) Children() []sql.Node { 74 return nil 75 } 76 77 func (t *TableCountLookup) WithChildren(_ ...sql.Node) (sql.Node, error) { 78 return t, nil 79 } 80 81 func (t *TableCountLookup) CheckPrivileges(_ *sql.Context, _ sql.PrivilegedOperationChecker) bool { 82 return true 83 }