cascades

package
v1.1.0-beta.0...-9815b45 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptimizer = NewOptimizer()

DefaultOptimizer is the optimizer which contains all of the default transformation and implementation rules.

DefaultRuleBatches contain all the transformation rules. Each batch will be applied to the memo independently.

PostTransformationBatch does the transformation which is related to the constraints of the execution engine of TiDB. For example, TopN/Sort only support `order by` columns in TiDB layer, as for scalar functions, we need to inject a Projection for them below the TopN/Sort.

TiDBLayerOptimizationBatch does the optimization in the TiDB layer.

TiKVLayerOptimizationBatch does the optimization related to TiKV layer. For example, rules about pushing down Operators like Selection, Limit, Aggregation into TiKV layer should be inside this batch.

Functions

func ToString

func ToString(g *memo.Group) []string

ToString stringifies a Group Tree.

Types

type EliminateOuterJoinBelowAggregation

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

EliminateOuterJoinBelowAggregation eliminate the outer join which below aggregation.

func (*EliminateOuterJoinBelowAggregation) GetPattern

func (r *EliminateOuterJoinBelowAggregation) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*EliminateOuterJoinBelowAggregation) Match

Match implements Transformation interface.

func (*EliminateOuterJoinBelowAggregation) OnTransform

func (r *EliminateOuterJoinBelowAggregation) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to eliminate outer join which below aggregation.

type EliminateOuterJoinBelowProjection

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

EliminateOuterJoinBelowProjection eliminate the outer join which below projection.

func (*EliminateOuterJoinBelowProjection) GetPattern

func (r *EliminateOuterJoinBelowProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*EliminateOuterJoinBelowProjection) Match

Match implements Transformation interface.

func (*EliminateOuterJoinBelowProjection) OnTransform

func (r *EliminateOuterJoinBelowProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to eliminate outer join which below projection.

type EliminateProjection

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

EliminateProjection eliminates the projection.

func (*EliminateProjection) GetPattern

func (r *EliminateProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*EliminateProjection) Match

func (*EliminateProjection) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*EliminateProjection) OnTransform

func (*EliminateProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to eliminate the projection whose output columns are the same with its child.

type EliminateSingleMaxMin

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

EliminateSingleMaxMin tries to convert a single max/min to Limit+Sort operators.

func (*EliminateSingleMaxMin) GetPattern

func (r *EliminateSingleMaxMin) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*EliminateSingleMaxMin) Match

func (r *EliminateSingleMaxMin) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*EliminateSingleMaxMin) OnTransform

func (r *EliminateSingleMaxMin) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `max/min->X` to `max/min->top1->sel->X`.

type Enforcer

type Enforcer interface {
	// NewProperty generates relaxed property with the help of enforcer.
	NewProperty(prop *property.PhysicalProperty) (newProp *property.PhysicalProperty)
	// OnEnforce adds physical operators on top of child implementation to satisfy
	// required physical property.
	OnEnforce(reqProp *property.PhysicalProperty, child memo.Implementation) (impl memo.Implementation)
	// GetEnforceCost calculates cost of enforcing required physical property.
	GetEnforceCost(g *memo.Group) float64
}

Enforcer defines the interface for enforcer rules.

func GetEnforcerRules

func GetEnforcerRules(g *memo.Group, prop *property.PhysicalProperty) (enforcers []Enforcer)

GetEnforcerRules gets all candidate enforcer rules based on required physical property.

type EnumeratePaths

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

EnumeratePaths converts DataSource to table scan and index scans.

func (*EnumeratePaths) GetPattern

func (r *EnumeratePaths) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*EnumeratePaths) Match

func (*EnumeratePaths) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*EnumeratePaths) OnTransform

func (*EnumeratePaths) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface.

type ImplApply

type ImplApply struct {
}

ImplApply implements LogicalApply to PhysicalApply

func (*ImplApply) Match

func (*ImplApply) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplApply) OnImplement

func (*ImplApply) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface

type ImplHashAgg

type ImplHashAgg struct {
}

ImplHashAgg is the implementation rule which implements LogicalAggregation to PhysicalHashAgg.

func (*ImplHashAgg) Match

func (*ImplHashAgg) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplHashAgg) OnImplement

func (*ImplHashAgg) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplHashJoinBuildLeft

type ImplHashJoinBuildLeft struct {
}

ImplHashJoinBuildLeft implements LogicalJoin to PhysicalHashJoin which uses the left child to build hash table.

func (*ImplHashJoinBuildLeft) Match

func (*ImplHashJoinBuildLeft) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplHashJoinBuildLeft) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplHashJoinBuildRight

type ImplHashJoinBuildRight struct {
}

ImplHashJoinBuildRight implements LogicalJoin to PhysicalHashJoin which uses the right child to build hash table.

func (*ImplHashJoinBuildRight) Match

func (*ImplHashJoinBuildRight) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplHashJoinBuildRight) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplIndexScan

type ImplIndexScan struct {
}

ImplIndexScan implements IndexScan as PhysicalIndexScan.

