memo

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2023 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SortedDistinctOp distinctOp
	HashDistinctOp
)

Variables

View Source
var HaltErr = errors.New("halt dfs")

Functions

func DfsRel

func DfsRel(grp *ExprGroup, cb func(rel RelExpr) error) error

DfsRel runs a callback |cb| on all execution plans in the memo expression group. An expression group is defined by 1) a set of child expression groups that serve as logical inputs to this operator, and 2) a set of logically equivalent plans for executing this expression group's operator. We recursively walk to expression group leaves, and then traverse every execution plan in leaf groups before working upwards back to the root group. Returning a HaltErr short circuits the walk.

func DfsScalar

func DfsScalar(e ScalarExpr, cb func(e ScalarExpr) error) error

DfsScalar walks scalar expression memo groups. Returning a HaltErr short circuits the walk.

func FormatExpr

func FormatExpr(r exprType) string

func NewJoinOrderBuilder

func NewJoinOrderBuilder(memo *Memo) *joinOrderBuilder

func ScalarToSqlCol

func ScalarToSqlCol(e *ExprGroup) *sql.Column

Types

type And

type And struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*And) Children

func (r *And) Children() []*ExprGroup

func (*And) ExprId

func (r *And) ExprId() ScalarExprId

func (And) Group

func (r And) Group() *ExprGroup

func (And) SetGroup

func (r And) SetGroup(g *ExprGroup)

func (*And) String

func (r *And) String() string

type AntiJoin

type AntiJoin struct {
	*JoinBase
}

func (AntiJoin) Cost

func (r AntiJoin) Cost() float64

func (AntiJoin) Distinct

func (r AntiJoin) Distinct() distinctOp

func (AntiJoin) Group

func (r AntiJoin) Group() *ExprGroup

func (*AntiJoin) JoinPrivate

func (r *AntiJoin) JoinPrivate() *JoinBase

func (AntiJoin) Next

func (r AntiJoin) Next() RelExpr

func (AntiJoin) SetCost

func (r AntiJoin) SetCost(c float64)

func (AntiJoin) SetDistinct

func (r AntiJoin) SetDistinct(d distinctOp)

func (AntiJoin) SetGroup

func (r AntiJoin) SetGroup(g *ExprGroup)

func (AntiJoin) SetNext

func (r AntiJoin) SetNext(rel RelExpr)

func (*AntiJoin) String

func (r *AntiJoin) String() string

type ArithType

type ArithType uint8
const (
	ArithTypeUnknown    ArithType = iota // unknown
	ArithTypeBitAnd                      // &
	ArithTypeBitOr                       // |
	ArithTypeBitXor                      // ^
	ArithTypePlus                        // +
	ArithTypeMinus                       // -
	ArithTypeMult                        // *
	ArithTypeDiv                         // /
	ArithTypeIntDiv                      // div
	ArithTypeMod                         // %
	ArithTypeShiftLeft                   // <<
	ArithTypeShiftRight                  // >>
)

func (ArithType) String

func (i ArithType) String() string

type Arithmetic

type Arithmetic struct {
	Left  *ExprGroup
	Right *ExprGroup
	Op    ArithType
	// contains filtered or unexported fields
}

func (*Arithmetic) Children

func (r *Arithmetic) Children() []*ExprGroup

func (*Arithmetic) ExprId

func (r *Arithmetic) ExprId() ScalarExprId

func (Arithmetic) Group

func (r Arithmetic) Group() *ExprGroup

func (Arithmetic) SetGroup

func (r Arithmetic) SetGroup(g *ExprGroup)

func (*Arithmetic) String

func (r *Arithmetic) String() string

type Bindvar

type Bindvar struct {
	Name string
	Typ  sql.Type
	// contains filtered or unexported fields
}

func (*Bindvar) Children

func (r *Bindvar) Children() []*ExprGroup

func (*Bindvar) ExprId

func (r *Bindvar) ExprId() ScalarExprId

func (Bindvar) Group

func (r Bindvar) Group() *ExprGroup

func (Bindvar) SetGroup

func (r Bindvar) SetGroup(g *ExprGroup)

func (*Bindvar) String

func (r *Bindvar) String() string

type Carder

type Carder interface {
	// EstimateCard returns the estimate row count outputs for a relational
	// expression. Cardinality is an expression group property.
	EstimateCard(*sql.Context, RelExpr, sql.StatsReader) (float64, error)
}

Carder types can estimate the cardinality (row count) of relational expressions.

func NewDefaultCarder

func NewDefaultCarder() Carder

type ColRef

type ColRef struct {
	Col   sql.ColumnId
	Table GroupId
	Gf    *expression.GetField
	// contains filtered or unexported fields
}

func (*ColRef) Children

func (r *ColRef) Children() []*ExprGroup

func (*ColRef) ExprId

func (r *ColRef) ExprId() ScalarExprId

func (ColRef) Group

func (r ColRef) Group() *ExprGroup

func (ColRef) SetGroup

