func NewOrderedDistinct(child sql.Node) *OrderedDistinct {
	return &OrderedDistinct{
		UnaryNode: UnaryNode{Child: child},
	}
}
NewOrderedDistinct creates a new OrderedDistinct node.
package plan
import (
	"io"
	"github.com/src-d/go-mysql-server/sql"
)
type Distinct struct {
	UnaryNode
}
func NewDistinct(child sql.Node) *Distinct {
	return &Distinct{
		UnaryNode: UnaryNode{Child: child},
	}
}
func (d *Distinct) Resolved() bool {
	return d.UnaryNode.Child.Resolved()
}
func (d *Distinct) RowIter(ctx *sql.Context) (sql.RowIter, error) {
	span, ctx := ctx.Span("plan.Distinct")
	it, err := d.Child.RowIter(ctx)
	if err != nil {
		span.Finish()
		return nil, err
	}
	return sql.NewSpanIter(span, newDistinctIter(ctx, it)), nil
}
func (d *Distinct) WithChildren(children ...sql.Node) (sql.Node, error) {
	if len(children) != 1 {
		return nil, sql.ErrInvalidChildrenNumber.New(d, len(children), 1)
	}
	return NewDistinct(children[0]), nil
}
func (d Distinct) String() string {
	p := sql.NewTreePrinter()
	_ = p.WriteNode("Distinct")
	_ = p.WriteChildren(d.Child.String())
	return p.String()
}
type distinctIter struct {
	childIter sql.RowIter
	seen      sql.KeyValueCache
	dispose   sql.DisposeFunc
}
func newDistinctIter(ctx *sql.Context, child sql.RowIter) *distinctIter {
	cache, dispose := ctx.Memory.NewHistoryCache()
	return &distinctIter{
		childIter: child,
		seen:      cache,
		dispose:   dispose,
	}
}
func (di *distinctIter) Next() (sql.Row, error) {
	for {
		row, err := di.childIter.Next()
		if err != nil {
			if err == io.EOF {
				di.Dispose()
			}
			return nil, err
		}
		hash := sql.CacheKey(row)
		if _, err := di.seen.Get(hash); err == nil {
			continue
		}
		if err := di.seen.Put(hash, struct{}{}); err != nil {
			return nil, err
		}
		return row, nil
	}
}
func (di *distinctIter) Close() error {
	di.Dispose()
	return di.childIter.Close()
}
func (di *distinctIter) Dispose() {
	if di.dispose != nil {
		di.dispose()
	}
}
type OrderedDistinct struct {
	UnaryNode
}