abstract

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func (c *Concatenate) PushPredicate(sqlparser.Expr, *semantics.SemTable) 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 Operator
	Alias string
}

Derived represents a derived table in the query

func (*Derived) CheckValid added in v0.12.0

func (d *Derived) CheckValid() error

CheckValid implements the Operator interface

func (*Derived) Compact added in v0.12.0

func (d *Derived) Compact(*semantics.SemTable) (Operator, error)

Compact implements the Operator interface

func (*Derived) PushPredicate added in v0.12.0

func (d *Derived) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error

PushPredicate implements the Operator interface

func (*Derived) TableID added in v0.12.0

func (d *Derived) TableID() semantics.TableSet

TableID implements the Operator interface

func (*Derived) UnsolvedPredicates added in v0.12.0

func (d *Derived) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates 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

type Join struct {
	LHS, RHS  Operator
	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

func (j *Join) CheckValid() error

CheckValid implements the Operator interface

func (*Join) Compact added in v0.12.0

func (j *Join) Compact(semTable *semantics.SemTable) (Operator, error)

Compact implements the Operator interface

func (*Join) PushPredicate

func (j *Join) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error

PushPredicate implements the Operator interface

func (*Join) TableID

func (j *Join) TableID() semantics.TableSet

TableID implements the Operator interface

func (*Join) UnsolvedPredicates added in v0.12.0

func (j *Join) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates 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

type OrderBy struct {
	Inner         *sqlparser.Order
	WeightStrExpr sqlparser.Expr
}

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

func (qg *QueryGraph) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) 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
	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.

func (SelectExpr) GetExpr added in v0.12.0

func (s SelectExpr) GetExpr() (sqlparser.Expr, error)

GetExpr returns the underlying sqlparser.Expr of our SelectExpr

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

func (s *SubQuery) CheckValid() error

CheckValid implements the Operator interface

func (*SubQuery) Compact added in v0.12.0

func (s *SubQuery) Compact(*semantics.SemTable) (Operator, error)

Compact implements the Operator interface

func (*SubQuery) PushPredicate added in v0.12.0

func (s *SubQuery) PushPredicate(sqlparser.Expr, *semantics.SemTable) error

PushPredicate implements the Operator interface

func (*SubQuery) TableID added in v0.12.0

func (s *SubQuery) TableID() semantics.TableSet

TableID implements the Operator interface

func (*SubQuery) UnsolvedPredicates added in v0.12.0

func (s *SubQuery) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates 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

func (v *Vindex) CheckValid() error

CheckValid implements the Operator interface

func (*Vindex) Compact added in v0.12.0

func (v *Vindex) Compact(*semantics.SemTable) (Operator, error)

Compact implements the Operator interface

func (*Vindex) PushPredicate added in v0.12.0

func (v *Vindex) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error

PushPredicate implements the Operator interface

func (*Vindex) TableID added in v0.12.0

func (v *Vindex) TableID() semantics.TableSet

TableID implements the Operator interface

func (*Vindex) UnsolvedPredicates added in v0.12.0

func (v *Vindex) UnsolvedPredicates(*semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the Operator interface

type VindexTable added in v0.12.0

type VindexTable struct {
	TableID    semantics.TableSet
	Alias      *sqlparser.AliasedTableExpr
	Table      sqlparser.TableName
	Predicates []sqlparser.Expr
	VTable     *vindexes.Table
}

VindexTable contains information about the vindex table we want to query

Jump to

Keyboard shortcuts

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