func (r ColRef) SetGroup(g *ExprGroup)

func (*ColRef) String

func (r *ColRef) String() string

type ConcatJoin

type ConcatJoin struct {
	*JoinBase
	Concat []*Lookup
}

func (ConcatJoin) Cost

func (r ConcatJoin) Cost() float64

func (ConcatJoin) Distinct

func (r ConcatJoin) Distinct() distinctOp

func (ConcatJoin) Group

func (r ConcatJoin) Group() *ExprGroup

func (*ConcatJoin) JoinPrivate

func (r *ConcatJoin) JoinPrivate() *JoinBase

func (ConcatJoin) Next

func (r ConcatJoin) Next() RelExpr

func (ConcatJoin) SetCost

func (r ConcatJoin) SetCost(c float64)

func (ConcatJoin) SetDistinct

func (r ConcatJoin) SetDistinct(d distinctOp)

func (ConcatJoin) SetGroup

func (r ConcatJoin) SetGroup(g *ExprGroup)

func (ConcatJoin) SetNext

func (r ConcatJoin) SetNext(rel RelExpr)

func (*ConcatJoin) String

func (r *ConcatJoin) String() string

type Coster

type Coster interface {
	// EstimateCost cost returns the incremental CPU and memory cost for an
	// operator, or an error. Cost is dependent on physical operator type,
	// and the cardinality of inputs.
	EstimateCost(*sql.Context, RelExpr, sql.StatsReader) (float64, error)
}

Coster types can estimate the CPU and memory cost of physical execution operators.

func NewDefaultCoster

func NewDefaultCoster() Coster

func NewHashBiasedCoster

func NewHashBiasedCoster() Coster

func NewInnerBiasedCoster

func NewInnerBiasedCoster() Coster

func NewLookupBiasedCoster

func NewLookupBiasedCoster() Coster

func NewMergeBiasedCoster

func NewMergeBiasedCoster() Coster

func NewPartialBiasedCoster

func NewPartialBiasedCoster() Coster

type CrossJoin

type CrossJoin struct {
	*JoinBase
}

func (CrossJoin) Cost

func (r CrossJoin) Cost() float64

func (CrossJoin) Distinct

func (r CrossJoin) Distinct() distinctOp

func (CrossJoin) Group

func (r CrossJoin) Group() *ExprGroup

func (*CrossJoin) JoinPrivate

func (r *CrossJoin) JoinPrivate() *JoinBase

func (CrossJoin) Next

func (r CrossJoin) Next() RelExpr

func (CrossJoin) SetCost

func (r CrossJoin) SetCost(c float64)

func (CrossJoin) SetDistinct

func (r CrossJoin) SetDistinct(d distinctOp)

func (CrossJoin) SetGroup

func (r CrossJoin) SetGroup(g *ExprGroup)

func (CrossJoin) SetNext

func (r CrossJoin) SetNext(rel RelExpr)

func (*CrossJoin) String

func (r *CrossJoin) String() string

type Distinct

type Distinct struct {
	Child *ExprGroup
	// contains filtered or unexported fields
}

func (*Distinct) Children

func (r *Distinct) Children() []*ExprGroup

func (Distinct) Cost

func (r Distinct) Cost() float64

func (Distinct) Distinct

func (r Distinct) Distinct() distinctOp

func (Distinct) Group

func (r Distinct) Group() *ExprGroup

func (Distinct) Next

func (r Distinct) Next() RelExpr

func (Distinct) SetCost

func (r Distinct) SetCost(c float64)

func (Distinct) SetDistinct

func (r Distinct) SetDistinct(d distinctOp)

func (Distinct) SetGroup

func (r Distinct) SetGroup(g *ExprGroup)

func (Distinct) SetNext

func (r Distinct) SetNext(rel RelExpr)

func (*Distinct) String

func (r *Distinct) String() string

type EmptyTable

type EmptyTable struct {
	Table *plan.EmptyTable
	// contains filtered or unexported fields
}

func (*EmptyTable) Children

func (r *EmptyTable) Children() []*ExprGroup

func (EmptyTable) Indexes

func (s EmptyTable) Indexes() []*Index

func (*EmptyTable) Name

func (r *EmptyTable) Name() string

func (*EmptyTable) OutputCols

func (r *EmptyTable) OutputCols() sql.Schema

func (EmptyTable) SetIndexes

func (s EmptyTable) SetIndexes(indexes []*Index)

func (*EmptyTable) String

func (r *EmptyTable) String() string

func (*EmptyTable) TableId

func (r *EmptyTable) TableId() TableId

type Equal

type Equal struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Equal) Children

func (r *Equal) Children() []*ExprGroup

func (*Equal) ExprId

func (r *Equal) ExprId() ScalarExprId

func (Equal) Group

func (r Equal) Group() *ExprGroup

func (Equal) SetGroup

func (r Equal) SetGroup(g *ExprGroup)

func (*Equal) String

func (r *Equal) String() string

type ExecBuilder

type ExecBuilder struct{}

