tidb: github.com/pingcap/tidb/planner/cascades Index | Files

package cascades

import "github.com/pingcap/tidb/planner/cascades"

Index

Package Files

enforcer_rules.go implementation_rules.go optimize.go stringer.go transformation_rules.go

Variables

var DefaultOptimizer = NewOptimizer()

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

var DefaultRuleBatches = []TransformationRuleBatch{
    TiDBLayerOptimizationBatch,
    TiKVLayerOptimizationBatch,
    PostTransformationBatch,
}

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

var PostTransformationBatch = TransformationRuleBatch{
    memo.OperandProjection: {
        NewRuleEliminateProjection(),
        NewRuleMergeAdjacentProjection(),
    },
    memo.OperandAggregation: {
        NewRuleInjectProjectionBelowAgg(),
    },
    memo.OperandTopN: {
        NewRuleInjectProjectionBelowTopN(),
    },
}

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.

var TiDBLayerOptimizationBatch = TransformationRuleBatch{
    memo.OperandSelection: {
        NewRulePushSelDownSort(),
        NewRulePushSelDownProjection(),
        NewRulePushSelDownAggregation(),
        NewRulePushSelDownJoin(),
        NewRulePushSelDownUnionAll(),
        NewRulePushSelDownWindow(),
        NewRuleMergeAdjacentSelection(),
    },
    memo.OperandAggregation: {
        NewRuleMergeAggregationProjection(),
        NewRuleEliminateSingleMaxMin(),
        NewRuleEliminateOuterJoinBelowAggregation(),
        NewRuleTransformAggregateCaseToSelection(),
        NewRuleTransformAggToProj(),
    },
    memo.OperandLimit: {
        NewRuleTransformLimitToTopN(),
        NewRulePushLimitDownProjection(),
        NewRulePushLimitDownUnionAll(),
        NewRulePushLimitDownOuterJoin(),
        NewRuleMergeAdjacentLimit(),
        NewRuleTransformLimitToTableDual(),
    },
    memo.OperandProjection: {
        NewRuleEliminateProjection(),
        NewRuleMergeAdjacentProjection(),
        NewRuleEliminateOuterJoinBelowProjection(),
    },
    memo.OperandTopN: {
        NewRulePushTopNDownProjection(),
        NewRulePushTopNDownOuterJoin(),
        NewRulePushTopNDownUnionAll(),
        NewRuleMergeAdjacentTopN(),
    },
    memo.OperandApply: {
        NewRuleTransformApplyToJoin(),
        NewRulePullSelectionUpApply(),
    },
}

TiDBLayerOptimizationBatch does the optimization in the TiDB layer.

var TiKVLayerOptimizationBatch = TransformationRuleBatch{
    memo.OperandDataSource: {
        NewRuleEnumeratePaths(),
    },
    memo.OperandSelection: {
        NewRulePushSelDownTiKVSingleGather(),
        NewRulePushSelDownTableScan(),
        NewRulePushSelDownIndexScan(),
        NewRuleMergeAdjacentSelection(),
    },
    memo.OperandAggregation: {
        NewRulePushAggDownGather(),
    },
    memo.OperandLimit: {
        NewRulePushLimitDownTiKVSingleGather(),
    },
    memo.OperandTopN: {
        NewRulePushTopNDownTiKVSingleGather(),
    },
}

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.

func ToString Uses

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

ToString stringifies a Group Tree.

type EliminateOuterJoinBelowAggregation Uses

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

EliminateOuterJoinBelowAggregation eliminate the outer join which below aggregation.

func (*EliminateOuterJoinBelowAggregation) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*EliminateOuterJoinBelowAggregation) Match Uses

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

Match implements Transformation interface.

func (*EliminateOuterJoinBelowAggregation) OnTransform Uses

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 Uses

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

EliminateOuterJoinBelowProjection eliminate the outer join which below projection.

func (*EliminateOuterJoinBelowProjection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*EliminateOuterJoinBelowProjection) Match Uses

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

Match implements Transformation interface.

func (*EliminateOuterJoinBelowProjection) OnTransform Uses

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 Uses

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

EliminateProjection eliminates the projection.

func (*EliminateProjection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*EliminateProjection) Match Uses

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

Match implements Transformation Interface.

func (*EliminateProjection) OnTransform Uses

