func (ui UpdateInfo) String() string {
	return fmt.Sprintf("Rows matched: %d  Changed: %d  Warnings: %d", ui.Matched, ui.Updated, ui.Warnings)
}
String implements fmt.Stringer
package plan
import (
	"fmt"
	"gopkg.in/src-d/go-errors.v1"
	"github.com/dolthub/go-mysql-server/sql"
	"github.com/dolthub/go-mysql-server/sql/expression"
)
var ErrUpdateNotSupported = errors.NewKind("table doesn't support UPDATE")
var ErrUpdateUnexpectedSetResult = errors.NewKind("attempted to set field but expression returned %T")
type Update struct {
	UnaryNode
	Checks sql.CheckConstraints
}
func NewUpdate(n sql.Node, updateExprs []sql.Expression) *Update {
	return &Update{
		UnaryNode: UnaryNode{NewUpdateSource(
			n,
			updateExprs,
		)}}
}
func getUpdatable(node sql.Node) (sql.UpdatableTable, error) {
	switch node := node.(type) {
	case sql.UpdatableTable:
		return node, nil
	case *IndexedTableAccess:
		return getUpdatable(node.ResolvedTable)
	case *ResolvedTable:
		return getUpdatableTable(node.Table)
	case *SubqueryAlias:
		return nil, ErrUpdateNotSupported.New()
	case *TriggerExecutor:
		return getUpdatable(node.Left())
	case sql.TableWrapper:
		return getUpdatableTable(node.Underlying())
	case *UpdateJoin:
		return node.GetUpdatable(), nil
	}
	if len(node.Children()) > 1 {
		return nil, ErrUpdateNotSupported.New()
	}
	for _, child := range node.Children() {
		updater, _ := getUpdatable(child)
		if updater != nil {
			return updater, nil
		}
	}
	return nil, ErrUpdateNotSupported.New()
}
func getUpdatableTable(t sql.Table) (sql.UpdatableTable, error) {
	switch t := t.(type) {
	case sql.UpdatableTable:
		return t, nil
	case sql.TableWrapper:
		return getUpdatableTable(t.Underlying())
	default:
		return nil, ErrUpdateNotSupported.New()
	}
}
func updateDatabaseHelper(node sql.Node) string {
	switch node := node.(type) {
	case sql.UpdatableTable:
		return ""
	case *IndexedTableAccess:
		return updateDatabaseHelper(node.ResolvedTable)
	case *ResolvedTable:
		return node.Database.Name()
	case *UnresolvedTable:
		return node.Database
	}
	for _, child := range node.Children() {
		return updateDatabaseHelper(child)
	}
	return ""
}
func (u *Update) Database() string {
	return updateDatabaseHelper(u.Child)
}
func (u *Update) Expressions() []sql.Expression {
	return u.Checks.ToExpressions()
}
func (u *Update) Resolved() bool {
	return u.Child.Resolved() && expression.ExpressionsResolved(u.Checks.ToExpressions()...)
}
func (u Update) WithExpressions(newExprs ...sql.Expression) (sql.Node, error) {
	if len(newExprs) != len(u.Checks) {
		return nil, sql.ErrInvalidChildrenNumber.New(u, len(newExprs), len(u.Checks))
	}
	var err error
	u.Checks, err = u.Checks.FromExpressions(newExprs)
	if err != nil {
		return nil, err
	}
	return &u, nil
}
type UpdateInfo struct {
	Matched, Updated, Warnings int
}