func NewExecBuilder

func NewExecBuilder() *ExecBuilder

type ExprGroup

type ExprGroup struct {
	RelProps *relProps

	Scalar ScalarExpr
	First  RelExpr
	Best   RelExpr

	Id GroupId

	Cost   float64
	Done   bool
	HintOk bool
	// contains filtered or unexported fields
}

ExprGroup is a linked list of plans that return the same result set defined by row count and schema.

func (*ExprGroup) Prepend

func (e *ExprGroup) Prepend(rel RelExpr)

Prepend adds a new plan to an expression group at the beginning of the list, to avoid recursive exploration steps (like adding indexed joins).

func (*ExprGroup) ScalarProps

func (e *ExprGroup) ScalarProps() *scalarProps

func (*ExprGroup) String

func (e *ExprGroup) String() string

type Filter

type Filter struct {
	Child   *ExprGroup
	Filters []*ExprGroup
	// contains filtered or unexported fields
}

func (*Filter) Children

func (r *Filter) Children() []*ExprGroup

func (Filter) Cost

func (r Filter) Cost() float64

func (Filter) Distinct

func (r Filter) Distinct() distinctOp

func (Filter) Group

func (r Filter) Group() *ExprGroup

func (Filter) Next

func (r Filter) Next() RelExpr

func (Filter) SetCost

func (r Filter) SetCost(c float64)

func (Filter) SetDistinct

func (r Filter) SetDistinct(d distinctOp)

func (Filter) SetGroup

func (r Filter) SetGroup(g *ExprGroup)

func (Filter) SetNext

func (r Filter) SetNext(rel RelExpr)

func (*Filter) String

func (r *Filter) String() string

type FullOuterJoin

type FullOuterJoin struct {
	*JoinBase
}

func (FullOuterJoin) Cost

func (r FullOuterJoin) Cost() float64

func (FullOuterJoin) Distinct

func (r FullOuterJoin) Distinct() distinctOp

func (FullOuterJoin) Group

func (r FullOuterJoin) Group() *ExprGroup

func (*FullOuterJoin) JoinPrivate

func (r *FullOuterJoin) JoinPrivate() *JoinBase

func (FullOuterJoin) Next

func (r FullOuterJoin) Next() RelExpr

func (FullOuterJoin) SetCost

func (r FullOuterJoin) SetCost(c float64)

func (FullOuterJoin) SetDistinct

func (r FullOuterJoin) SetDistinct(d distinctOp)

func (FullOuterJoin) SetGroup

func (r FullOuterJoin) SetGroup(g *ExprGroup)

func (FullOuterJoin) SetNext

func (r FullOuterJoin) SetNext(rel RelExpr)

func (*FullOuterJoin) String

func (r *FullOuterJoin) String() string

type Geq

type Geq struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Geq) Children

func (r *Geq) Children() []*ExprGroup

func (*Geq) ExprId

func (r *Geq) ExprId() ScalarExprId

func (Geq) Group

func (r Geq) Group() *ExprGroup

func (Geq) SetGroup

func (r Geq) SetGroup(g *ExprGroup)

func (*Geq) String

func (r *Geq) String() string

type GroupId

type GroupId uint16

type Gt

type Gt struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Gt) Children

func (r *Gt) Children() []*ExprGroup

func (*Gt) ExprId

func (r *Gt) ExprId() ScalarExprId

func (Gt) Group

func (r Gt) Group() *ExprGroup

func (Gt) SetGroup

func (r Gt) SetGroup(g *ExprGroup)

func (*Gt) String

func (r *Gt) String() string

type HashJoin

type HashJoin struct {
	*JoinBase
	RightAttrs []*ExprGroup
	LeftAttrs  []*ExprGroup
}

func (HashJoin) Cost

func (r HashJoin) Cost() float64

func (HashJoin) Distinct

func (r HashJoin) Distinct() distinctOp

func (HashJoin) Group

func (r HashJoin) Group() *ExprGroup

func (*HashJoin) JoinPrivate

func (r *HashJoin) JoinPrivate() *JoinBase

func (HashJoin) Next

func (r HashJoin) Next() RelExpr

func (HashJoin) SetCost

func (r HashJoin) SetCost(c float64)

func (HashJoin) SetDistinct

func (r HashJoin) SetDistinct(d distinctOp)

func (HashJoin) SetGroup

func (r HashJoin) SetGroup(g *ExprGroup)

func (HashJoin) SetNext

func (r HashJoin) SetNext(rel RelExpr)

func (*HashJoin) String

func (r *HashJoin) String() string

type Hidden

type Hidden struct {
	E      sql.Expression
	Cols   sql.ColSet
	Tables sql.FastIntSet
	// contains filtered or unexported fields
}

func (*Hidden) Children

func (r *Hidden) Children() []*ExprGroup

func (*Hidden) ExprId

func (r *Hidden) ExprId() ScalarExprId

func (Hidden) Group

func (r Hidden) Group() *ExprGroup

func (Hidden) SetGroup