func (r *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 Uses

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

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

func (*EliminateSingleMaxMin) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*EliminateSingleMaxMin) Match Uses

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

Match implements Transformation interface.

func (*EliminateSingleMaxMin) OnTransform Uses

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 Uses

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 Uses

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

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

type EnumeratePaths Uses

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

EnumeratePaths converts DataSource to table scan and index scans.

func (*EnumeratePaths) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*EnumeratePaths) Match Uses

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

Match implements Transformation Interface.

func (*EnumeratePaths) OnTransform Uses

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

OnTransform implements Transformation interface.

type ImplApply Uses

type ImplApply struct {
}

ImplApply implements LogicalApply to PhysicalApply

func (*ImplApply) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplApply) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface

type ImplHashAgg Uses

type ImplHashAgg struct {
}

ImplHashAgg is the implementation rule which implements LogicalAggregation to PhysicalHashAgg.

func (*ImplHashAgg) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplHashAgg) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplHashJoinBuildLeft Uses

type ImplHashJoinBuildLeft struct {
}

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

func (*ImplHashJoinBuildLeft) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplHashJoinBuildLeft) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplHashJoinBuildRight Uses

type ImplHashJoinBuildRight struct {
}

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

func (*ImplHashJoinBuildRight) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplHashJoinBuildRight) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplIndexScan Uses

type ImplIndexScan struct {
}

ImplIndexScan implements IndexScan as PhysicalIndexScan.

func (*ImplIndexScan) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplIndexScan) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplLimit Uses

type ImplLimit struct {
}

ImplLimit is the implementation rule which implements LogicalLimit to PhysicalLimit.

func (*ImplLimit) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplLimit) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplMaxOneRow Uses

type ImplMaxOneRow struct {
}

ImplMaxOneRow implements LogicalMaxOneRow to PhysicalMaxOneRow.

func (*ImplMaxOneRow) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplMaxOneRow) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface

type ImplMemTableScan Uses

type ImplMemTableScan struct {
}

ImplMemTableScan implements LogicalMemTable as PhysicalMemTable.

func (*ImplMemTableScan) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplMemTableScan) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplMergeJoin Uses

type ImplMergeJoin struct {
}

ImplMergeJoin implements LogicalMergeJoin to PhysicalMergeJoin.

func (*ImplMergeJoin) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplMergeJoin) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplProjection Uses

type ImplProjection struct {
}

ImplProjection implements LogicalProjection as PhysicalProjection.

func (*ImplProjection) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplProjection) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplSelection Uses

type ImplSelection struct {
}

ImplSelection is the implementation rule which implements LogicalSelection to PhysicalSelection.

func (*ImplSelection) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplSelection) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplShow Uses

type ImplShow struct {
}

ImplShow is the implementation rule which implements LogicalShow to PhysicalShow.

func (*ImplShow) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplShow) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplSort Uses

type ImplSort struct {
}

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

func (*ImplSort) Match Uses

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

Match implements ImplementationRule match interface.

func (*ImplSort) OnImplement Uses

func (r *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 Uses

type ImplTableDual struct {
}

ImplTableDual implements LogicalTableDual as PhysicalTableDual.

func (*ImplTableDual) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplTableDual) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplTableScan Uses

type ImplTableScan struct {
}

ImplTableScan implements TableScan as PhysicalTableScan.

func (*ImplTableScan) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplTableScan) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplTiKVSingleReadGather Uses

type ImplTiKVSingleReadGather struct {
}

ImplTiKVSingleReadGather implements TiKVSingleGather as PhysicalTableReader or PhysicalIndexReader.

func (*ImplTiKVSingleReadGather) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplTiKVSingleReadGather) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplTopN Uses

type ImplTopN struct {
}

ImplTopN is the implementation rule which implements LogicalTopN to PhysicalTopN.

func (*ImplTopN) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplTopN) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplTopNAsLimit Uses

type ImplTopNAsLimit struct {
}

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

func (*ImplTopNAsLimit) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplTopNAsLimit) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplUnionAll Uses

type ImplUnionAll struct {
}

ImplUnionAll implements LogicalUnionAll to PhysicalUnionAll.

func (*ImplUnionAll) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplUnionAll) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplWindow Uses

type ImplWindow struct {
}

ImplWindow implements LogicalWindow to PhysicalWindow.

