physical

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BreakExpressionInLHSandRHS

func BreakExpressionInLHSandRHS(
	ctx *plancontext.PlanningContext,
	expr sqlparser.Expr,
	lhs semantics.TableSet,
) (bvNames []string, columns []*sqlparser.ColName, rewrittenExpr sqlparser.Expr, err error)

BreakExpressionInLHSandRHS takes an expression and extracts the parts that are coming from one of the sides into `ColName`s that are needed

func PushOutputColumns

PushOutputColumns will push the columns to the table they originate from, making sure that intermediate operators pass the data through

func PushPredicate

PushPredicate is used to push predicates. It pushed it as far down as is possible in the tree. If we encounter a join and the predicate depends on both sides of the join, the predicate will be split into two parts, where data is fetched from the LHS of the join to be used in the evaluation on the RHS

func RemovePredicate

RemovePredicate is used when we turn a predicate into a plan operator, and the predicate needs to be removed as an AST construct

func VisitOperators

func VisitOperators(op abstract.PhysicalOperator, f func(tbl abstract.PhysicalOperator) (bool, error)) error

VisitOperators visits all the operators.

Types

type ApplyJoin

type ApplyJoin struct {
	LHS, RHS abstract.PhysicalOperator

	// Columns stores the column indexes of the columns coming from the left and right side
	// negative value comes from LHS and positive from RHS
	Columns []int

	// Vars are the arguments that need to be copied from the LHS to the RHS
	Vars map[string]int

	// LeftJoin will be true in the case of an outer join
	LeftJoin bool

	// JoinCols are the columns from the LHS used for the join.
	// These are the same columns pushed on the LHS that are now used in the Vars field
	LHSColumns []*sqlparser.ColName

	Predicate sqlparser.Expr
}

ApplyJoin is a nested loop join - for each row on the LHS, we'll execute the plan on the RHS, feeding data from left to right

func (*ApplyJoin) CheckValid

func (a *ApplyJoin) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*ApplyJoin) Clone

func (a *ApplyJoin) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*ApplyJoin) Compact

func (a *ApplyJoin) Compact(semTable *semantics.SemTable) (abstract.Operator, error)

Compact implements the PhysicalOperator interface

func (*ApplyJoin) Cost

func (a *ApplyJoin) Cost() int

Cost implements the PhysicalOperator interface

func (*ApplyJoin) IPhysical

func (a *ApplyJoin) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*ApplyJoin) TableID

func (a *ApplyJoin) TableID() semantics.TableSet

TableID implements the PhysicalOperator interface

func (*ApplyJoin) UnsolvedPredicates

func (a *ApplyJoin) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the PhysicalOperator interface

type CorrelatedSubQueryOp

type CorrelatedSubQueryOp struct {
	Outer, Inner abstract.PhysicalOperator
	Extracted    *sqlparser.ExtractedSubquery

	// JoinCols are the columns from the LHS used for the join.
	// These are the same columns pushed on the LHS that are now used in the Vars field
	LHSColumns []*sqlparser.ColName

	// arguments that need to be copied from the outer to inner
	Vars map[string]int
}

func (*CorrelatedSubQueryOp) CheckValid

func (c *CorrelatedSubQueryOp) CheckValid() error

func (*CorrelatedSubQueryOp) Clone

func (*CorrelatedSubQueryOp) Cost

func (c *CorrelatedSubQueryOp) Cost() int

func (*CorrelatedSubQueryOp) IPhysical

func (c *CorrelatedSubQueryOp) IPhysical()

func (*CorrelatedSubQueryOp) TableID

func (*CorrelatedSubQueryOp) UnsolvedPredicates

func (c *CorrelatedSubQueryOp) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

type Cost

type Cost struct {
	VindexCost int
	IsUnique   bool
	OpCode     engine.Opcode
}

Cost is used to make it easy to compare the Cost of two plans with each other

type Delete added in v0.15.0

type Delete struct {
	QTable           *abstract.QueryTable
	VTable           *vindexes.Table
	OwnedVindexQuery string
	AST              *sqlparser.Delete
}

func (*Delete) CheckValid added in v0.15.0

func (d *Delete) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*Delete) Clone added in v0.15.0

func (d *Delete) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Delete) Cost added in v0.15.0

func (d *Delete) Cost() int

Cost implements the PhysicalOperator interface

func (*Delete) GetQTable added in v0.15.0

func (d *Delete) GetQTable() *abstract.QueryTable

GetQTable implements the IntroducesTable interface

func (*Delete) GetVTable added in v0.15.0

func (d *Delete) GetVTable() *vindexes.Table

GetVTable implements the IntroducesTable interface

func (*Delete) IPhysical added in v0.15.0

func (d *Delete) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Delete) TableID added in v0.15.0

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

TableID implements the PhysicalOperator interface

func (*Delete) UnsolvedPredicates added in v0.15.0

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

UnsolvedPredicates implements the PhysicalOperator interface

type Derived

type Derived struct {
	Source abstract.PhysicalOperator

	Query         sqlparser.SelectStatement
	Alias         string
	ColumnAliases sqlparser.Columns

	// Columns needed to feed other plans
	Columns       []*sqlparser.ColName
	ColumnsOffset []int
}

func (*Derived) CheckValid

func (d *Derived) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*Derived) Clone

func (d *Derived) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Derived) Cost

func (d *Derived) Cost() int

Cost implements the PhysicalOperator interface

func (*Derived) IPhysical

func (d *Derived) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Derived) IsMergeable added in v0.14.4

func (d *Derived) IsMergeable(ctx *plancontext.PlanningContext) bool

IsMergeable is not a great name for this function. Suggestions for a better one are welcome! This function will return false if the derived table inside it has to run on the vtgate side, and so can't be merged with subqueries This logic can also be used to check if this is a derived table that can be had on the left hand side of a vtgate join. Since vtgate joins are always nested loop joins, we can't execute them on the RHS if they do some things, like LIMIT or GROUP BY on wrong columns

func (*Derived) TableID

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

TableID implements the PhysicalOperator interface

func (*Derived) UnsolvedPredicates

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

UnsolvedPredicates implements the PhysicalOperator interface

type Filter

type Filter struct {
	Source     abstract.PhysicalOperator
	Predicates []sqlparser.Expr
}

func (*Filter) CheckValid

func (f *Filter) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*Filter) Clone

func (f *Filter) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Filter) Compact

func (f *Filter) Compact(semTable *semantics.SemTable) (abstract.Operator, error)

Compact implements the PhysicalOperator interface

func (*Filter) Cost

func (f *Filter) Cost() int

Cost implements the PhysicalOperator interface

func (*Filter) IPhysical

func (f *Filter) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Filter) TableID

func (f *Filter) TableID() semantics.TableSet

TableID implements the PhysicalOperator interface

func (*Filter) UnsolvedPredicates

func (f *Filter) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the PhysicalOperator interface

type Route

type Route struct {
	Source abstract.PhysicalOperator

	RouteOpCode engine.Opcode
	Keyspace    *vindexes.Keyspace

	// here we store the possible vindexes we can use so that when we add predicates to the plan,
	// we can quickly check if the new predicates enables any new vindex Options
	VindexPreds []*VindexPlusPredicates

	// the best option available is stored here
	Selected *VindexOption

	// The following two fields are used when routing information_schema queries
	SysTableTableSchema []evalengine.Expr
	SysTableTableName   map[string]evalengine.Expr

	// SeenPredicates contains all the predicates that have had a chance to influence routing.
	// If we need to replan routing, we'll use this list
	SeenPredicates []sqlparser.Expr

	// TargetDestination specifies an explicit target destination tablet type
	TargetDestination key.Destination
}

func (*Route) CheckValid

func (r *Route) CheckValid() error

CheckValid implements the Operator interface

func (*Route) Clone

func (r *Route) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Route) Compact

func (r *Route) Compact(semTable *semantics.SemTable) (abstract.Operator, error)

Compact implements the Operator interface

func (*Route) Cost

func (r *Route) Cost() int

Cost implements the Operator interface

func (*Route) IPhysical

func (*Route) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Route) IsSingleShard

func (r *Route) IsSingleShard() bool

func (*Route) PickBestAvailableVindex

func (r *Route) PickBestAvailableVindex()

PickBestAvailableVindex goes over the available vindexes for this route and picks the best one available.

func (*Route) SelectedVindex

func (r *Route) SelectedVindex() vindexes.Vindex

func (*Route) TableID

func (r *Route) TableID() semantics.TableSet

TableID implements the Operator interface

func (*Route) UnsolvedPredicates

func (r *Route) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the Operator interface

func (*Route) UpdateRoutingLogic

func (r *Route) UpdateRoutingLogic(ctx *plancontext.PlanningContext, expr sqlparser.Expr) error

func (*Route) VindexExpressions

func (r *Route) VindexExpressions() []sqlparser.Expr

type SubQueryInner

type SubQueryInner struct {
	Inner abstract.LogicalOperator

	// ExtractedSubquery contains all information we need about this subquery
	ExtractedSubquery *sqlparser.ExtractedSubquery
}

type SubQueryOp

type SubQueryOp struct {
	Outer, Inner abstract.PhysicalOperator
	Extracted    *sqlparser.ExtractedSubquery
}

func (*SubQueryOp) CheckValid

func (s *SubQueryOp) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*SubQueryOp) Clone

Clone implements the PhysicalOperator interface

func (*SubQueryOp) Cost

func (s *SubQueryOp) Cost() int

Cost implements the PhysicalOperator interface

func (*SubQueryOp) IPhysical

func (s *SubQueryOp) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*SubQueryOp) TableID

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

TableID implements the PhysicalOperator interface

func (*SubQueryOp) UnsolvedPredicates

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

UnsolvedPredicates implements the PhysicalOperator interface

type Table

type Table struct {
	QTable  *abstract.QueryTable
	VTable  *vindexes.Table
	Columns []*sqlparser.ColName
}