func (r Hidden) SetGroup(g *ExprGroup)

func (*Hidden) String

func (r *Hidden) String() string

type Hint

type Hint struct {
	Typ  HintType
	Args []string
}

func ExtractJoinHint

func ExtractJoinHint(n *plan.JoinNode) []Hint

func (Hint) String

func (h Hint) String() string

type HintType

type HintType uint8
const (
	HintTypeUnknown                  HintType = iota //
	HintTypeJoinOrder                                // JOIN_ORDER
	HintTypeJoinFixedOrder                           // JOIN_FIXED_ORDER
	HintTypeMergeJoin                                // MERGE_JOIN
	HintTypeLookupJoin                               // LOOKUP_JOIN
	HintTypeHashJoin                                 // HASH_JOIN
	HintTypeSemiJoin                                 // SEMI_JOIN
	HintTypeAntiJoin                                 // ANTI_JOIN
	HintTypeInnerJoin                                // INNER_JOIN
	HintTypeLeftOuterLookupJoin                      // LEFT_OUTER_LOOKUP_JOIN
	HintTypeNoIndexConditionPushDown                 // NO_ICP
)

TODO implement NO_ICP and JOIN_FIXED_ORDER

func (HintType) String

func (i HintType) String() string

type InTuple

type InTuple struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*InTuple) Children

func (r *InTuple) Children() []*ExprGroup

func (*InTuple) ExprId

func (r *InTuple) ExprId() ScalarExprId

func (InTuple) Group

func (r InTuple) Group() *ExprGroup

func (InTuple) SetGroup

func (r InTuple) SetGroup(g *ExprGroup)

func (*InTuple) String

func (r *InTuple) String() string

type Index

type Index struct {
	// contains filtered or unexported fields
}

func (*Index) ColSet

func (i *Index) ColSet() sql.ColSet

func (*Index) Cols

func (i *Index) Cols() []sql.ColumnId

func (*Index) SqlIdx

func (i *Index) SqlIdx() sql.Index

type IndexScan

type IndexScan struct {
	Idx    *Index
	Range  sql.Range
	Parent *JoinBase
}

type InnerJoin

type InnerJoin struct {
	*JoinBase
}

func (InnerJoin) Cost

func (r InnerJoin) Cost() float64

func (InnerJoin) Distinct

func (r InnerJoin) Distinct() distinctOp

func (InnerJoin) Group

func (r InnerJoin) Group() *ExprGroup

func (*InnerJoin) JoinPrivate

func (r *InnerJoin) JoinPrivate() *JoinBase

func (InnerJoin) Next

func (r InnerJoin) Next() RelExpr

func (InnerJoin) SetCost

func (r InnerJoin) SetCost(c float64)

func (InnerJoin) SetDistinct

func (r InnerJoin) SetDistinct(d distinctOp)

func (InnerJoin) SetGroup

func (r InnerJoin) SetGroup(g *ExprGroup)

func (InnerJoin) SetNext

func (r InnerJoin) SetNext(rel RelExpr)

func (*InnerJoin) String

func (r *InnerJoin) String() string

type IsNull

type IsNull struct {
	Child *ExprGroup
	// contains filtered or unexported fields
}

func (*IsNull) Children

func (r *IsNull) Children() []*ExprGroup

func (*IsNull) ExprId

func (r *IsNull) ExprId() ScalarExprId

func (IsNull) Group

func (r IsNull) Group() *ExprGroup

func (IsNull) SetGroup

func (r IsNull) SetGroup(g *ExprGroup)

func (*IsNull) String

func (r *IsNull) String() string

type JoinBase

type JoinBase struct {
	Op     plan.JoinType
	Filter []ScalarExpr
	Left   *ExprGroup
	Right  *ExprGroup
	// contains filtered or unexported fields
}

func (*JoinBase) Children

func (r *JoinBase) Children() []*ExprGroup

func (*JoinBase) Copy

func (r *JoinBase) Copy() *JoinBase

Copy creates a JoinBase with the same underlying join expression. note: it is important to Copy the base node to avoid cyclical relExpr references in the ExprGroup linked list.

func (JoinBase) Cost

func (r JoinBase) Cost() float64

func (JoinBase) Distinct

func (r JoinBase) Distinct() distinctOp

func (JoinBase) Group

func (r JoinBase) Group() *ExprGroup

func (*JoinBase) JoinPrivate

func (r *JoinBase) JoinPrivate() *JoinBase

func (JoinBase) Next

func (r JoinBase) Next() RelExpr

func (JoinBase) SetCost

func (r JoinBase) SetCost(c float64)

func (JoinBase) SetDistinct

func (r JoinBase) SetDistinct(d distinctOp)

func (JoinBase) SetGroup

func (r JoinBase) SetGroup(g *ExprGroup)

func (JoinBase) SetNext

func (r JoinBase) SetNext(rel RelExpr)

type JoinRel

type JoinRel interface {
	RelExpr
	JoinPrivate() *JoinBase
	Group() *ExprGroup
}