func (*ImplWindow) Match Uses

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

Match implements ImplementationRule Match interface.

func (*ImplWindow) OnImplement Uses

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

OnImplement implements ImplementationRule OnImplement interface.

type ImplementationRule Uses

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 Uses

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 Uses

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

GetPattern implements Transformation Interface.

func (*InjectProjectionBelowAgg) Match Uses

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

Match implements Transformation interface.

func (*InjectProjectionBelowAgg) OnTransform Uses

func (r *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 Uses

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 Uses

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

GetPattern implements Transformation Interface.

func (*InjectProjectionBelowTopN) Match Uses

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

Match implements Transformation interface.

func (*InjectProjectionBelowTopN) OnTransform Uses

func (r *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 Uses

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

MergeAdjacentLimit merge the adjacent limit.

func (*MergeAdjacentLimit) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*MergeAdjacentLimit) Match Uses

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

Match implements Transformation Interface.

func (*MergeAdjacentLimit) OnTransform Uses

func (r *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 Uses

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

MergeAdjacentProjection merge the adjacent projection.

func (*MergeAdjacentProjection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*MergeAdjacentProjection) Match Uses

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

Match implements Transformation Interface.

func (*MergeAdjacentProjection) OnTransform Uses

func (r *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 Uses

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

MergeAdjacentSelection merge adjacent selection.

func (*MergeAdjacentSelection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*MergeAdjacentSelection) Match Uses

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

Match implements Transformation Interface.

func (*MergeAdjacentSelection) OnTransform Uses

func (r *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 Uses

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

MergeAdjacentTopN merge adjacent TopN.

func (*MergeAdjacentTopN) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*MergeAdjacentTopN) Match Uses

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

Match implements Transformation interface.

func (*MergeAdjacentTopN) OnTransform Uses

func (r *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 MergeAggregationProjection Uses

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 Uses

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

GetPattern implements Transformation Interface.

func (*MergeAggregationProjection) Match Uses

func (r *MergeAggregationProjection) Match(old *memo.ExprIter) bool

Match implements Transformation interface.

func (*MergeAggregationProjection) OnTransform Uses

func (r *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 Uses

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

Optimizer is the struct for cascades optimizer.

func NewOptimizer Uses

func NewOptimizer() *Optimizer

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

func (*Optimizer) FindBestPlan Uses

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 Uses

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 Uses

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

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

func (*Optimizer) ResetTransformationRules Uses

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

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

type OrderEnforcer Uses

type OrderEnforcer struct {
}

OrderEnforcer enforces order property on child implementation.

func (*OrderEnforcer) GetEnforceCost Uses

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

GetEnforceCost calculates cost of sort operator.

func (*OrderEnforcer) NewProperty Uses

func (e *OrderEnforcer) NewProperty(prop *property.PhysicalProperty) (newProp *property.PhysicalProperty)

NewProperty removes order property from required physical property.

func (*OrderEnforcer) OnEnforce Uses

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

OnEnforce adds sort operator to satisfy required order property.

type PullSelectionUpApply Uses

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

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

func (*PullSelectionUpApply) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PullSelectionUpApply) Match Uses

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

Match implements Transformation Interface.

func (*PullSelectionUpApply) OnTransform Uses

func (r *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 Uses

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 Uses

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

GetPattern implements Transformation Interface.

func (*PushAggDownGather) Match Uses

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

Match implements Transformation interface.

func (*PushAggDownGather) OnTransform Uses

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 Uses

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

PushLimitDownOuterJoin pushes Limit through Join.

func (*PushLimitDownOuterJoin) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushLimitDownOuterJoin) Match Uses

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

Match implements Transformation interface.

func (*PushLimitDownOuterJoin) OnTransform Uses

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 Uses

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

PushLimitDownProjection pushes Limit to Projection.

func (*PushLimitDownProjection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushLimitDownProjection) Match Uses

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

Match implements Transformation interface.

func (*PushLimitDownProjection) OnTransform Uses

func (r *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 Uses

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

PushLimitDownTiKVSingleGather pushes the limit down to child of TiKVSingleGather.

func (*PushLimitDownTiKVSingleGather) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushLimitDownTiKVSingleGather) Match Uses

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

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

func (*PushLimitDownTiKVSingleGather) OnTransform Uses

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 Uses

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

PushLimitDownUnionAll pushes limit to union all.

func (*PushLimitDownUnionAll) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushLimitDownUnionAll) Match Uses

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

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

func (*PushLimitDownUnionAll) OnTransform Uses

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 Uses

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

PushSelDownAggregation pushes Selection down to the child of Aggregation.

func (*PushSelDownAggregation) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownAggregation) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownAggregation) OnTransform Uses

func (r *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 Uses

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

PushSelDownIndexScan pushes a Selection down to IndexScan.

func (*PushSelDownIndexScan) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownIndexScan) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownIndexScan) OnTransform Uses

