Documentation ¶
Index ¶
- type Concatenate
- func (c *Concatenate) CheckValid() error
- func (c *Concatenate) Compact(*semantics.SemTable) (Operator, error)
- func (c *Concatenate) PushPredicate(sqlparser.Expr, *semantics.SemTable) 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) (Operator, error)
- func (d *Derived) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error
- func (d *Derived) TableID() semantics.TableSet
- func (d *Derived) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type GroupBy
- type Join
- func (j *Join) CheckValid() error
- func (j *Join) Compact(semTable *semantics.SemTable) (Operator, error)
- func (j *Join) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error
- func (j *Join) TableID() semantics.TableSet
- func (j *Join) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type Operator
- type OrderBy
- type QueryGraph
- func (qg *QueryGraph) CheckValid() error
- func (qg *QueryGraph) Compact(*semantics.SemTable) (Operator, error)
- func (qg *QueryGraph) GetPredicates(lhs, rhs semantics.TableSet) []sqlparser.Expr
- func (qg *QueryGraph) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error
- func (qg *QueryGraph) TableID() semantics.TableSet
- func (qg *QueryGraph) UnsolvedPredicates(_ *semantics.SemTable) []sqlparser.Expr
- type QueryProjection
- type QueryTable
- type SelectExpr
- type SubQuery
- func (s *SubQuery) CheckValid() error
- func (s *SubQuery) Compact(*semantics.SemTable) (Operator, error)
- func (s *SubQuery) PushPredicate(sqlparser.Expr, *semantics.SemTable) error
- func (s *SubQuery) TableID() semantics.TableSet
- func (s *SubQuery) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr
- type SubQueryInner
- type Vindex
- func (v *Vindex) CheckValid() error
- func (v *Vindex) Compact(*semantics.SemTable) (Operator, error)
- func (v *Vindex) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) 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 ¶
This section is empty.
Types ¶
type Concatenate ¶ added in v0.12.0
type Concatenate struct { Distinct bool SelectStmts []*sqlparser.Select Sources []Operator OrderBy sqlparser.OrderBy Limit *sqlparser.Limit }
Concatenate represents a UNION ALL.
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) (Operator, error)
Compact implements the Operator interface
func (*Concatenate) PushPredicate ¶ added in v0.12.0
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 Operator Alias string }
Derived represents a derived table in the query
func (*Derived) CheckValid ¶ added in v0.12.0
CheckValid implements the Operator interface
func (*Derived) PushPredicate ¶ added in v0.12.0
PushPredicate implements the Operator interface
type GroupBy ¶ added in v0.12.0
type GroupBy struct { Inner sqlparser.Expr WeightStrExpr sqlparser.Expr // This is to add the distinct function expression in grouping column for pushing down but not be to used as grouping key at VTGate level. // Starts with 1 so that default (0) means unassigned. DistinctAggrIndex int }
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.
type Join ¶
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) PushPredicate ¶
PushPredicate implements the Operator interface
type Operator ¶
type Operator interface { // TableID returns a TableSet of the tables contained within TableID() semantics.TableSet // PushPredicate pushes a predicate to the closest possible operator PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error // 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 // Compact will optimise the operator tree into a smaller but equivalent version Compact(semTable *semantics.SemTable) (Operator, error) }
Operator forms the tree of operators, representing the declarative query provided. An operator can be:
- Derived - which represents an expression that generates a table.
- QueryGraph - which represents a group of tables and predicates that can be evaluated in any order while still preserving the results
- LeftJoin - A left join. These can't be evaluated in any order, so we keep them separate
- Join - A join represents inner join.
- SubQuery - Represents a query that encapsulates one or more sub-queries (SubQueryInner).
- Vindex - Represents a query that selects from vindex tables.
- Concatenate - Represents concatenation of the outputs of all the input sources
func CreateOperatorFromAST ¶ added in v0.12.0
func CreateOperatorFromAST(selStmt sqlparser.SelectStatement, semTable *semantics.SemTable) (op Operator, err error)
CreateOperatorFromAST creates an operator tree that represents the input SELECT or UNION query
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 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) (Operator, 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 ¶
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 GroupByExprs []GroupBy OrderExprs []OrderBy CanPushDownSorting bool HasStar bool }
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, semTable *semantics.SemTable) (*QueryProjection, error)
CreateQPFromSelect creates the QueryProjection for the input *sqlparser.Select
func CreateQPFromUnion ¶ added in v0.12.0
func CreateQPFromUnion(union *sqlparser.Union, semTable *semantics.SemTable) (*QueryProjection, error)
CreateQPFromUnion creates the QueryProjection for the input *sqlparser.Union
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
type QueryTable ¶
type QueryTable struct { TableID 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
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 Operator }
SubQuery stores the information about subquery
func (*SubQuery) CheckValid ¶ added in v0.12.0
CheckValid 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 Operator // Type represents the type of the subquery (value, in, not in, exists) Type engine.PulloutOpcode // SelectStatement is the inner's select SelectStatement *sqlparser.Select // ArgName is the substitution argument string for the subquery. // Subquery argument name looks like: `__sq1`, with `1` being an // unique identifier. This is used when we wish to replace the // subquery by an argument for PullOut subqueries. ArgName string // HasValues is a string of form `__sq_has_values1` with `1` being // a unique identifier that matches the one used in ArgName. // We use `__sq_has_values` for in and not in subqueries. HasValues string // ExprsNeedReplace is a slice of all the expressions that were // introduced by the rewrite of the subquery and that potentially // need to be re-replace if we can merge the subquery into a route. // An expression that contains at least all of ExprsNeedReplace will // be replaced by the expression in ReplaceBy. ExprsNeedReplace []sqlparser.Expr ReplaceBy sqlparser.Expr }
SubQueryInner stores the subquery information for a select statement
type Vindex ¶ added in v0.12.0
type Vindex struct { OpCode engine.VindexOpcode Table VindexTable Vindex vindexes.Vindex Value sqltypes.PlanValue }
Vindex stores the information about the vindex query
func (*Vindex) CheckValid ¶ added in v0.12.0
CheckValid implements the Operator interface
func (*Vindex) PushPredicate ¶ added in v0.12.0
PushPredicate implements the Operator interface