JoinRel represents a plan.JoinNode or plan.CrossJoin. See plan.JoinType for the full list.

type LeftJoin

type LeftJoin struct {
	*JoinBase
}

func (LeftJoin) Cost

func (r LeftJoin) Cost() float64

func (LeftJoin) Distinct

func (r LeftJoin) Distinct() distinctOp

func (LeftJoin) Group

func (r LeftJoin) Group() *ExprGroup

func (*LeftJoin) JoinPrivate

func (r *LeftJoin) JoinPrivate() *JoinBase

func (LeftJoin) Next

func (r LeftJoin) Next() RelExpr

func (LeftJoin) SetCost

func (r LeftJoin) SetCost(c float64)

func (LeftJoin) SetDistinct

func (r LeftJoin) SetDistinct(d distinctOp)

func (LeftJoin) SetGroup

func (r LeftJoin) SetGroup(g *ExprGroup)

func (LeftJoin) SetNext

func (r LeftJoin) SetNext(rel RelExpr)

func (*LeftJoin) String

func (r *LeftJoin) String() string

type Leq

type Leq struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Leq) Children

func (r *Leq) Children() []*ExprGroup

func (*Leq) ExprId

func (r *Leq) ExprId() ScalarExprId

func (Leq) Group

func (r Leq) Group() *ExprGroup

func (Leq) SetGroup

func (r Leq) SetGroup(g *ExprGroup)

func (*Leq) String

func (r *Leq) String() string

type Literal

type Literal struct {
	Val interface{}
	Typ sql.Type
	// contains filtered or unexported fields
}

func (*Literal) Children

func (r *Literal) Children() []*ExprGroup

func (*Literal) ExprId

func (r *Literal) ExprId() ScalarExprId

func (Literal) Group

func (r Literal) Group() *ExprGroup

func (Literal) SetGroup

func (r Literal) SetGroup(g *ExprGroup)

func (*Literal) String

func (r *Literal) String() string

type Lookup

type Lookup struct {
	Index    *Index
	KeyExprs []ScalarExpr
	Nullmask []bool

	Parent *JoinBase
}

type LookupJoin

type LookupJoin struct {
	*JoinBase
	Lookup *Lookup
}

func (LookupJoin) Cost

func (r LookupJoin) Cost() float64

func (LookupJoin) Distinct

func (r LookupJoin) Distinct() distinctOp

func (LookupJoin) Group

func (r LookupJoin) Group() *ExprGroup

func (*LookupJoin) JoinPrivate

func (r *LookupJoin) JoinPrivate() *JoinBase

func (LookupJoin) Next

func (r LookupJoin) Next() RelExpr

func (LookupJoin) SetCost

func (r LookupJoin) SetCost(c float64)

func (LookupJoin) SetDistinct

func (r LookupJoin) SetDistinct(d distinctOp)

func (LookupJoin) SetGroup

func (r LookupJoin) SetGroup(g *ExprGroup)

func (LookupJoin) SetNext

func (r LookupJoin) SetNext(rel RelExpr)

func (*LookupJoin) String

func (r *LookupJoin) String() string

type Lt

type Lt struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Lt) Children

func (r *Lt) Children() []*ExprGroup

func (*Lt) ExprId

func (r *Lt) ExprId() ScalarExprId

func (Lt) Group

func (r Lt) Group() *ExprGroup

func (Lt) SetGroup

func (r Lt) SetGroup(g *ExprGroup)

func (*Lt) String

func (r *Lt) String() string

type Max1Row

type Max1Row struct {
	Table sql.NameableNode
	// contains filtered or unexported fields
}

func (*Max1Row) Children

func (r *Max1Row) Children() []*ExprGroup

func (Max1Row) Indexes

func (s Max1Row) Indexes() []*Index

func (*Max1Row) Name

func (r *Max1Row) Name() string

func (*Max1Row) OutputCols

func (r *Max1Row) OutputCols() sql.Schema

func (Max1Row) SetIndexes

func (s Max1Row) SetIndexes(indexes []*Index)

func (*Max1Row) String

func (r *Max1Row) String() string

func (*Max1Row) TableId

func (r *Max1Row) TableId() TableId

type Memo

type Memo struct {
	Columns map[string]sql.ColumnId

	Ctx *sql.Context

	TableProps *tableProps
	// contains filtered or unexported fields
}

Memo collects a forest of query plans structured by logical and physical equivalency. Logically equivalent plans, represented by an exprGroup, produce the same rows (possibly unordered) and schema. Physical plans are stored in a linked list within an expression group.

func NewMemo

func NewMemo(ctx *sql.Context, stats sql.StatsReadWriter, s *plan.Scope, scopeLen int, cost Coster, card Carder) *Memo

func (*Memo) ApplyHint

func (m *Memo) ApplyHint(hint Hint)

func (*Memo) BestRootPlan

func (m *Memo) BestRootPlan() (sql.Node, error)

func (*Memo) MemoizeColRef

