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