func (*ImplIndexScan) Match

func (*ImplIndexScan) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplIndexScan) OnImplement

func (*ImplIndexScan) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplLimit

type ImplLimit struct {
}

ImplLimit is the implementation rule which implements LogicalLimit to PhysicalLimit.

func (*ImplLimit) Match

func (*ImplLimit) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplLimit) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplMaxOneRow

type ImplMaxOneRow struct {
}

ImplMaxOneRow implements LogicalMaxOneRow to PhysicalMaxOneRow.

func (*ImplMaxOneRow) Match

func (*ImplMaxOneRow) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplMaxOneRow) OnImplement

OnImplement implements ImplementationRule OnImplement interface

type ImplMemTableScan

type ImplMemTableScan struct {
}

ImplMemTableScan implements LogicalMemTable as PhysicalMemTable.

func (*ImplMemTableScan) Match

func (*ImplMemTableScan) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplMemTableScan) OnImplement

func (*ImplMemTableScan) OnImplement(
	expr *memo.GroupExpr,
	reqProp *property.PhysicalProperty,
) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplMergeJoin

type ImplMergeJoin struct {
}

ImplMergeJoin implements LogicalMergeJoin to PhysicalMergeJoin.

func (*ImplMergeJoin) Match

func (*ImplMergeJoin) Match(_ *memo.GroupExpr, _ *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplMergeJoin) OnImplement

func (*ImplMergeJoin) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplProjection

type ImplProjection struct {
}

ImplProjection implements LogicalProjection as PhysicalProjection.

func (*ImplProjection) Match

func (*ImplProjection) Match(_ *memo.GroupExpr, _ *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplProjection) OnImplement

func (*ImplProjection) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplSelection

type ImplSelection struct {
}

ImplSelection is the implementation rule which implements LogicalSelection to PhysicalSelection.

func (*ImplSelection) Match

func (*ImplSelection) Match(_ *memo.GroupExpr, _ *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplSelection) OnImplement

func (*ImplSelection) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplShow

type ImplShow struct {
}

ImplShow is the implementation rule which implements LogicalShow to PhysicalShow.

func (*ImplShow) Match

func (*ImplShow) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplShow) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplSort

type ImplSort struct {
}

ImplSort is the implementation rule which implements LogicalSort to PhysicalSort or NominalSort.

func (*ImplSort) Match

func (*ImplSort) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule match interface.

func (*ImplSort) OnImplement

func (*ImplSort) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface. If all of the sort items are columns, generate a NominalSort, otherwise generate a PhysicalSort.

type ImplTableDual

type ImplTableDual struct {
}

ImplTableDual implements LogicalTableDual as PhysicalTableDual.

func (*ImplTableDual) Match

func (*ImplTableDual) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplTableDual) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplTableScan

type ImplTableScan struct {
}

ImplTableScan implements TableScan as PhysicalTableScan.

func (*ImplTableScan) Match

func (*ImplTableScan) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplTableScan) OnImplement

func (*ImplTableScan) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplTiKVSingleReadGather

type ImplTiKVSingleReadGather struct {
}

ImplTiKVSingleReadGather implements TiKVSingleGather as PhysicalTableReader or PhysicalIndexReader.

func (*ImplTiKVSingleReadGather) Match

Match implements ImplementationRule Match interface.

func (*ImplTiKVSingleReadGather) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplTopN

type ImplTopN struct {
}

ImplTopN is the implementation rule which implements LogicalTopN to PhysicalTopN.

func (*ImplTopN) Match

func (*ImplTopN) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplTopN) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplTopNAsLimit

type ImplTopNAsLimit struct {
}

ImplTopNAsLimit is the implementation rule which implements LogicalTopN as PhysicalLimit with required order property.

func (*ImplTopNAsLimit) Match

func (*ImplTopNAsLimit) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplTopNAsLimit) OnImplement

OnImplement implements ImplementationRule OnImplement interface.

type ImplUnionAll

type ImplUnionAll struct {
}

ImplUnionAll implements LogicalUnionAll to PhysicalUnionAll.

func (*ImplUnionAll) Match

func (*ImplUnionAll) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplUnionAll) OnImplement

func (*ImplUnionAll) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplWindow

type ImplWindow struct {
}

ImplWindow implements LogicalWindow to PhysicalWindow.

func (*ImplWindow) Match

func (*ImplWindow) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)

Match implements ImplementationRule Match interface.

func (*ImplWindow) OnImplement

func (*ImplWindow) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)

OnImplement implements ImplementationRule OnImplement interface.

type ImplementationRule

type ImplementationRule interface {
	// Match checks if current GroupExpr matches this rule under required physical property.
	Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
	// OnImplement generates physical plan using this rule for current GroupExpr. Note that
	// childrenReqProps of generated physical plan should be set correspondingly in this function.
	OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
}

ImplementationRule defines the interface for implementation rules.

type InjectProjectionBelowAgg

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

InjectProjectionBelowAgg injects Projection below Agg if Agg's AggFuncDesc.Args or Agg's GroupByItem contain ScalarFunctions.