func (m *Memo) MemoizeColRef(e *expression.GetField) *ExprGroup

func (*Memo) MemoizeFilter

func (m *Memo) MemoizeFilter(grp, child *ExprGroup, filters []*ExprGroup) *ExprGroup

func (*Memo) MemoizeInnerJoin

func (m *Memo) MemoizeInnerJoin(grp, left, right *ExprGroup, op plan.JoinType, filter []ScalarExpr) *ExprGroup

func (*Memo) MemoizeIsNull

func (m *Memo) MemoizeIsNull(child sql.Expression) *ExprGroup

func (*Memo) MemoizeLeftJoin

func (m *Memo) MemoizeLeftJoin(grp, left, right *ExprGroup, op plan.JoinType, filter []ScalarExpr) *ExprGroup

func (*Memo) MemoizeLookupJoin

func (m *Memo) MemoizeLookupJoin(grp, left, right *ExprGroup, op plan.JoinType, filter []ScalarExpr, lookup *Lookup) *ExprGroup

func (*Memo) MemoizeMergeJoin

func (m *Memo) MemoizeMergeJoin(grp, left, right *ExprGroup, lIdx, rIdx *IndexScan, op plan.JoinType, filter []ScalarExpr, swapCmp bool) *ExprGroup

func (*Memo) MemoizeProject

func (m *Memo) MemoizeProject(grp, child *ExprGroup, projections []*ExprGroup) *ExprGroup

func (*Memo) MemoizeScalar

func (m *Memo) MemoizeScalar(e sql.Expression) *ExprGroup

func (*Memo) NewExprGroup

func (m *Memo) NewExprGroup(rel exprType) *ExprGroup

newExprGroup creates a new logical expression group to encapsulate the action of a SQL clause. TODO: this is supposed to deduplicate logically equivalent table scans and scalar expressions, replacing references with a pointer. Currently a hacky format to quickly support memoizing join trees.

func (*Memo) OptimizeRoot

func (m *Memo) OptimizeRoot() error

OptimizeRoot finds the implementation for the root expression that has the lowest cost.

func (*Memo) PreexistingScalar

func (m *Memo) PreexistingScalar(e ScalarExpr) *ExprGroup

func (*Memo) Root

func (m *Memo) Root() *ExprGroup

func (*Memo) String

func (m *Memo) String() string

func (*Memo) WithJoinOp

func (m *Memo) WithJoinOp(op HintType, left, right string)

func (*Memo) WithJoinOrder

func (m *Memo) WithJoinOrder(tables []string)

type MergeJoin

type MergeJoin struct {
	*JoinBase
	InnerScan *IndexScan
	OuterScan *IndexScan
	SwapCmp   bool
}

func (MergeJoin) Cost

func (r MergeJoin) Cost() float64

func (MergeJoin) Distinct

func (r MergeJoin) Distinct() distinctOp

func (MergeJoin) Group

func (r MergeJoin) Group() *ExprGroup

func (*MergeJoin) JoinPrivate

func (r *MergeJoin) JoinPrivate() *JoinBase

func (MergeJoin) Next

func (r MergeJoin) Next() RelExpr

func (MergeJoin) SetCost

func (r MergeJoin) SetCost(c float64)

func (MergeJoin) SetDistinct

func (r MergeJoin) SetDistinct(d distinctOp)

func (MergeJoin) SetGroup

func (r MergeJoin) SetGroup(g *ExprGroup)

func (MergeJoin) SetNext

func (r MergeJoin) SetNext(rel RelExpr)

func (*MergeJoin) String

func (r *MergeJoin) String() string

type Not

type Not struct {
	Child *ExprGroup
	// contains filtered or unexported fields
}

func (*Not) Children

func (r *Not) Children() []*ExprGroup

func (*Not) ExprId

func (r *Not) ExprId() ScalarExprId

func (Not) Group

func (r Not) Group() *ExprGroup

func (Not) SetGroup

func (r Not) SetGroup(g *ExprGroup)

func (*Not) String

func (r *Not) String() string

type NullSafeEq

type NullSafeEq struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*NullSafeEq) Children

func (r *NullSafeEq) Children() []*ExprGroup

func (*NullSafeEq) ExprId

func (r *NullSafeEq) ExprId() ScalarExprId

func (NullSafeEq) Group

func (r NullSafeEq) Group() *ExprGroup

func (NullSafeEq) SetGroup

func (r NullSafeEq) SetGroup(g *ExprGroup)

func (*NullSafeEq) String

func (r *NullSafeEq) String() string

type Or

type Or struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Or) Children

func (r *Or) Children() []*ExprGroup

func (*Or) ExprId

func (r *Or) ExprId() ScalarExprId

func (Or) Group

func (r Or) Group() *ExprGroup

func (Or) SetGroup

func (r Or) SetGroup(g *ExprGroup)

func (*Or) String

func (r *Or) String() string

type Project

type Project struct {
	Child       *ExprGroup
	Projections []*ExprGroup
	// contains filtered or unexported fields
}