func (r *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 Uses

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

PushSelDownJoin pushes Selection through Join.

func (*PushSelDownJoin) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownJoin) Match Uses

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

Match implements Transformation interface.

func (*PushSelDownJoin) OnTransform Uses

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 Uses

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

PushSelDownProjection pushes the Selection down to the child of Projection.

func (*PushSelDownProjection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownProjection) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownProjection) OnTransform Uses

func (r *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 Uses

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

PushSelDownSort pushes the Selection down to the child of Sort.

func (*PushSelDownSort) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownSort) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownSort) OnTransform Uses

func (r *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 Uses

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

PushSelDownTableScan pushes the selection down to TableScan.

func (*PushSelDownTableScan) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownTableScan) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownTableScan) OnTransform Uses

func (r *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 Uses

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

PushSelDownTiKVSingleGather pushes the selection down to child of TiKVSingleGather.

func (*PushSelDownTiKVSingleGather) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownTiKVSingleGather) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownTiKVSingleGather) OnTransform Uses

func (r *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 Uses

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

PushSelDownUnionAll pushes selection through union all.

func (*PushSelDownUnionAll) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownUnionAll) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownUnionAll) OnTransform Uses

func (r *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 Uses

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

PushSelDownWindow pushes Selection down to the child of Window.

func (*PushSelDownWindow) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushSelDownWindow) Match Uses

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

Match implements Transformation Interface.

func (*PushSelDownWindow) OnTransform Uses

func (r *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 Uses

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

PushTopNDownOuterJoin pushes topN to outer join.

func (*PushTopNDownOuterJoin) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushTopNDownOuterJoin) Match Uses

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

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

func (*PushTopNDownOuterJoin) OnTransform Uses

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 Uses

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

PushTopNDownProjection pushes TopN to Projection.

func (*PushTopNDownProjection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushTopNDownProjection) Match Uses

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

Match implements Transformation interface.

func (*PushTopNDownProjection) OnTransform Uses

func (r *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 Uses

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

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

func (*PushTopNDownTiKVSingleGather) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushTopNDownTiKVSingleGather) Match Uses

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

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

func (*PushTopNDownTiKVSingleGather) OnTransform Uses

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 Uses

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

PushTopNDownUnionAll pushes topN to union all.

func (*PushTopNDownUnionAll) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*PushTopNDownUnionAll) Match Uses

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

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

func (*PushTopNDownUnionAll) OnTransform Uses

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 Uses

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

TransformAggToProj convert Agg to Proj.

func (*TransformAggToProj) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*TransformAggToProj) Match Uses

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

Match implements Transformation interface.

func (*TransformAggToProj) OnTransform Uses

func (r *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 Uses

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

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

func (*TransformAggregateCaseToSelection) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*TransformAggregateCaseToSelection) Match Uses

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

Match implements Transformation interface.

func (*TransformAggregateCaseToSelection) OnTransform Uses

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 Uses

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 Uses

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

GetPattern implements Transformation Interface.

func (*TransformApplyToJoin) Match Uses

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

Match implements Transformation Interface.

func (*TransformApplyToJoin) OnTransform Uses

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

OnTransform implements Transformation interface.

type TransformLimitToTableDual Uses

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

TransformLimitToTableDual convert limit to TableDual.

func (*TransformLimitToTableDual) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*TransformLimitToTableDual) Match Uses

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

Match implements Transformation interface.

func (*TransformLimitToTableDual) OnTransform Uses