func (*InjectProjectionBelowAgg) GetPattern

func (r *InjectProjectionBelowAgg) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*InjectProjectionBelowAgg) Match

Match implements Transformation interface.

func (*InjectProjectionBelowAgg) OnTransform

func (*InjectProjectionBelowAgg) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will convert `Agg -> X` to `Agg -> Proj -> X`.

type InjectProjectionBelowTopN

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

InjectProjectionBelowTopN injects two Projections below and upon TopN if TopN's ByItems contain ScalarFunctions.

func (*InjectProjectionBelowTopN) GetPattern

func (r *InjectProjectionBelowTopN) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*InjectProjectionBelowTopN) Match

Match implements Transformation interface.

func (*InjectProjectionBelowTopN) OnTransform

func (*InjectProjectionBelowTopN) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will convert `TopN -> X` to `Projection -> TopN -> Projection -> X`.

type MergeAdjacentLimit

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

MergeAdjacentLimit merge the adjacent limit.

func (*MergeAdjacentLimit) GetPattern

func (r *MergeAdjacentLimit) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*MergeAdjacentLimit) Match

func (*MergeAdjacentLimit) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*MergeAdjacentLimit) OnTransform

func (*MergeAdjacentLimit) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to merge adjacent limit.

type MergeAdjacentProjection

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

MergeAdjacentProjection merge the adjacent projection.

func (*MergeAdjacentProjection) GetPattern

func (r *MergeAdjacentProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*MergeAdjacentProjection) Match

func (*MergeAdjacentProjection) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*MergeAdjacentProjection) OnTransform

func (*MergeAdjacentProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `proj->proj->x` to `proj->x` or just keep the adjacent projections unchanged.

type MergeAdjacentSelection

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

MergeAdjacentSelection merge adjacent selection.

func (*MergeAdjacentSelection) GetPattern

func (r *MergeAdjacentSelection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*MergeAdjacentSelection) Match

func (*MergeAdjacentSelection) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*MergeAdjacentSelection) OnTransform

func (*MergeAdjacentSelection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to merge adjacent selection, with no simplification.

type MergeAdjacentTopN

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

MergeAdjacentTopN merge adjacent TopN.

func (*MergeAdjacentTopN) GetPattern

func (r *MergeAdjacentTopN) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*MergeAdjacentTopN) Match

func (*MergeAdjacentTopN) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*MergeAdjacentTopN) OnTransform

func (*MergeAdjacentTopN) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to merge adjacent TopN.

type MergeAdjacentWindow

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

MergeAdjacentWindow merge adjacent Window.

func (*MergeAdjacentWindow) GetPattern

func (r *MergeAdjacentWindow) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*MergeAdjacentWindow) Match

func (*MergeAdjacentWindow) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*MergeAdjacentWindow) OnTransform

func (*MergeAdjacentWindow) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule will transform `window -> window -> x` to `window -> x`

type MergeAggregationProjection

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

MergeAggregationProjection merges the Projection below an Aggregation as a new Aggregation. The Projection may be regenerated in the ImplementationPhase. But this rule allows the Aggregation to match other rules, such as MergeAdjacentAggregation.

func (*MergeAggregationProjection) GetPattern

func (r *MergeAggregationProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*MergeAggregationProjection) Match

Match implements Transformation interface.

func (*MergeAggregationProjection) OnTransform