func (*Project) Children

func (r *Project) Children() []*ExprGroup

func (Project) Cost

func (r Project) Cost() float64

func (Project) Distinct

func (r Project) Distinct() distinctOp

func (Project) Group

func (r Project) Group() *ExprGroup

func (Project) Next

func (r Project) Next() RelExpr

func (Project) SetCost

func (r Project) SetCost(c float64)

func (Project) SetDistinct

func (r Project) SetDistinct(d distinctOp)

func (Project) SetGroup

func (r Project) SetGroup(g *ExprGroup)

func (Project) SetNext

func (r Project) SetNext(rel RelExpr)

func (*Project) String

func (r *Project) String() string

type RecursiveCte

type RecursiveCte struct {
	Table *plan.RecursiveCte
	// contains filtered or unexported fields
}

func (*RecursiveCte) Children

func (r *RecursiveCte) Children() []*ExprGroup

func (RecursiveCte) Indexes

func (s RecursiveCte) Indexes() []*Index

func (*RecursiveCte) Name

func (r *RecursiveCte) Name() string

func (*RecursiveCte) OutputCols

func (r *RecursiveCte) OutputCols() sql.Schema

func (RecursiveCte) SetIndexes

func (s RecursiveCte) SetIndexes(indexes []*Index)

func (*RecursiveCte) String

func (r *RecursiveCte) String() string

func (*RecursiveCte) TableId

func (r *RecursiveCte) TableId() TableId

type RecursiveTable

type RecursiveTable struct {
	Table *plan.RecursiveTable
	// contains filtered or unexported fields
}

func (*RecursiveTable) Children

func (r *RecursiveTable) Children() []*ExprGroup

func (RecursiveTable) Indexes

func (s RecursiveTable) Indexes() []*Index

func (*RecursiveTable) Name

func (r *RecursiveTable) Name() string

func (*RecursiveTable) OutputCols

func (r *RecursiveTable) OutputCols() sql.Schema

func (RecursiveTable) SetIndexes

func (s RecursiveTable) SetIndexes(indexes []*Index)

func (*RecursiveTable) String

func (r *RecursiveTable) String() string

func (*RecursiveTable) TableId

func (r *RecursiveTable) TableId() TableId

type Regexp

type Regexp struct {
	Left  *ExprGroup
	Right *ExprGroup
	// contains filtered or unexported fields
}

func (*Regexp) Children

func (r *Regexp) Children() []*ExprGroup

func (*Regexp) ExprId

func (r *Regexp) ExprId() ScalarExprId

func (Regexp) Group

func (r Regexp) Group() *ExprGroup

func (Regexp) SetGroup

func (r Regexp) SetGroup(g *ExprGroup)

func (*Regexp) String

func (r *Regexp) String() string

type RelExpr

type RelExpr interface {
	fmt.Stringer

	Next() RelExpr
	SetNext(RelExpr)
	SetCost(c float64)
	Cost() float64
	Distinct() distinctOp
	SetDistinct(distinctOp)
	// contains filtered or unexported methods
}

RelExpr wraps a sql.Node for use as a ExprGroup linked list node. TODO: we need relExprs for every sql.Node and sql.Expression

type ScalarExpr

type ScalarExpr interface {
	fmt.Stringer

	ExprId() ScalarExprId
	// contains filtered or unexported methods
}

ScalarExpr is a sql.Expression equivalent. Both ScalarExpr and RelExpr are embedded in Memo as *ExprGroup. ScalarExpr will only have one implementation. todo: do we need scalar expressions in the memo? or could they be ref'd out

func SplitConjunction

func SplitConjunction(e ScalarExpr) []ScalarExpr

splitConjunction_memo breaks AND expressions into their left and right parts, recursively

func SplitDisjunction

func SplitDisjunction(e *Or) []ScalarExpr

splitDisjunction breaks OR expressions into their left and right parts, recursively

type ScalarExprId

type ScalarExprId uint8
const (
	ScalarExprUnknown ScalarExprId = iota
	ScalarExprEqual
	ScalarExprNot
	ScalarExprColRef
	ScalarExprLiteral
	ScalarExprOr
	ScalarExprAnd
	ScalarExprInTuple
	ScalarExprLt
	ScalarExprLeq
	ScalarExprGt
	ScalarExprGeq
	ScalarExprNullSafeEq
	ScalarExprRegexp
	ScalarExprArithmetic
	ScalarExprBindvar
	ScalarExprIsNull
	ScalarExprTuple
	ScalarExprHidden
)

type SemiJoin

type SemiJoin struct {
	*JoinBase
}

func (SemiJoin) Cost

func (r SemiJoin) Cost() float64

func (SemiJoin) Distinct

func (r SemiJoin) Distinct() distinctOp

func (SemiJoin) Group

func (r SemiJoin) Group() *ExprGroup

func (*SemiJoin) JoinPrivate

func (r *SemiJoin) JoinPrivate() *JoinBase