func (r *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 Uses

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

TransformLimitToTopN transforms Limit+Sort to TopN.

func (*TransformLimitToTopN) GetPattern Uses

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

GetPattern implements Transformation Interface.

func (*TransformLimitToTopN) Match Uses

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

Match implements Transformation Interface.

func (*TransformLimitToTopN) OnTransform Uses

func (r *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 Uses

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 Uses

func NewRuleEliminateOuterJoinBelowAggregation() Transformation

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

func NewRuleEliminateOuterJoinBelowProjection Uses

func NewRuleEliminateOuterJoinBelowProjection() Transformation

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

func NewRuleEliminateProjection Uses

func NewRuleEliminateProjection() Transformation

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

func NewRuleEliminateSingleMaxMin Uses

func NewRuleEliminateSingleMaxMin() Transformation

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

func NewRuleEnumeratePaths Uses

func NewRuleEnumeratePaths() Transformation

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

func NewRuleInjectProjectionBelowAgg Uses

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 Uses

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 Uses

func NewRuleMergeAdjacentLimit() Transformation

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

func NewRuleMergeAdjacentProjection Uses

func NewRuleMergeAdjacentProjection() Transformation

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

func NewRuleMergeAdjacentSelection Uses

func NewRuleMergeAdjacentSelection() Transformation

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

func NewRuleMergeAdjacentTopN Uses

func NewRuleMergeAdjacentTopN() Transformation

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

func NewRuleMergeAggregationProjection Uses

func NewRuleMergeAggregationProjection() Transformation

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

func NewRulePullSelectionUpApply Uses

func NewRulePullSelectionUpApply() Transformation

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

func NewRulePushAggDownGather Uses

func NewRulePushAggDownGather() Transformation

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

func NewRulePushLimitDownOuterJoin Uses

func NewRulePushLimitDownOuterJoin() Transformation

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

func NewRulePushLimitDownProjection Uses

func NewRulePushLimitDownProjection() Transformation

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

func NewRulePushLimitDownTiKVSingleGather Uses

func NewRulePushLimitDownTiKVSingleGather() Transformation

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

func NewRulePushLimitDownUnionAll Uses

func NewRulePushLimitDownUnionAll() Transformation

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

func NewRulePushSelDownAggregation Uses

func NewRulePushSelDownAggregation() Transformation

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

func NewRulePushSelDownIndexScan Uses

func NewRulePushSelDownIndexScan() Transformation

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

func NewRulePushSelDownJoin Uses

func NewRulePushSelDownJoin() Transformation

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

func NewRulePushSelDownProjection Uses

func NewRulePushSelDownProjection() Transformation

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

func NewRulePushSelDownSort Uses

func NewRulePushSelDownSort() Transformation

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

func NewRulePushSelDownTableScan Uses

func NewRulePushSelDownTableScan() Transformation

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

func NewRulePushSelDownTiKVSingleGather Uses

func NewRulePushSelDownTiKVSingleGather() Transformation

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

func NewRulePushSelDownUnionAll Uses

func NewRulePushSelDownUnionAll() Transformation

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

func NewRulePushSelDownWindow Uses

func NewRulePushSelDownWindow() Transformation

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

func NewRulePushTopNDownOuterJoin Uses

func NewRulePushTopNDownOuterJoin() Transformation

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

func NewRulePushTopNDownProjection Uses

func NewRulePushTopNDownProjection() Transformation

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

func NewRulePushTopNDownTiKVSingleGather Uses

func NewRulePushTopNDownTiKVSingleGather() Transformation

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

func NewRulePushTopNDownUnionAll Uses

func NewRulePushTopNDownUnionAll() Transformation

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

func NewRuleTransformAggToProj Uses

func NewRuleTransformAggToProj() Transformation

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

func NewRuleTransformAggregateCaseToSelection Uses

func NewRuleTransformAggregateCaseToSelection() Transformation

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

func NewRuleTransformApplyToJoin Uses

func NewRuleTransformApplyToJoin() Transformation

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

func NewRuleTransformLimitToTableDual Uses

func NewRuleTransformLimitToTableDual() Transformation

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

func NewRuleTransformLimitToTopN Uses

func NewRuleTransformLimitToTopN() Transformation

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

type TransformationRuleBatch Uses

type TransformationRuleBatch map[memo.Operand][]Transformation

TransformationRuleBatch is a batch of transformation rules.

Package cascades imports 19 packages (graph) and is imported by 8 packages. Updated 2020-07-03. Refresh now. Tools for package owners.