func (*Table) CheckValid

func (to *Table) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*Table) Clone

func (to *Table) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Table) Compact

func (to *Table) Compact(semTable *semantics.SemTable) (abstract.Operator, error)

Compact implements the PhysicalOperator interface

func (*Table) Cost

func (to *Table) Cost() int

Cost implements the PhysicalOperator interface

func (*Table) GetQTable added in v0.14.0

func (to *Table) GetQTable() *abstract.QueryTable

GetQTable implements the IntroducesTable interface

func (*Table) GetVTable added in v0.14.0

func (to *Table) GetVTable() *vindexes.Table

GetVTable implements the IntroducesTable interface

func (*Table) IPhysical

func (to *Table) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Table) PushPredicate

func (to *Table) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error

PushPredicate implements the PhysicalOperator interface

func (*Table) TableID

func (to *Table) TableID() semantics.TableSet

TableID implements the PhysicalOperator interface

func (*Table) UnsolvedPredicates

func (to *Table) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the PhysicalOperator interface

type Union

type Union struct {
	Sources     []abstract.PhysicalOperator
	SelectStmts []*sqlparser.Select
	Distinct    bool

	// TODO this should be removed. For now it's used to fail queries
	Ordering sqlparser.OrderBy
}

func (*Union) CheckValid

func (u *Union) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*Union) Clone

func (u *Union) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Union) Cost

func (u *Union) Cost() int

Cost implements the PhysicalOperator interface

func (*Union) IPhysical

func (u *Union) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Union) TableID

func (u *Union) TableID() semantics.TableSet

TableID implements the PhysicalOperator interface

func (*Union) UnsolvedPredicates

func (u *Union) UnsolvedPredicates(*semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the PhysicalOperator interface

type Update added in v0.14.0

type Update struct {
	QTable              *abstract.QueryTable
	VTable              *vindexes.Table
	Assignments         map[string]sqlparser.Expr
	ChangedVindexValues map[string]*engine.VindexValues
	OwnedVindexQuery    string
	AST                 *sqlparser.Update
}

func (*Update) CheckValid added in v0.14.0

func (u *Update) CheckValid() error

CheckValid implements the PhysicalOperator interface

func (*Update) Clone added in v0.14.0

func (u *Update) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Update) Cost added in v0.14.0

func (u *Update) Cost() int

Cost implements the PhysicalOperator interface

func (*Update) GetQTable added in v0.14.0

func (u *Update) GetQTable() *abstract.QueryTable

GetQTable implements the IntroducesTable interface

func (*Update) GetVTable added in v0.14.0

func (u *Update) GetVTable() *vindexes.Table

GetVTable implements the IntroducesTable interface

func (*Update) IPhysical added in v0.14.0

func (u *Update) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Update) TableID added in v0.14.0

func (u *Update) TableID() semantics.TableSet

TableID implements the PhysicalOperator interface

func (*Update) UnsolvedPredicates added in v0.14.0

func (u *Update) UnsolvedPredicates(semTable *semantics.SemTable) []sqlparser.Expr

UnsolvedPredicates implements the PhysicalOperator interface

type Vindex

type Vindex struct {
	OpCode  engine.VindexOpcode
	Table   abstract.VindexTable
	Vindex  vindexes.Vindex
	Solved  semantics.TableSet
	Columns []*sqlparser.ColName
	Value   sqlparser.Expr
}

func (*Vindex) CheckValid

func (v *Vindex) CheckValid() error

CheckValid implements the Operator interface

func (*Vindex) Clone

func (v *Vindex) Clone() abstract.PhysicalOperator

Clone implements the PhysicalOperator interface

func (*Vindex) Cost

func (v *Vindex) Cost() int

Cost implements the PhysicalOperator interface

func (*Vindex) IPhysical

func (v *Vindex) IPhysical()

IPhysical implements the PhysicalOperator interface

func (*Vindex) PushOutputColumns

func (v *Vindex) PushOutputColumns(columns []*sqlparser.ColName) ([]int, error)

func (*Vindex) TableID

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

TableID implements the Operator interface

func (*Vindex) UnsolvedPredicates

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

UnsolvedPredicates implements the Operator interface

type VindexOption

type VindexOption struct {
	Ready  bool
	Values []evalengine.Expr
	// columns that we have seen so far. Used only for multi-column vindexes so that we can track how many columns part of the vindex we have seen
	ColsSeen    map[string]any
	ValueExprs  []sqlparser.Expr
	Predicates  []sqlparser.Expr
	OpCode      engine.Opcode
	FoundVindex vindexes.Vindex
	Cost        Cost
}

VindexOption stores the information needed to know if we have all the information needed to use a vindex

type VindexPlusPredicates

type VindexPlusPredicates struct {
	TableID   semantics.TableSet
	ColVindex *vindexes.ColumnVindex

	// during planning, we store the alternatives found for this route in this slice
	Options []*VindexOption
}

VindexPlusPredicates is a struct used to store all the predicates that the vindex can be used to query

Jump to

Keyboard shortcuts

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