func (SemiJoin) Next

func (r SemiJoin) Next() RelExpr

func (SemiJoin) SetCost

func (r SemiJoin) SetCost(c float64)

func (SemiJoin) SetDistinct

func (r SemiJoin) SetDistinct(d distinctOp)

func (SemiJoin) SetGroup

func (r SemiJoin) SetGroup(g *ExprGroup)

func (SemiJoin) SetNext

func (r SemiJoin) SetNext(rel RelExpr)

func (*SemiJoin) String

func (r *SemiJoin) String() string

type SourceRel

type SourceRel interface {
	RelExpr
	// outputCols retuns the output schema of this data source.
	// TODO: this is more useful as a relExpr property, but we need
	// this to fix up expression indexes currently
	OutputCols() sql.Schema
	Name() string
	TableId() TableId
	Indexes() []*Index
	SetIndexes(indexes []*Index)
}

SourceRel represents a data source, like a tableScan, subqueryAlias, or list of values.

type SubqueryAlias

type SubqueryAlias struct {
	Table *plan.SubqueryAlias
	// contains filtered or unexported fields
}

func (*SubqueryAlias) Children

func (r *SubqueryAlias) Children() []*ExprGroup

func (SubqueryAlias) Indexes

func (s SubqueryAlias) Indexes() []*Index

func (*SubqueryAlias) Name

func (r *SubqueryAlias) Name() string

func (*SubqueryAlias) OutputCols

func (r *SubqueryAlias) OutputCols() sql.Schema

func (SubqueryAlias) SetIndexes

func (s SubqueryAlias) SetIndexes(indexes []*Index)

func (*SubqueryAlias) String

func (r *SubqueryAlias) String() string

func (*SubqueryAlias) TableId

func (r *SubqueryAlias) TableId() TableId

type TableAlias

type TableAlias struct {
	Table *plan.TableAlias
	// contains filtered or unexported fields
}

func (*TableAlias) Children

func (r *TableAlias) Children() []*ExprGroup

func (TableAlias) Indexes

func (s TableAlias) Indexes() []*Index

func (*TableAlias) Name

func (r *TableAlias) Name() string

func (*TableAlias) OutputCols

func (r *TableAlias) OutputCols() sql.Schema

func (TableAlias) SetIndexes

func (s TableAlias) SetIndexes(indexes []*Index)

func (*TableAlias) String

func (r *TableAlias) String() string

func (*TableAlias) TableId

func (r *TableAlias) TableId() TableId

type TableFunc

type TableFunc struct {
	Table sql.TableFunction
	// contains filtered or unexported fields
}

func (*TableFunc) Children

func (r *TableFunc) Children() []*ExprGroup

func (TableFunc) Indexes

func (s TableFunc) Indexes() []*Index

func (*TableFunc) Name

func (r *TableFunc) Name() string

func (*TableFunc) OutputCols

func (r *TableFunc) OutputCols() sql.Schema

func (TableFunc) SetIndexes

func (s TableFunc) SetIndexes(indexes []*Index)

func (*TableFunc) String

func (r *TableFunc) String() string

func (*TableFunc) TableId

func (r *TableFunc) TableId() TableId

type TableId

type TableId uint16

func TableIdForSource

func TableIdForSource(id GroupId) TableId

type TableScan

type TableScan struct {
	Table *plan.ResolvedTable
	// contains filtered or unexported fields
}

func (*TableScan) Children

func (r *TableScan) Children() []*ExprGroup

func (TableScan) Indexes

func (s TableScan) Indexes() []*Index

func (*TableScan) Name

func (r *TableScan) Name() string

func (*TableScan) OutputCols

func (r *TableScan) OutputCols() sql.Schema

func (TableScan) SetIndexes

func (s TableScan) SetIndexes(indexes []*Index)

func (*TableScan) String

func (r *TableScan) String() string

func (*TableScan) TableId

func (r *TableScan) TableId() TableId

type Tuple

type Tuple struct {
	Values []*ExprGroup
	// contains filtered or unexported fields
}

func (*Tuple) Children

func (r *Tuple) Children() []*ExprGroup

func (*Tuple) ExprId

func (r *Tuple) ExprId() ScalarExprId

func (Tuple) Group

func (r Tuple) Group() *ExprGroup

func (Tuple) SetGroup

func (r Tuple) SetGroup(g *ExprGroup)

func (*Tuple) String

func (r *Tuple) String() string

type Values

type Values struct {
	Table *plan.ValueDerivedTable
	// contains filtered or unexported fields
}

func (*Values) Children

func (r *Values) Children() []*ExprGroup

func (Values) Indexes

func (s Values) Indexes() []*Index

func (*Values) Name

func (r *Values) Name() string

func (*Values) OutputCols

func (r *Values) OutputCols() sql.Schema

func (Values) SetIndexes

func (s Values) SetIndexes(indexes []*Index)

func (*Values) String

func (r *Values) String() string

func (*Values) TableId

func (r *Values) TableId() TableId

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL