Documentation ¶
Index ¶
- func CompareRefInt(a *int, b *int) bool
- func SortAggregations(a []Aggr)
- func SortGrouping(a []GroupBy)
- type Aggr
- type AggrRewriter
- type Concatenate
- func (c *Concatenate) CheckValid() error
- func (c *Concatenate) Compact(*semantics.SemTable) (LogicalOperator, error)
- func (c *Concatenate) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (c *Concatenate) TableID() semantics.TableSet
- func (c *Concatenate) UnsolvedPredicates(*semantics.SemTable) []sqlparser.Expr
- type Derived
- func (d *Derived) CheckValid() error
- func (d *Derived) Compact(*semantics.SemTable) (LogicalOperator, error)
- func (d *Derived) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (d *Derived) TableID() semantics.TableSet
- func (d *Derived) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type Filter
- func (f *Filter) CheckValid() error
- func (f *Filter) Compact(semTable *semantics.SemTable) (LogicalOperator, error)
- func (f *Filter) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (f *Filter) TableID() semantics.TableSet
- func (f *Filter) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type GroupBy
- type IntroducesTable
- type Join
- func (j *Join) CheckValid() error
- func (j *Join) Compact(semTable *semantics.SemTable) (LogicalOperator, error)
- func (j *Join) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (j *Join) TableID() semantics.TableSet
- func (j *Join) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type LogicalOperator
- type Operator
- type OrderBy
- type PhysicalOperator
- type QueryGraph
- func (qg *QueryGraph) CheckValid() error
- func (qg *QueryGraph) Compact(*semantics.SemTable) (LogicalOperator, error)
- func (qg *QueryGraph) GetPredicates(lhs, rhs semantics.TableSet) []sqlparser.Expr
- func (qg *QueryGraph) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (qg *QueryGraph) TableID() semantics.TableSet
- func (qg *QueryGraph) UnsolvedPredicates(_ *semantics.SemTable) []sqlparser.Expr
- type QueryProjection
- func (qp *QueryProjection) AddGroupBy(by GroupBy)
- func (qp *QueryProjection) AggrRewriter() *AggrRewriter
- func (qp *QueryProjection) AggregationExpressions() (out []Aggr, err error)
- func (qp *QueryProjection) AlignGroupByAndOrderBy()
- func (qp *QueryProjection) FindSelectExprIndexForExpr(expr sqlparser.Expr) (*int, *sqlparser.AliasedExpr)
- func (qp *QueryProjection) GetColumnCount() int
- func (qp *QueryProjection) GetGrouping() []GroupBy
- func (qp *QueryProjection) GetSimplifiedExpr(e sqlparser.Expr) (expr sqlparser.Expr, weightStrExpr sqlparser.Expr, err error)
- func (qp *QueryProjection) NeedsAggregation() bool
- func (qp *QueryProjection) NeedsDistinct() bool
- func (qp *QueryProjection) NeedsProjecting(ctx *plancontext.PlanningContext, ...) (needsVtGateEval bool, expressions []sqlparser.Expr, colNames []string, ...)
- type QueryTable
- type SelectExpr
- type SubQuery
- func (s *SubQuery) CheckValid() error
- func (s *SubQuery) Compact(*semantics.SemTable) (LogicalOperator, error)
- func (s *SubQuery) PushPredicate(sqlparser.Expr, *semantics.SemTable) (LogicalOperator, error)
- func (s *SubQuery) TableID() semantics.TableSet
- func (s *SubQuery) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type SubQueryInner
- type Update
- func (u *Update) CheckValid() error
- func (u *Update) Compact(semTable *semantics.SemTable) (LogicalOperator, error)
- func (u *Update) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (u *Update) TableID() semantics.TableSet
- func (u *Update) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type Vindex
- func (v *Vindex) CheckValid() error
- func (v *Vindex) Compact(*semantics.SemTable) (LogicalOperator, error)
- func (v *Vindex) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
- func (v *Vindex) TableID() semantics.TableSet
- func (v *Vindex) UnsolvedPredicates(*semantics.SemTable) []sqlparser.Expr
- type VindexTable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareRefInt ¶ added in v0.14.0
CompareRefInt compares two references of integers. In case either one is nil, it is considered to be smaller
func SortAggregations ¶ added in v0.14.0
func SortAggregations(a []Aggr)
func SortGrouping ¶ added in v0.14.0
func SortGrouping(a []GroupBy)
Types ¶
type Aggr ¶ added in v0.14.0
type Aggr struct { Original *sqlparser.AliasedExpr OpCode engine.AggregateOpcode Alias string // The index at which the user expects to see this aggregated function. Set to nil, if the user does not ask for it Index *int Distinct bool }
Aggr encodes all information needed for aggregation functions
type AggrRewriter ¶ added in v0.14.0
type AggrRewriter struct { Err error // contains filtered or unexported fields }
type Concatenate ¶ added in v0.12.0
type Concatenate struct { Distinct bool SelectStmts []*sqlparser.Select Sources []LogicalOperator OrderBy sqlparser.OrderBy Limit *sqlparser.Limit }
Concatenate represents a UNION ALL/DISTINCT.
func (*Concatenate) CheckValid ¶ added in v0.12.0
func (c *Concatenate) CheckValid() error
CheckValid implements the Operator interface
func (*Concatenate) Compact ¶ added in v0.12.0
func (c *Concatenate) Compact(*semantics.SemTable) (LogicalOperator, error)
Compact implements the Operator interface
func (*Concatenate) PushPredicate ¶ added in v0.12.0
func (c *Concatenate) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the Operator interface
func (*Concatenate) TableID ¶ added in v0.12.0
func (c *Concatenate) TableID() semantics.TableSet
TableID implements the Operator interface
func (*Concatenate) UnsolvedPredicates ¶ added in v0.12.0
func (c *Concatenate) UnsolvedPredicates(*semantics.SemTable) []sqlparser.Expr
UnsolvedPredicates implements the Operator interface
type Derived ¶ added in v0.12.0
type Derived struct { Sel sqlparser.SelectStatement Inner LogicalOperator Alias string ColumnAliases sqlparser.Columns }
Derived represents a derived table in the query
func (*Derived) CheckValid ¶ added in v0.12.0
CheckValid implements the Operator interface
func (*Derived) Compact ¶ added in v0.12.0
func (d *Derived) Compact(*semantics.SemTable) (LogicalOperator, error)
Compact implements the Operator interface
func (*Derived) PushPredicate ¶ added in v0.12.0
func (d *Derived) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the Operator interface
type Filter ¶ added in v0.13.0
type Filter struct { Source LogicalOperator Predicates []sqlparser.Expr }
func (*Filter) CheckValid ¶ added in v0.13.0
CheckValid implements the LogicalOperator interface
func (*Filter) Compact ¶ added in v0.13.0
func (f *Filter) Compact(semTable *semantics.SemTable) (LogicalOperator, error)
Compact implements the LogicalOperator interface
func (*Filter) PushPredicate ¶ added in v0.13.0
func (f *Filter) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the LogicalOperator interface
type GroupBy ¶ added in v0.12.0
type GroupBy struct { Inner sqlparser.Expr WeightStrExpr sqlparser.Expr // The index at which the user expects to see this column. Set to nil, if the user does not ask for it InnerIndex *int // contains filtered or unexported fields }
GroupBy contains the expression to used in group by and also if grouping is needed at VTGate level then what the weight_string function expression to be sent down for evaluation.
func (GroupBy) AsAliasedExpr ¶ added in v0.14.0
func (b GroupBy) AsAliasedExpr() *sqlparser.AliasedExpr
type IntroducesTable ¶ added in v0.14.0
type IntroducesTable interface { GetQTable() *QueryTable GetVTable() *vindexes.Table }
IntroducesTable is used to make it possible to gather information about the table an operator introduces
type Join ¶
type Join struct {
LHS, RHS LogicalOperator
Predicate sqlparser.Expr
LeftJoin bool
}
Join represents a join. If we have a predicate, this is an inner join. If no predicate exists, it is a cross join
func (*Join) CheckValid ¶ added in v0.12.0
CheckValid implements the Operator interface
func (*Join) Compact ¶ added in v0.12.0
func (j *Join) Compact(semTable *semantics.SemTable) (LogicalOperator, error)
Compact implements the Operator interface
func (*Join) PushPredicate ¶
func (j *Join) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the Operator interface
type LogicalOperator ¶ added in v0.13.0
type LogicalOperator interface { Operator // PushPredicate pushes a predicate to the closest possible operator PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error) // Compact will optimise the operator tree into a smaller but equivalent version Compact(semTable *semantics.SemTable) (LogicalOperator, error) // contains filtered or unexported methods }
func CreateLogicalOperatorFromAST ¶ added in v0.14.0
func CreateLogicalOperatorFromAST(selStmt sqlparser.Statement, semTable *semantics.SemTable) (op LogicalOperator, err error)
CreateLogicalOperatorFromAST creates an operator tree that represents the input SELECT or UNION query
type Operator ¶
type Operator interface { // TableID returns a TableSet of the tables contained within TableID() semantics.TableSet // UnsolvedPredicates returns any predicates that have dependencies on the given Operator and // on the outside of it (a parent Select expression, any other table not used by Operator, etc). UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr // CheckValid checks if we have a valid operator tree, and returns an error if something is wrong CheckValid() error }
Operator forms the tree of operators, representing the declarative query provided.
type OrderBy ¶ added in v0.12.0
OrderBy contains the expression to used in order by and also if ordering is needed at VTGate level then what the weight_string function expression to be sent down for evaluation.
type PhysicalOperator ¶ added in v0.13.0
type PhysicalOperator interface { Operator IPhysical() // Cost is simply the number of routes in the operator tree Cost() int // Clone creates a copy of the operator that can be updated without changing the original Clone() PhysicalOperator }
type QueryGraph ¶
type QueryGraph struct { // the Tables, including predicates that only depend on this particular table Tables []*QueryTable // NoDeps contains the predicates that can be evaluated anywhere. NoDeps sqlparser.Expr // contains filtered or unexported fields }
QueryGraph represents the FROM and WHERE parts of a query.
It is an intermediate representation of the query that makes it easier for the planner to find all possible join combinations. Instead of storing the query information in a form that is close to the syntax (AST), we extract the interesting parts into a graph form with the nodes being tables in the FROM clause and the edges between them being predicates. We keep predicates in a hash map keyed by the dependencies of the predicate. This makes it very fast to look up connections between tables in the query.
func (*QueryGraph) CheckValid ¶ added in v0.12.0
func (qg *QueryGraph) CheckValid() error
CheckValid implements the Operator interface
func (*QueryGraph) Compact ¶ added in v0.12.0
func (qg *QueryGraph) Compact(*semantics.SemTable) (LogicalOperator, error)
Compact implements the Operator interface
func (*QueryGraph) GetPredicates ¶
func (qg *QueryGraph) GetPredicates(lhs, rhs semantics.TableSet) []sqlparser.Expr
GetPredicates returns the predicates that are applicable for the two given TableSets
func (*QueryGraph) PushPredicate ¶
func (qg *QueryGraph) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the Operator interface
func (*QueryGraph) TableID ¶
func (qg *QueryGraph) TableID() semantics.TableSet
TableID implements the Operator interface
func (*QueryGraph) UnsolvedPredicates ¶ added in v0.12.0
func (qg *QueryGraph) UnsolvedPredicates(_ *semantics.SemTable) []sqlparser.Expr
UnsolvedPredicates implements the Operator interface
type QueryProjection ¶ added in v0.12.0
type QueryProjection struct { // If you change the contents here, please update the toString() method SelectExprs []SelectExpr HasAggr bool Distinct bool OrderExprs []OrderBy CanPushDownSorting bool HasStar bool // AddedColumn keeps a counter for expressions added to solve HAVING expressions the user is not selecting AddedColumn int // contains filtered or unexported fields }
QueryProjection contains the information about the projections, group by and order by expressions used to do horizon planning.
func CreateQPFromSelect ¶ added in v0.12.0
func CreateQPFromSelect(sel *sqlparser.Select) (*QueryProjection, error)
CreateQPFromSelect creates the QueryProjection for the input *sqlparser.Select
func CreateQPFromUnion ¶ added in v0.12.0
func CreateQPFromUnion(union *sqlparser.Union) (*QueryProjection, error)
CreateQPFromUnion creates the QueryProjection for the input *sqlparser.Union
func (*QueryProjection) AddGroupBy ¶ added in v0.14.0
func (qp *QueryProjection) AddGroupBy(by GroupBy)
AddGroupBy does just that
func (*QueryProjection) AggrRewriter ¶ added in v0.14.0
func (qp *QueryProjection) AggrRewriter() *AggrRewriter
AggrRewriter extracts
func (*QueryProjection) AggregationExpressions ¶ added in v0.14.0
func (qp *QueryProjection) AggregationExpressions() (out []Aggr, err error)
func (*QueryProjection) AlignGroupByAndOrderBy ¶ added in v0.14.0
func (qp *QueryProjection) AlignGroupByAndOrderBy()
AlignGroupByAndOrderBy aligns the group by and order by columns, so they are in the same order The GROUP BY clause is a set - the order between the elements does not make any difference, so we can simply re-arrange the column order We are also free to add more ORDER BY columns than the user asked for which we leverage, so the input is already ordered according to the GROUP BY columns used
func (*QueryProjection) FindSelectExprIndexForExpr ¶ added in v0.14.0
func (qp *QueryProjection) FindSelectExprIndexForExpr(expr sqlparser.Expr) (*int, *sqlparser.AliasedExpr)
FindSelectExprIndexForExpr returns the index of the given expression in the select expressions, if it is part of it returns -1 otherwise.
func (*QueryProjection) GetColumnCount ¶ added in v0.14.0
func (qp *QueryProjection) GetColumnCount() int
func (*QueryProjection) GetGrouping ¶ added in v0.14.0
func (qp *QueryProjection) GetGrouping() []GroupBy
GetGrouping returns a copy of the grouping parameters of the QP
func (*QueryProjection) GetSimplifiedExpr ¶ added in v0.14.0
func (qp *QueryProjection) GetSimplifiedExpr(e sqlparser.Expr) (expr sqlparser.Expr, weightStrExpr sqlparser.Expr, err error)
GetSimplifiedExpr takes an expression used in ORDER BY or GROUP BY, and returns an expression that is simpler to evaluate
func (*QueryProjection) NeedsAggregation ¶ added in v0.12.0
func (qp *QueryProjection) NeedsAggregation() bool
NeedsAggregation returns true if we either have aggregate functions or grouping defined
func (*QueryProjection) NeedsDistinct ¶ added in v0.12.0
func (qp *QueryProjection) NeedsDistinct() bool
NeedsDistinct returns true if the query needs explicit distinct
func (*QueryProjection) NeedsProjecting ¶ added in v0.14.5
func (qp *QueryProjection) NeedsProjecting( ctx *plancontext.PlanningContext, pusher func(expr *sqlparser.AliasedExpr) (int, error), ) (needsVtGateEval bool, expressions []sqlparser.Expr, colNames []string, err error)
NeedsProjecting returns true if we have projections that need to be evaluated at the vtgate level and can't be pushed down to MySQL
type QueryTable ¶
type QueryTable struct { ID semantics.TableSet Alias *sqlparser.AliasedTableExpr Table sqlparser.TableName Predicates []sqlparser.Expr IsInfSchema bool }
QueryTable is a single FROM table, including all predicates particular to this table This is to be used as an immutable data structure which is created in the logical Operator Tree
type SelectExpr ¶ added in v0.12.0
type SelectExpr struct { Col sqlparser.SelectExpr Aggr bool }
SelectExpr provides whether the columns is aggregation expression or not.
func (SelectExpr) GetAliasedExpr ¶ added in v0.12.0
func (s SelectExpr) GetAliasedExpr() (*sqlparser.AliasedExpr, error)
GetAliasedExpr returns the SelectExpr as a *sqlparser.AliasedExpr if its type allows it, otherwise an error is returned.
type SubQuery ¶ added in v0.12.0
type SubQuery struct { Inner []*SubQueryInner Outer LogicalOperator }
SubQuery stores the information about subquery
func (*SubQuery) CheckValid ¶ added in v0.12.0
CheckValid implements the Operator interface
func (*SubQuery) Compact ¶ added in v0.12.0
func (s *SubQuery) Compact(*semantics.SemTable) (LogicalOperator, error)
Compact implements the Operator interface
func (*SubQuery) PushPredicate ¶ added in v0.12.0
PushPredicate implements the Operator interface
type SubQueryInner ¶ added in v0.12.0
type SubQueryInner struct { // Inner is the Operator inside the parenthesis of the subquery. // i.e: select (select 1 union select 1), the Inner here would be // of type Concatenate since we have a Union. Inner LogicalOperator // ExtractedSubquery contains all information we need about this subquery ExtractedSubquery *sqlparser.ExtractedSubquery }
SubQueryInner stores the subquery information for a select statement
type Update ¶ added in v0.14.0
type Update struct { Table *QueryTable TableInfo semantics.TableInfo Assignments map[string]sqlparser.Expr AST *sqlparser.Update }
func (*Update) CheckValid ¶ added in v0.14.0
CheckValid implements the LogicalOperator interface
func (*Update) Compact ¶ added in v0.14.0
func (u *Update) Compact(semTable *semantics.SemTable) (LogicalOperator, error)
Compact implements the LogicalOperator interface
func (*Update) PushPredicate ¶ added in v0.14.0
func (u *Update) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the LogicalOperator interface
type Vindex ¶ added in v0.12.0
type Vindex struct { OpCode engine.VindexOpcode Table VindexTable Vindex vindexes.Vindex Value sqlparser.Expr }
Vindex stores the information about the vindex query
func (*Vindex) CheckValid ¶ added in v0.12.0
CheckValid implements the Operator interface
func (*Vindex) Compact ¶ added in v0.12.0
func (v *Vindex) Compact(*semantics.SemTable) (LogicalOperator, error)
Compact implements the Operator interface
func (*Vindex) PushPredicate ¶ added in v0.12.0
func (v *Vindex) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) (LogicalOperator, error)
PushPredicate implements the Operator interface