Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions enginetest/engine_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ func TestUnlockTables(t *testing.T) {
catalog.LockTable(ctx, "foo")
catalog.LockTable(ctx, "bar")

node := plan.NewUnlockTables()
node.Catalog = catalog

_, err := node.RowIter(ctx, nil)
err := catalog.UnlockTables(ctx, ctx.ID())
require.NoError(err)

require.Equal(1, t1.unlocks)
Expand Down
44 changes: 0 additions & 44 deletions sql/plan/drop_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/dolthub/go-mysql-server/sql/types"
)

Expand Down Expand Up @@ -100,46 +99,3 @@ func (n *DropRole) WithChildren(children ...sql.Node) (sql.Node, error) {
func (*DropRole) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 7
}

// RowIter implements the interface sql.Node.
func (n *DropRole) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
mysqlDb, ok := n.MySQLDb.(*mysql_db.MySQLDb)
if !ok {
return nil, sql.ErrDatabaseNotFound.New("mysql")
}

editor := mysqlDb.Editor()
defer editor.Close()

for _, role := range n.Roles {
userPk := mysql_db.UserPrimaryKey{
Host: role.Host,
User: role.Name,
}
if role.AnyHost {
userPk.Host = "%"
}
existingUser, ok := editor.GetUser(userPk)
if !ok {
if n.IfExists {
continue
}
return nil, sql.ErrRoleDeletionFailure.New(role.String("'"))
}

//TODO: if a role is mentioned in the "mandatory_roles" system variable then they cannot be dropped
editor.RemoveUser(userPk)
editor.RemoveRoleEdgesFromKey(mysql_db.RoleEdgesFromKey{
FromHost: existingUser.Host,
FromUser: existingUser.User,
})
editor.RemoveRoleEdgesToKey(mysql_db.RoleEdgesToKey{
ToHost: existingUser.Host,
ToUser: existingUser.User,
})
}
if err := mysqlDb.Persist(ctx, editor); err != nil {
return nil, err
}
return sql.RowsToRowIter(sql.Row{types.NewOkResult(0)}), nil
}
38 changes: 0 additions & 38 deletions sql/plan/drop_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"strings"

"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/dolthub/go-mysql-server/sql/types"

"github.com/dolthub/go-mysql-server/sql"
Expand Down Expand Up @@ -101,40 +100,3 @@ func (n *DropUser) WithChildren(children ...sql.Node) (sql.Node, error) {
func (*DropUser) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 7
}

// RowIter implements the interface sql.Node.
func (n *DropUser) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
mysqlDb, ok := n.MySQLDb.(*mysql_db.MySQLDb)
if !ok {
return nil, sql.ErrDatabaseNotFound.New("mysql")
}
editor := mysqlDb.Editor()
defer editor.Close()
for _, user := range n.Users {
existingUser := mysqlDb.GetUser(editor, user.Name, user.Host, false)
if existingUser == nil {
if n.IfExists {
continue
}
return nil, sql.ErrUserDeletionFailure.New(user.String("'"))
}

//TODO: if a user is mentioned in the "mandatory_roles" (users and roles are interchangeable) system variable then they cannot be dropped
editor.RemoveUser(mysql_db.UserPrimaryKey{
Host: existingUser.Host,
User: existingUser.User,
})
editor.RemoveRoleEdgesFromKey(mysql_db.RoleEdgesFromKey{
FromHost: existingUser.Host,
FromUser: existingUser.User,
})
editor.RemoveRoleEdgesToKey(mysql_db.RoleEdgesToKey{
ToHost: existingUser.Host,
ToUser: existingUser.User,
})
}
if err := mysqlDb.Persist(ctx, editor); err != nil {
return nil, err
}
return sql.RowsToRowIter(sql.Row{types.NewOkResult(0)}), nil
}
5 changes: 0 additions & 5 deletions sql/plan/drop_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ func (dv *SingleDropView) IsReadOnly() bool {
return false
}

// RowIter implements the Node interface. It always returns an empty iterator.
func (dv *SingleDropView) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
return sql.RowsToRowIter(), nil
}