func (*MergeAggregationProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `Aggregation->Projection->X` to `Aggregation->X`.

type Optimizer

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

Optimizer is the struct for cascades optimizer.

func NewOptimizer

func NewOptimizer() *Optimizer

NewOptimizer returns a cascades optimizer with default transformation rules and implementation rules.

func (*Optimizer) FindBestPlan

func (opt *Optimizer) FindBestPlan(sctx sessionctx.Context, logical plannercore.LogicalPlan) (p plannercore.PhysicalPlan, cost float64, err error)

FindBestPlan is the optimization entrance of the cascades planner. The optimization is composed of 3 phases: preprocessing, exploration and implementation.

------------------------------------------------------------------------------ Phase 1: Preprocessing ------------------------------------------------------------------------------

The target of this phase is to preprocess the plan tree by some heuristic rules which should always be beneficial, for example Column Pruning.

------------------------------------------------------------------------------ Phase 2: Exploration ------------------------------------------------------------------------------

The target of this phase is to explore all the logically equivalent expressions by exploring all the equivalent group expressions of each group.

At the very beginning, there is only one group expression in a Group. After applying some transformation rules on certain expressions of the Group, all the equivalent expressions are found and stored in the Group. This procedure can be regarded as searching for a weak connected component in a directed graph, where nodes are expressions and directed edges are the transformation rules.

------------------------------------------------------------------------------ Phase 3: Implementation ------------------------------------------------------------------------------

The target of this phase is to search the best physical plan for a Group which satisfies a certain required physical property.

In this phase, we need to enumerate all the applicable implementation rules for each expression in each group under the required physical property. A memo structure is used for a group to reduce the repeated search on the same required physical property.

func (*Optimizer) GetImplementationRules

func (opt *Optimizer) GetImplementationRules(node plannercore.LogicalPlan) []ImplementationRule

GetImplementationRules gets all the candidate implementation rules of the optimizer for the logical plan node.

func (*Optimizer) ResetImplementationRules

func (opt *Optimizer) ResetImplementationRules(rules map[memo.Operand][]ImplementationRule) *Optimizer

ResetImplementationRules resets the implementationRuleMap of the optimizer, and returns the optimizer.

func (*Optimizer) ResetTransformationRules

func (opt *Optimizer) ResetTransformationRules(ruleBatches ...TransformationRuleBatch) *Optimizer

ResetTransformationRules resets the transformationRuleBatches of the optimizer, and returns the optimizer.

type OrderEnforcer

type OrderEnforcer struct {
}

OrderEnforcer enforces order property on child implementation.

func (*OrderEnforcer) GetEnforceCost

func (*OrderEnforcer) GetEnforceCost(g *memo.Group) float64

GetEnforceCost calculates cost of sort operator.

func (*OrderEnforcer) NewProperty

func (*OrderEnforcer) NewProperty(_ *property.PhysicalProperty) (newProp *property.PhysicalProperty)

NewProperty removes order property from required physical property.

func (*OrderEnforcer) OnEnforce

func (*OrderEnforcer) OnEnforce(reqProp *property.PhysicalProperty, child memo.Implementation) (impl memo.Implementation)

OnEnforce adds sort operator to satisfy required order property.

type PullSelectionUpApply

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

PullSelectionUpApply pulls up the inner-side Selection into Apply as its join condition.

func (*PullSelectionUpApply) GetPattern

func (r *PullSelectionUpApply) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PullSelectionUpApply) Match

func (*PullSelectionUpApply) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PullSelectionUpApply) OnTransform

func (*PullSelectionUpApply) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to pull up the inner side Selection, and add these conditions to Join condition inside the Apply.

type PushAggDownGather

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

PushAggDownGather splits Aggregation to two stages, final and partial1, and pushed the partial Aggregation down to the child of TiKVSingleGather.

func (*PushAggDownGather) GetPattern

func (r *PushAggDownGather) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushAggDownGather) Match

func (r *PushAggDownGather) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*PushAggDownGather) OnTransform

func (r *PushAggDownGather) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `Agg->Gather` to `Agg(Final) -> Gather -> Agg(Partial1)`.

type PushLimitDownOuterJoin

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

PushLimitDownOuterJoin pushes Limit through Join.

func (*PushLimitDownOuterJoin) GetPattern

func (r *PushLimitDownOuterJoin) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushLimitDownOuterJoin) Match

func (r *PushLimitDownOuterJoin) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*PushLimitDownOuterJoin) OnTransform

func (r *PushLimitDownOuterJoin) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to pushes the Limit through outer Join.

type PushLimitDownProjection

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

PushLimitDownProjection pushes Limit to Projection.

func (*PushLimitDownProjection) GetPattern

func (r *PushLimitDownProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushLimitDownProjection) Match

func (*PushLimitDownProjection) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*PushLimitDownProjection) OnTransform

func (*PushLimitDownProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to pushes the Limit through Projection.

type PushLimitDownTiKVSingleGather

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

PushLimitDownTiKVSingleGather pushes the limit down to child of TiKVSingleGather.

func (*PushLimitDownTiKVSingleGather) GetPattern

func (r *PushLimitDownTiKVSingleGather) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushLimitDownTiKVSingleGather) Match

Match implements Transformation interface. Use appliedRuleSet in GroupExpr to avoid re-apply rules.

func (*PushLimitDownTiKVSingleGather) OnTransform

func (r *PushLimitDownTiKVSingleGather) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It transforms `Limit -> TiKVSingleGather` to `Limit(Final) -> TiKVSingleGather -> Limit(Partial)`.

type PushLimitDownUnionAll

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

PushLimitDownUnionAll pushes limit to union all.

func (*PushLimitDownUnionAll) GetPattern

func (r *PushLimitDownUnionAll) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushLimitDownUnionAll) Match

func (r *PushLimitDownUnionAll) Match(expr *memo.ExprIter) bool

Match implements Transformation interface. Use appliedRuleSet in GroupExpr to avoid re-apply rules.

func (*PushLimitDownUnionAll) OnTransform

func (r *PushLimitDownUnionAll) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `Limit->UnionAll->X` to `Limit->UnionAll->Limit->X`.

type PushSelDownAggregation

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

PushSelDownAggregation pushes Selection down to the child of Aggregation.

func (*PushSelDownAggregation) GetPattern

func (r *PushSelDownAggregation) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownAggregation) Match

func (*PushSelDownAggregation) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownAggregation) OnTransform

func (*PushSelDownAggregation) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `sel->agg->x` to `agg->sel->x` or `sel->agg->sel->x` or just keep the selection unchanged.

type PushSelDownIndexScan

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

PushSelDownIndexScan pushes a Selection down to IndexScan.

func (*PushSelDownIndexScan) GetPattern

func (r *PushSelDownIndexScan) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownIndexScan) Match

func (*PushSelDownIndexScan) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownIndexScan) OnTransform

func (*PushSelDownIndexScan) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `Selection -> IndexScan` to:

  `IndexScan(with a new access range)` or
  `Selection -> IndexScan(with a new access range)`
	 or just keep the two GroupExprs unchanged.

type PushSelDownJoin

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

PushSelDownJoin pushes Selection through Join.

func (*PushSelDownJoin) GetPattern

func (r *PushSelDownJoin) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownJoin) Match

func (r *PushSelDownJoin) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*PushSelDownJoin) OnTransform

func (r *PushSelDownJoin) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to pushes the Selection through Join. Besides, this rule fulfills the `XXXConditions` field of Join.

type PushSelDownProjection

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

PushSelDownProjection pushes the Selection down to the child of Projection.

func (*PushSelDownProjection) GetPattern

func (r *PushSelDownProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownProjection) Match

func (*PushSelDownProjection) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownProjection) OnTransform

func (*PushSelDownProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `selection -> projection -> x` to 1. `projection -> selection -> x` or 2. `selection -> projection -> selection -> x` or 3. just keep unchanged.

type PushSelDownSort

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

PushSelDownSort pushes the Selection down to the child of Sort.

func (*PushSelDownSort) GetPattern

func (r *PushSelDownSort) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownSort) Match

func (*PushSelDownSort) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownSort) OnTransform

func (*PushSelDownSort) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `sel->sort->x` to `sort->sel->x`.

type PushSelDownTableScan

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

PushSelDownTableScan pushes the selection down to TableScan.

func (*PushSelDownTableScan) GetPattern

func (r *PushSelDownTableScan) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownTableScan) Match

func (*PushSelDownTableScan) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownTableScan) OnTransform

func (*PushSelDownTableScan) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface.

It transforms `sel -> ts` to one of the following new exprs: 1. `newSel -> newTS` 2. `newTS`

Filters of the old `sel` operator are removed if they are used to calculate the key ranges of the `ts` operator.

type PushSelDownTiKVSingleGather

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

PushSelDownTiKVSingleGather pushes the selection down to child of TiKVSingleGather.

func (*PushSelDownTiKVSingleGather) GetPattern

func (r *PushSelDownTiKVSingleGather) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownTiKVSingleGather) Match

func (*PushSelDownTiKVSingleGather) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownTiKVSingleGather) OnTransform

func (*PushSelDownTiKVSingleGather) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface.

It transforms `oldSel -> oldTg -> any` to one of the following new exprs: 1. `newTg -> pushedSel -> any` 2. `remainedSel -> newTg -> pushedSel -> any`

type PushSelDownUnionAll

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

PushSelDownUnionAll pushes selection through union all.

func (*PushSelDownUnionAll) GetPattern

func (r *PushSelDownUnionAll) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownUnionAll) Match

func (*PushSelDownUnionAll) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownUnionAll) OnTransform

func (*PushSelDownUnionAll) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `Selection->UnionAll->x` to `UnionAll->Selection->x`.

type PushSelDownWindow

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

PushSelDownWindow pushes Selection down to the child of Window.

func (*PushSelDownWindow) GetPattern

func (r *PushSelDownWindow) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushSelDownWindow) Match

func (*PushSelDownWindow) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*PushSelDownWindow) OnTransform

func (*PushSelDownWindow) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule will transform `sel -> window -> x` to 1. `window -> sel -> x` or 2. `sel -> window -> sel -> x` or 3. just keep unchanged.

type PushTopNDownOuterJoin

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

PushTopNDownOuterJoin pushes topN to outer join.

func (*PushTopNDownOuterJoin) GetPattern

func (r *PushTopNDownOuterJoin) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushTopNDownOuterJoin) Match

func (r *PushTopNDownOuterJoin) Match(expr *memo.ExprIter) bool

Match implements Transformation interface. Use appliedRuleSet in GroupExpr to avoid re-apply rules.

func (*PushTopNDownOuterJoin) OnTransform

func (r *PushTopNDownOuterJoin) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule will transform `TopN->OuterJoin->(OuterChild, InnerChild)` to `TopN->OuterJoin->(TopN->OuterChild, InnerChild)`

type PushTopNDownProjection

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

PushTopNDownProjection pushes TopN to Projection.

func (*PushTopNDownProjection) GetPattern

func (r *PushTopNDownProjection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushTopNDownProjection) Match

func (*PushTopNDownProjection) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*PushTopNDownProjection) OnTransform

func (*PushTopNDownProjection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to pushes the TopN through Projection.

type PushTopNDownTiKVSingleGather

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

PushTopNDownTiKVSingleGather pushes the top-n down to child of TiKVSingleGather.

func (*PushTopNDownTiKVSingleGather) GetPattern

func (r *PushTopNDownTiKVSingleGather) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushTopNDownTiKVSingleGather) Match

Match implements Transformation interface. Use appliedRuleSet in GroupExpr to avoid re-apply rules.

func (*PushTopNDownTiKVSingleGather) OnTransform

func (r *PushTopNDownTiKVSingleGather) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It transforms `TopN -> TiKVSingleGather` to `TopN(Final) -> TiKVSingleGather -> TopN(Partial)`.

type PushTopNDownUnionAll

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

PushTopNDownUnionAll pushes topN to union all.

func (*PushTopNDownUnionAll) GetPattern

func (r *PushTopNDownUnionAll) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*PushTopNDownUnionAll) Match

func (r *PushTopNDownUnionAll) Match(expr *memo.ExprIter) bool

Match implements Transformation interface. Use appliedRuleSet in GroupExpr to avoid re-apply rules.

func (*PushTopNDownUnionAll) OnTransform

func (r *PushTopNDownUnionAll) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. It will transform `TopN->UnionAll->X` to `TopN->UnionAll->TopN->X`.

type TransformAggToProj

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

TransformAggToProj convert Agg to Proj.

func (*TransformAggToProj) GetPattern

func (r *TransformAggToProj) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*TransformAggToProj) Match

func (*TransformAggToProj) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*TransformAggToProj) OnTransform

func (*TransformAggToProj) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to convert agg to proj.

type TransformAggregateCaseToSelection

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

TransformAggregateCaseToSelection convert Agg(case when) to Agg->Selection.

func (*TransformAggregateCaseToSelection) GetPattern

func (r *TransformAggregateCaseToSelection) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*TransformAggregateCaseToSelection) Match

Match implements Transformation interface.

func (*TransformAggregateCaseToSelection) OnTransform

func (r *TransformAggregateCaseToSelection) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to convert Agg(case when) to Agg->Selection.

type TransformApplyToJoin

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

TransformApplyToJoin transforms a LogicalApply to LogicalJoin if it's inner children has no correlated columns from it's outer schema.

func (*TransformApplyToJoin) GetPattern

func (r *TransformApplyToJoin) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*TransformApplyToJoin) Match

func (*TransformApplyToJoin) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*TransformApplyToJoin) OnTransform

func (r *TransformApplyToJoin) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface.

type TransformJoinCondToSel

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

TransformJoinCondToSel convert Join(len(cond) > 0) to Join-->(Sel, Sel).

func (*TransformJoinCondToSel) GetPattern

func (r *TransformJoinCondToSel) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*TransformJoinCondToSel) Match

func (r *TransformJoinCondToSel) Match(expr *memo.ExprIter) bool

Match implements Transformation interface.

func (*TransformJoinCondToSel) OnTransform

func (r *TransformJoinCondToSel) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to transform Join conditions to Selection. Besides, this rule fulfills the `XXXConditions` field of Join.

type TransformLimitToTableDual

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

TransformLimitToTableDual convert limit to TableDual.

func (*TransformLimitToTableDual) GetPattern

func (r *TransformLimitToTableDual) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*TransformLimitToTableDual) Match

Match implements Transformation interface.

func (*TransformLimitToTableDual) OnTransform

func (*TransformLimitToTableDual) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule tries to convert limit to tableDual.

type TransformLimitToTopN

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

TransformLimitToTopN transforms Limit+Sort to TopN.

func (*TransformLimitToTopN) GetPattern

func (r *TransformLimitToTopN) GetPattern() *memo.Pattern

GetPattern implements Transformation Interface.

func (*TransformLimitToTopN) Match

func (*TransformLimitToTopN) Match(_ *memo.ExprIter) bool

Match implements Transformation Interface.

func (*TransformLimitToTopN) OnTransform

func (*TransformLimitToTopN) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)

OnTransform implements Transformation interface. This rule will transform `Limit -> Sort -> x` to `TopN -> x`.

type Transformation

type Transformation interface {
	// GetPattern gets the cached pattern of the rule.
	GetPattern() *memo.Pattern
	// Match is used to check whether the GroupExpr satisfies all the requirements of the transformation rule.
	//
	// The pattern only identifies the operator type, some transformation rules also need
	// detailed information for certain plan operators to decide whether it is applicable.
	Match(expr *memo.ExprIter) bool
	// OnTransform does the real work of the optimization rule.
	//
	// newExprs indicates the new GroupExprs generated by the transformationrule. Multiple GroupExprs may be
	// returned, e.g, EnumeratePath would convert DataSource to several possible assess paths.
	//
	// eraseOld indicates that the returned GroupExpr must be better than the old one, so we can remove it from Group.
	//
	// eraseAll indicates that the returned GroupExpr must be better than all other candidates in the Group, e.g, we can
	// prune all other access paths if we found the filter is constantly false.
	OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error)
}

Transformation defines the interface for the transformation rules.

func NewRuleEliminateOuterJoinBelowAggregation

func NewRuleEliminateOuterJoinBelowAggregation() Transformation

NewRuleEliminateOuterJoinBelowAggregation creates a new Transformation EliminateOuterJoinBelowAggregation. The pattern of this rule is `Aggregation->Join->X`.

func NewRuleEliminateOuterJoinBelowProjection

func NewRuleEliminateOuterJoinBelowProjection() Transformation

NewRuleEliminateOuterJoinBelowProjection creates a new Transformation EliminateOuterJoinBelowProjection. The pattern of this rule is `Projection->Join->X`.

func NewRuleEliminateProjection

func NewRuleEliminateProjection() Transformation

NewRuleEliminateProjection creates a new Transformation EliminateProjection. The pattern of this rule is `Projection -> Any`.

func NewRuleEliminateSingleMaxMin

func NewRuleEliminateSingleMaxMin() Transformation

NewRuleEliminateSingleMaxMin creates a new Transformation EliminateSingleMaxMin. The pattern of this rule is `max/min->X`.

func NewRuleEnumeratePaths

func NewRuleEnumeratePaths() Transformation

NewRuleEnumeratePaths creates a new Transformation EnumeratePaths. The pattern of this rule is: `DataSource`.

func NewRuleInjectProjectionBelowAgg

func NewRuleInjectProjectionBelowAgg() Transformation

NewRuleInjectProjectionBelowAgg creates a new Transformation NewRuleInjectProjectionBelowAgg. It will extract the ScalarFunctions of `AggFuncDesc` and `GroupByItems` into a Projection and injects it below Agg. The reason why we need this rule is that, AggExecutor in TiDB does not support ScalarFunction as `AggFuncDesc.Arg` and `GroupByItem`. So we have to use a Projection to calculate the ScalarFunctions in advance. The pattern of this rule is: a single Aggregation.

func NewRuleInjectProjectionBelowTopN

func NewRuleInjectProjectionBelowTopN() Transformation

NewRuleInjectProjectionBelowTopN creates a new Transformation InjectProjectionBelowTopN. It will extract the ScalarFunctions of `ByItems` into a Projection and injects it below TopN. When a Projection is injected as the child of TopN, we need to add another Projection upon TopN to prune the extra Columns. The reason why we need this rule is that, TopNExecutor in TiDB does not support ScalarFunction as `ByItem`. So we have to use a Projection to calculate the ScalarFunctions in advance. The pattern of this rule is: a single TopN

func NewRuleMergeAdjacentLimit

func NewRuleMergeAdjacentLimit() Transformation

NewRuleMergeAdjacentLimit creates a new Transformation MergeAdjacentLimit. The pattern of this rule is `Limit->Limit->X`.

func NewRuleMergeAdjacentProjection

func NewRuleMergeAdjacentProjection() Transformation

NewRuleMergeAdjacentProjection creates a new Transformation MergeAdjacentProjection. The pattern of this rule is `Projection -> Projection`.

func NewRuleMergeAdjacentSelection

func NewRuleMergeAdjacentSelection() Transformation

NewRuleMergeAdjacentSelection creates a new Transformation MergeAdjacentSelection. The pattern of this rule is `Selection->Selection->X`.

func NewRuleMergeAdjacentTopN

func NewRuleMergeAdjacentTopN() Transformation

NewRuleMergeAdjacentTopN creates a new Transformation MergeAdjacentTopN. The pattern of this rule is `TopN->TopN->X`.

func NewRuleMergeAdjacentWindow

func NewRuleMergeAdjacentWindow() Transformation

NewRuleMergeAdjacentWindow creates a new Transformation MergeAdjacentWindow. The pattern of this rule is `Window -> Window`.

func NewRuleMergeAggregationProjection

func NewRuleMergeAggregationProjection() Transformation

NewRuleMergeAggregationProjection creates a new Transformation MergeAggregationProjection. The pattern of this rule is: `Aggregation -> Projection`.

func NewRulePullSelectionUpApply

func NewRulePullSelectionUpApply() Transformation

NewRulePullSelectionUpApply creates a new Transformation PullSelectionUpApply. The pattern of this rule is: `Apply -> (Any<outer>, Selection<inner>)`.

func NewRulePushAggDownGather

func NewRulePushAggDownGather() Transformation

NewRulePushAggDownGather creates a new Transformation PushAggDownGather. The pattern of this rule is: `Aggregation -> TiKVSingleGather`.

func NewRulePushLimitDownOuterJoin

func NewRulePushLimitDownOuterJoin() Transformation

NewRulePushLimitDownOuterJoin creates a new Transformation PushLimitDownOuterJoin. The pattern of this rule is `Limit -> Join`.

func NewRulePushLimitDownProjection

func NewRulePushLimitDownProjection() Transformation

NewRulePushLimitDownProjection creates a new Transformation. The pattern of this rule is `Limit->Projection->X` to `Projection->Limit->X`.

func NewRulePushLimitDownTiKVSingleGather

func NewRulePushLimitDownTiKVSingleGather() Transformation

NewRulePushLimitDownTiKVSingleGather creates a new Transformation PushLimitDownTiKVSingleGather. The pattern of this rule is `Limit -> TiKVSingleGather`.

func NewRulePushLimitDownUnionAll

func NewRulePushLimitDownUnionAll() Transformation

NewRulePushLimitDownUnionAll creates a new Transformation PushLimitDownUnionAll. The pattern of this rule is `Limit->UnionAll->X`.

func NewRulePushSelDownAggregation

func NewRulePushSelDownAggregation() Transformation

NewRulePushSelDownAggregation creates a new Transformation PushSelDownAggregation. The pattern of this rule is `Selection -> Aggregation`.

func NewRulePushSelDownIndexScan

func NewRulePushSelDownIndexScan() Transformation

NewRulePushSelDownIndexScan creates a new Transformation PushSelDownIndexScan. The pattern of this rule is `Selection -> IndexScan`.

func NewRulePushSelDownJoin

func NewRulePushSelDownJoin() Transformation

NewRulePushSelDownJoin creates a new Transformation PushSelDownJoin. The pattern of this rule is `Selection -> Join`.

func NewRulePushSelDownProjection

func NewRulePushSelDownProjection() Transformation

NewRulePushSelDownProjection creates a new Transformation PushSelDownProjection. The pattern of this rule is: `Selection -> Projection`.

func NewRulePushSelDownSort

func NewRulePushSelDownSort() Transformation

NewRulePushSelDownSort creates a new Transformation PushSelDownSort. The pattern of this rule is: `Selection -> Sort`.

func NewRulePushSelDownTableScan

func NewRulePushSelDownTableScan() Transformation

NewRulePushSelDownTableScan creates a new Transformation PushSelDownTableScan. The pattern of this rule is: `Selection -> TableScan`

func NewRulePushSelDownTiKVSingleGather

func NewRulePushSelDownTiKVSingleGather() Transformation

NewRulePushSelDownTiKVSingleGather creates a new Transformation PushSelDownTiKVSingleGather. The pattern of this rule is `Selection -> TiKVSingleGather -> Any`.

func NewRulePushSelDownUnionAll

func NewRulePushSelDownUnionAll() Transformation

NewRulePushSelDownUnionAll creates a new Transformation PushSelDownUnionAll. The pattern of this rule is `Selection -> UnionAll`.

func NewRulePushSelDownWindow

func NewRulePushSelDownWindow() Transformation

NewRulePushSelDownWindow creates a new Transformation PushSelDownWindow. The pattern of this rule is `Selection -> Window`.

func NewRulePushTopNDownOuterJoin

func NewRulePushTopNDownOuterJoin() Transformation

NewRulePushTopNDownOuterJoin creates a new Transformation PushTopNDownOuterJoin. The pattern of this rule is: `TopN -> Join`.

func NewRulePushTopNDownProjection

func NewRulePushTopNDownProjection() Transformation

NewRulePushTopNDownProjection creates a new Transformation PushTopNDownProjection. The pattern of this rule is `TopN->Projection->X` to `Projection->TopN->X`.

func NewRulePushTopNDownTiKVSingleGather

func NewRulePushTopNDownTiKVSingleGather() Transformation

NewRulePushTopNDownTiKVSingleGather creates a new Transformation PushTopNDownTiKVSingleGather. The pattern of this rule is `TopN -> TiKVSingleGather`.

func NewRulePushTopNDownUnionAll

func NewRulePushTopNDownUnionAll() Transformation

NewRulePushTopNDownUnionAll creates a new Transformation PushTopNDownUnionAll. The pattern of this rule is `TopN->UnionAll->X`.

func NewRuleTransformAggToProj

func NewRuleTransformAggToProj() Transformation

NewRuleTransformAggToProj creates a new Transformation TransformAggToProj. The pattern of this rule is `Agg`.

func NewRuleTransformAggregateCaseToSelection

func NewRuleTransformAggregateCaseToSelection() Transformation

NewRuleTransformAggregateCaseToSelection creates a new Transformation TransformAggregateCaseToSelection. The pattern of this rule is `Agg->X`.

func NewRuleTransformApplyToJoin

func NewRuleTransformApplyToJoin() Transformation

NewRuleTransformApplyToJoin creates a new Transformation TransformApplyToJoin. The pattern of this rule is: `Apply -> (X, Y)`.

func NewRuleTransformJoinCondToSel

func NewRuleTransformJoinCondToSel() Transformation

NewRuleTransformJoinCondToSel creates a new Transformation TransformJoinCondToSel. The pattern of this rule is: `Join`.

func NewRuleTransformLimitToTableDual

func NewRuleTransformLimitToTableDual() Transformation

NewRuleTransformLimitToTableDual creates a new Transformation TransformLimitToTableDual. The pattern of this rule is `Limit->X`.

func NewRuleTransformLimitToTopN

func NewRuleTransformLimitToTopN() Transformation

NewRuleTransformLimitToTopN creates a new Transformation TransformLimitToTopN. The pattern of this rule is `Limit -> Sort`.

type TransformationRuleBatch

type TransformationRuleBatch map[memo.Operand][]Transformation

TransformationRuleBatch is a batch of transformation rules.

Jump to

Keyboard shortcuts

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