// Schema implements the Node interface. It always returns nil.
func (dv *SingleDropView) Schema() sql.Schema { return nil }

Expand Down
16 changes: 0 additions & 16 deletions sql/plan/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package plan

import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/dolthub/go-mysql-server/sql/types"
)

Expand All @@ -38,21 +37,6 @@ func NewFlushPrivileges(ft bool) *FlushPrivileges {
}
}

// RowIter implements the interface sql.Node.
func (f *FlushPrivileges) RowIter(ctx *sql.Context, _ sql.Row) (sql.RowIter, error) {
gts, ok := f.MysqlDb.(*mysql_db.MySQLDb)
if !ok {
return nil, sql.ErrDatabaseNotFound.New("mysql")
}
editor := gts.Editor()
defer editor.Close()
err := gts.Persist(ctx, editor)
if err != nil {
return nil, err
}
return sql.RowsToRowIter(sql.Row{types.NewOkResult(0)}), nil
}

// String implements the interface sql.Node.
func (*FlushPrivileges) String() string { return "FLUSH PRIVILEGES" }

Expand Down
6 changes: 4 additions & 2 deletions sql/plan/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,12 @@ func (j *JoinNode) Describe(options sql.DescribeOptions) string {
}
}
children = append(children, sql.Describe(j.left, options), sql.Describe(j.right, options))
comment := j.Comment()

if options.Estimates {
pr.WriteNode("%s %s", j.Op, j.GetDescribeStatsString(options))
pr.WriteNode("%s %s%s", j.Op, j.GetDescribeStatsString(options), comment)
} else {
pr.WriteNode("%s", j.Op)
pr.WriteNode("%s%s", j.Op, comment)
}
pr.WriteChildren(children...)
return pr.String()
Expand Down
12 changes: 0 additions & 12 deletions sql/plan/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ func (t *UnlockTables) IsReadOnly() bool { return true }
// Schema implements the sql.Node interface.
func (t *UnlockTables) Schema() sql.Schema { return nil }

// RowIter implements the sql.Node interface.
func (t *UnlockTables) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
span, ctx := ctx.Span("plan.UnlockTables")
defer span.End()

if err := t.Catalog.UnlockTables(ctx, ctx.ID()); err != nil {
return nil, err
}

return sql.RowsToRowIter(), nil
}

func (t *UnlockTables) String() string {
p := sql.NewTreePrinter()
_ = p.WriteNode("UnlockTables")
Expand Down
5 changes: 0 additions & 5 deletions sql/plan/namedwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ func (n *NamedWindows) DebugString() string {
return pr.String()
}

// RowIter implements sql.Node
func (n *NamedWindows) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
panic("cannot iterate *plan.NamedWindows")
}

// WithChildren implements sql.Node
func (n *NamedWindows) WithChildren(nodes ...sql.Node) (sql.Node, error) {
if len(nodes) != 1 {
Expand Down
3 changes: 0 additions & 3 deletions sql/plan/nothing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func (Nothing) Resolved() bool { return true }
func (Nothing) IsReadOnly() bool { return true }
func (Nothing) Schema() sql.Schema { return nil }
func (Nothing) Children() []sql.Node { return nil }
func (Nothing) RowIter(*sql.Context, sql.Row) (sql.RowIter, error) {
return sql.RowsToRowIter(), nil
}

// WithChildren implements the Node interface.
func (n Nothing) WithChildren(children ...sql.Node) (sql.Node, error) {
Expand Down
15 changes: 0 additions & 15 deletions sql/plan/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ func (pi PrepareInfo) String() string {
return "Statement prepared"
}

// RowIter implements the Node interface.
func (p *PrepareQuery) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
return sql.RowsToRowIter(sql.NewRow(types.OkResult{RowsAffected: 0, Info: PrepareInfo{}})), nil
}

func (p *PrepareQuery) Resolved() bool {
return true
}
Expand Down Expand Up @@ -110,11 +105,6 @@ func (p *ExecuteQuery) Schema() sql.Schema {
panic("ExecuteQuery methods shouldn't be used")
}

// RowIter implements the Node interface.
func (p *ExecuteQuery) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
panic("ExecuteQuery methods shouldn't be used")
}

func (p *ExecuteQuery) Resolved() bool {
panic("ExecuteQuery methods shouldn't be used")
}
Expand Down Expand Up @@ -160,11 +150,6 @@ func (p *DeallocateQuery) Schema() sql.Schema {
return types.OkResultSchema
}

// RowIter implements the Node interface.
func (p *DeallocateQuery) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
return sql.RowsToRowIter(sql.NewRow(types.OkResult{})), nil
}

func (p *DeallocateQuery) Resolved() bool {
return true
}
Expand Down
5 changes: 0 additions & 5 deletions sql/plan/rename_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,3 @@ func (n *RenameUser) WithChildren(children ...sql.Node) (sql.Node, error) {
func (*RenameUser) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 7
}

// RowIter implements the interface sql.Node.
func (n *RenameUser) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
return nil, fmt.Errorf("not yet implemented")
}
11 changes: 3 additions & 8 deletions sql/plan/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (n *Revoke) CheckAuth(ctx *sql.Context, opChecker sql.PrivilegedOperationCh
return opChecker.UserHasPrivileges(ctx, sql.NewPrivilegedOperation(subject,
convertToSqlPrivilegeType(true, n.Privileges...)...))
} else {
//TODO: add column checks
// TODO: add column checks
subject = sql.PrivilegeCheckSubject{
Database: n.PrivilegeLevel.Database,
Table: n.PrivilegeLevel.TableRoutine,
Expand Down Expand Up @@ -510,7 +510,7 @@ func (n *RevokeRole) CheckAuth(ctx *sql.Context, opChecker sql.PrivilegedOperati
sql.NewPrivilegedOperation(sql.PrivilegeCheckSubject{}, sql.PrivilegeType_Super)) {
return true
}
//TODO: only active roles may be revoked if the SUPER privilege is not held
// TODO: only active roles may be revoked if the SUPER privilege is not held
mysqlDb := n.MySQLDb.(*mysql_db.MySQLDb)
client := ctx.Session.Client()

Expand Down Expand Up @@ -606,16 +606,11 @@ func (n *RevokeProxy) WithChildren(children ...sql.Node) (sql.Node, error) {

// CheckAuth implements the interface sql.AuthorizationCheckerNode.
func (n *RevokeProxy) CheckAuth(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
//TODO: add this when proxy support is added
// TODO: add this when proxy support is added
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*RevokeProxy) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 7
}

// RowIter implements the interface sql.Node.
func (n *RevokeProxy) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
return nil, fmt.Errorf("not yet implemented")
}
46 changes: 0 additions & 46 deletions sql/plan/show_charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,49 +78,3 @@ func (sc *ShowCharset) Children() []sql.Node {
}
return []sql.Node{sc.CharacterSetTable}
}

func (sc *ShowCharset) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
//TODO: use the information_schema table instead, currently bypassing it to show currently-implemented charsets
//ri, err := sc.CharacterSetTable.RowIter(ctx, row)
//if err != nil {
// return nil, err
//}
//return &showCharsetIter{originalIter: ri}, nil

var rows []sql.Row
iter := sql.NewCharacterSetsIterator()
for charset, ok := iter.Next(); ok; charset, ok = iter.Next() {
if charset.Encoder != nil && charset.BinaryCollation.Sorter() != nil && charset.DefaultCollation.Sorter() != nil {
rows = append(rows, sql.Row{
charset.Name,
charset.Description,
charset.DefaultCollation.String(),
uint64(charset.MaxLength),
})
}
}
return sql.RowsToRowIter(rows...), nil
}

type showCharsetIter struct {
originalIter sql.RowIter
}

func (sci *showCharsetIter) Next(ctx *sql.Context) (sql.Row, error) {
row, err := sci.originalIter.Next(ctx)
if err != nil {
return nil, err
}

// switch the ordering (see notes on Schema())
defaultCollationName := row[1]

row[1] = row[2]
row[2] = defaultCollationName

return row, nil
}

func (sci *showCharsetIter) Close(ctx *sql.Context) error {
return sci.originalIter.Close(ctx)
}
Loading
Loading