Documentation ¶
Index ¶
- Variables
- func ToString(g *memo.Group) []string
- type EliminateOuterJoinBelowAggregation
- type EliminateOuterJoinBelowProjection
- type EliminateProjection
- type EliminateSingleMaxMin
- type Enforcer
- type EnumeratePaths
- type ImplApply
- type ImplHashAgg
- type ImplHashJoinBuildLeft
- type ImplHashJoinBuildRight
- type ImplIndexScan
- type ImplLimit
- type ImplMaxOneRow
- type ImplMemTableScan
- type ImplMergeJoin
- type ImplProjection
- type ImplSelection
- type ImplShow
- type ImplSort
- type ImplTableDual
- type ImplTableScan
- type ImplTiKVSingleReadGather
- type ImplTopN
- type ImplTopNAsLimit
- type ImplUnionAll
- type ImplWindow
- type ImplementationRule
- type InjectProjectionBelowTopN
- type MergeAdjacentLimit
- type MergeAdjacentProjection
- type MergeAdjacentSelection
- type MergeAdjacentTopN
- type MergeAggregationProjection
- type Optimizer
- func (opt *Optimizer) FindBestPlan(sctx sessionctx.Context, logical plannercore.LogicalPlan) (p plannercore.PhysicalPlan, cost float64, err error)
- func (opt *Optimizer) GetImplementationRules(node plannercore.LogicalPlan) []ImplementationRule
- func (opt *Optimizer) ResetImplementationRules(rules map[memo.Operand][]ImplementationRule) *Optimizer
- func (opt *Optimizer) ResetTransformationRules(ruleBatches ...TransformationRuleBatch) *Optimizer
- type OrderEnforcer
- type PullSelectionUpApply
- type PushAggDownGather
- type PushLimitDownOuterJoin
- type PushLimitDownProjection
- type PushLimitDownTiKVSingleGather
- type PushLimitDownUnionAll
- type PushSelDownAggregation
- type PushSelDownIndexScan
- type PushSelDownJoin
- type PushSelDownProjection
- type PushSelDownSort
- type PushSelDownTableScan
- type PushSelDownTiKVSingleGather
- type PushSelDownUnionAll
- type PushSelDownWindow
- type PushTopNDownOuterJoin
- type PushTopNDownProjection
- type PushTopNDownTiKVSingleGather
- type PushTopNDownUnionAll
- type TransformAggToProj
- type TransformAggregateCaseToSelection
- type TransformApplyToJoin
- type TransformLimitToTableDual
- type TransformLimitToTopN
- type Transformation
- func NewRuleEliminateOuterJoinBelowAggregation() Transformation
- func NewRuleEliminateOuterJoinBelowProjection() Transformation
- func NewRuleEliminateProjection() Transformation
- func NewRuleEliminateSingleMaxMin() Transformation
- func NewRuleEnumeratePaths() Transformation
- func NewRuleInjectProjectionBelowTopN() Transformation
- func NewRuleMergeAdjacentLimit() Transformation
- func NewRuleMergeAdjacentProjection() Transformation
- func NewRuleMergeAdjacentSelection() Transformation
- func NewRuleMergeAdjacentTopN() Transformation
- func NewRuleMergeAggregationProjection() Transformation
- func NewRulePullSelectionUpApply() Transformation
- func NewRulePushAggDownGather() Transformation
- func NewRulePushLimitDownOuterJoin() Transformation
- func NewRulePushLimitDownProjection() Transformation
- func NewRulePushLimitDownTiKVSingleGather() Transformation
- func NewRulePushLimitDownUnionAll() Transformation
- func NewRulePushSelDownAggregation() Transformation
- func NewRulePushSelDownIndexScan() Transformation
- func NewRulePushSelDownJoin() Transformation
- func NewRulePushSelDownProjection() Transformation
- func NewRulePushSelDownSort() Transformation
- func NewRulePushSelDownTableScan() Transformation
- func NewRulePushSelDownTiKVSingleGather() Transformation
- func NewRulePushSelDownUnionAll() Transformation
- func NewRulePushSelDownWindow() Transformation
- func NewRulePushTopNDownOuterJoin() Transformation
- func NewRulePushTopNDownProjection() Transformation
- func NewRulePushTopNDownTiKVSingleGather() Transformation
- func NewRulePushTopNDownUnionAll() Transformation
- func NewRuleTransformAggToProj() Transformation
- func NewRuleTransformAggregateCaseToSelection() Transformation
- func NewRuleTransformApplyToJoin() Transformation
- func NewRuleTransformLimitToTableDual() Transformation
- func NewRuleTransformLimitToTopN() Transformation
- type TransformationRuleBatch
Constants ¶
This section is empty.
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.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.
Functions ¶
Types ¶
type EliminateOuterJoinBelowAggregation ¶
type EliminateOuterJoinBelowAggregation struct {
// contains filtered or unexported fields
}
EliminateOuterJoinBelowAggregation eliminate the outer join which below aggregation.
func (*EliminateOuterJoinBelowAggregation) GetPattern ¶
GetPattern implements Transformation Interface.
func (*EliminateOuterJoinBelowAggregation) Match ¶
func (r *EliminateOuterJoinBelowAggregation) Match(expr *memo.ExprIter) bool
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 ¶
GetPattern implements Transformation Interface.
func (*EliminateOuterJoinBelowProjection) Match ¶
func (r *EliminateOuterJoinBelowProjection) Match(expr *memo.ExprIter) bool
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 ¶
GetPattern implements Transformation Interface.
func (*EliminateProjection) OnTransform ¶
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 ¶
type EliminateSingleMaxMin struct {
// contains filtered or unexported fields
}
EliminateSingleMaxMin tries to convert a single max/min to Limit+Sort operators.
func (*EliminateSingleMaxMin) GetPattern ¶
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 ¶
GetPattern implements Transformation Interface.
func (*EnumeratePaths) OnTransform ¶
func (r *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) OnImplement ¶
func (r *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 (r *ImplHashAgg) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplHashAgg) OnImplement ¶
func (r *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 (r *ImplHashJoinBuildLeft) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplHashJoinBuildLeft) OnImplement ¶
func (r *ImplHashJoinBuildLeft) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
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 (r *ImplHashJoinBuildRight) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplHashJoinBuildRight) OnImplement ¶
func (r *ImplHashJoinBuildRight) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface.
type ImplIndexScan ¶
type ImplIndexScan struct { }
ImplIndexScan implements IndexScan as PhysicalIndexScan.
func (*ImplIndexScan) Match ¶
func (r *ImplIndexScan) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplIndexScan) OnImplement ¶
func (r *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) OnImplement ¶
func (r *ImplLimit) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface.
type ImplMaxOneRow ¶
type ImplMaxOneRow struct { }
ImplMaxOneRow implements LogicalMaxOneRow to PhysicalMaxOneRow.
func (*ImplMaxOneRow) Match ¶
func (r *ImplMaxOneRow) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplMaxOneRow) OnImplement ¶
func (r *ImplMaxOneRow) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface
type ImplMemTableScan ¶
type ImplMemTableScan struct { }
ImplMemTableScan implements LogicalMemTable as PhysicalMemTable.
func (*ImplMemTableScan) Match ¶
func (r *ImplMemTableScan) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplMemTableScan) OnImplement ¶
func (r *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 (r *ImplMergeJoin) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplMergeJoin) OnImplement ¶
func (r *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 (r *ImplProjection) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplProjection) OnImplement ¶
func (r *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 (r *ImplSelection) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplSelection) OnImplement ¶
func (r *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) OnImplement ¶
func (r *ImplShow) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface.
type ImplSort ¶
type ImplSort struct { }
ImplSort is the implementation rule which implements LogicalSort to PhysicalSort or NominalSort.
func (*ImplSort) OnImplement ¶
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 ¶
type ImplTableDual struct { }
ImplTableDual implements LogicalTableDual as PhysicalTableDual.
func (*ImplTableDual) Match ¶
func (r *ImplTableDual) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplTableDual) OnImplement ¶
func (r *ImplTableDual) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface.
type ImplTableScan ¶
type ImplTableScan struct { }
ImplTableScan implements TableScan as PhysicalTableScan.
func (*ImplTableScan) Match ¶
func (r *ImplTableScan) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplTableScan) OnImplement ¶
func (r *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 ¶
func (r *ImplTiKVSingleReadGather) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplTiKVSingleReadGather) OnImplement ¶
func (r *ImplTiKVSingleReadGather) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface.
type ImplTopN ¶
type ImplTopN struct { }
ImplTopN is the implementation rule which implements LogicalTopN to PhysicalTopN.
func (*ImplTopN) OnImplement ¶
func (r *ImplTopN) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
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 (r *ImplTopNAsLimit) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplTopNAsLimit) OnImplement ¶
func (r *ImplTopNAsLimit) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error)
OnImplement implements ImplementationRule OnImplement interface.
type ImplUnionAll ¶
type ImplUnionAll struct { }
ImplUnionAll implements LogicalUnionAll to PhysicalUnionAll.
func (*ImplUnionAll) Match ¶
func (r *ImplUnionAll) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplUnionAll) OnImplement ¶
func (r *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 (w *ImplWindow) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool)
Match implements ImplementationRule Match interface.
func (*ImplWindow) OnImplement ¶
func (w *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 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 ¶
GetPattern implements Transformation Interface.
func (*InjectProjectionBelowTopN) Match ¶
func (r *InjectProjectionBelowTopN) Match(expr *memo.ExprIter) bool
Match implements Transformation interface.
func (*InjectProjectionBelowTopN) OnTransform ¶
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 ¶
type MergeAdjacentLimit struct {
// contains filtered or unexported fields
}
MergeAdjacentLimit merge the adjacent limit.
func (*MergeAdjacentLimit) GetPattern ¶
GetPattern implements Transformation Interface.
func (*MergeAdjacentLimit) OnTransform ¶
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 ¶
type MergeAdjacentProjection struct {
// contains filtered or unexported fields
}
MergeAdjacentProjection merge the adjacent projection.
func (*MergeAdjacentProjection) GetPattern ¶
GetPattern implements Transformation Interface.
func (*MergeAdjacentProjection) OnTransform ¶
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 ¶
type MergeAdjacentSelection struct {
// contains filtered or unexported fields
}
MergeAdjacentSelection merge adjacent selection.
func (*MergeAdjacentSelection) GetPattern ¶
GetPattern implements Transformation Interface.
func (*MergeAdjacentSelection) OnTransform ¶
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 ¶
type MergeAdjacentTopN struct {
// contains filtered or unexported fields
}
MergeAdjacentTopN merge adjacent TopN.
func (*MergeAdjacentTopN) GetPattern ¶
GetPattern implements Transformation Interface.
func (*MergeAdjacentTopN) Match ¶
func (r *MergeAdjacentTopN) Match(expr *memo.ExprIter) bool
Match implements Transformation interface.
func (*MergeAdjacentTopN) OnTransform ¶
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 ¶
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 ¶
GetPattern implements Transformation Interface.
func (*MergeAggregationProjection) Match ¶
func (r *MergeAggregationProjection) Match(old *memo.ExprIter) bool
Match implements Transformation interface.
func (*MergeAggregationProjection) OnTransform ¶
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 ¶
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 (e *OrderEnforcer) GetEnforceCost(g *memo.Group) float64
GetEnforceCost calculates cost of sort operator.
func (*OrderEnforcer) NewProperty ¶
func (e *OrderEnforcer) NewProperty(prop *property.PhysicalProperty) (newProp *property.PhysicalProperty)
NewProperty removes order property from required physical property.
func (*OrderEnforcer) OnEnforce ¶
func (e *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 ¶
GetPattern implements Transformation Interface.
func (*PullSelectionUpApply) OnTransform ¶
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 ¶
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 ¶
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 ¶
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 ¶
GetPattern implements Transformation Interface.
func (*PushLimitDownProjection) Match ¶
func (r *PushLimitDownProjection) Match(expr *memo.ExprIter) bool
Match implements Transformation interface.
func (*PushLimitDownProjection) OnTransform ¶
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 ¶
type PushLimitDownTiKVSingleGather struct {
// contains filtered or unexported fields
}
PushLimitDownTiKVSingleGather pushes the limit down to child of TiKVSingleGather.
func (*PushLimitDownTiKVSingleGather) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushLimitDownTiKVSingleGather) Match ¶
func (r *PushLimitDownTiKVSingleGather) Match(expr *memo.ExprIter) bool
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 ¶
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 ¶
GetPattern implements Transformation Interface.
func (*PushSelDownAggregation) OnTransform ¶
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 ¶
type PushSelDownIndexScan struct {
// contains filtered or unexported fields
}
PushSelDownIndexScan pushes a Selection down to IndexScan.
func (*PushSelDownIndexScan) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushSelDownIndexScan) OnTransform ¶
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 ¶
type PushSelDownJoin struct {
// contains filtered or unexported fields
}
PushSelDownJoin pushes Selection through Join.
func (*PushSelDownJoin) GetPattern ¶
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 ¶
GetPattern implements Transformation Interface.
func (*PushSelDownProjection) OnTransform ¶
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 ¶
type PushSelDownSort struct {
// contains filtered or unexported fields
}
PushSelDownSort pushes the Selection down to the child of Sort.
func (*PushSelDownSort) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushSelDownSort) OnTransform ¶
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 ¶
type PushSelDownTableScan struct {
// contains filtered or unexported fields
}
PushSelDownTableScan pushes the selection down to TableScan.
func (*PushSelDownTableScan) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushSelDownTableScan) OnTransform ¶
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 ¶
type PushSelDownTiKVSingleGather struct {
// contains filtered or unexported fields
}
PushSelDownTiKVSingleGather pushes the selection down to child of TiKVSingleGather.
func (*PushSelDownTiKVSingleGather) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushSelDownTiKVSingleGather) OnTransform ¶
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 ¶
type PushSelDownUnionAll struct {
// contains filtered or unexported fields
}
PushSelDownUnionAll pushes selection through union all.
func (*PushSelDownUnionAll) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushSelDownUnionAll) OnTransform ¶
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 ¶
type PushSelDownWindow struct {
// contains filtered or unexported fields
}
PushSelDownWindow pushes Selection down to the child of Window.
func (*PushSelDownWindow) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushSelDownWindow) OnTransform ¶
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 ¶
type PushTopNDownOuterJoin struct {
// contains filtered or unexported fields
}
PushTopNDownOuterJoin pushes topN to outer join.
func (*PushTopNDownOuterJoin) GetPattern ¶
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 ¶
GetPattern implements Transformation Interface.
func (*PushTopNDownProjection) Match ¶
func (r *PushTopNDownProjection) Match(expr *memo.ExprIter) bool
Match implements Transformation interface.
func (*PushTopNDownProjection) OnTransform ¶
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 ¶
type PushTopNDownTiKVSingleGather struct {
// contains filtered or unexported fields
}
PushTopNDownTiKVSingleGather pushes the top-n down to child of TiKVSingleGather.
func (*PushTopNDownTiKVSingleGather) GetPattern ¶
GetPattern implements Transformation Interface.
func (*PushTopNDownTiKVSingleGather) Match ¶
func (r *PushTopNDownTiKVSingleGather) Match(expr *memo.ExprIter) bool
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 ¶
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 ¶
GetPattern implements Transformation Interface.
func (*TransformAggToProj) Match ¶
func (r *TransformAggToProj) Match(expr *memo.ExprIter) bool
Match implements Transformation interface.
func (*TransformAggToProj) OnTransform ¶
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 ¶
type TransformAggregateCaseToSelection struct {
// contains filtered or unexported fields
}
TransformAggregateCaseToSelection convert Agg(case when) to Agg->Selection.
func (*TransformAggregateCaseToSelection) GetPattern ¶
GetPattern implements Transformation Interface.
func (*TransformAggregateCaseToSelection) Match ¶
func (r *TransformAggregateCaseToSelection) Match(expr *memo.ExprIter) bool
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 ¶
GetPattern 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 TransformLimitToTableDual ¶
type TransformLimitToTableDual struct {
// contains filtered or unexported fields
}
TransformLimitToTableDual convert limit to TableDual.
func (*TransformLimitToTableDual) GetPattern ¶
GetPattern implements Transformation Interface.
func (*TransformLimitToTableDual) Match ¶
func (r *TransformLimitToTableDual) Match(expr *memo.ExprIter) bool
Match implements Transformation interface.
func (*TransformLimitToTableDual) OnTransform ¶
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 ¶
type TransformLimitToTopN struct {
// contains filtered or unexported fields
}
TransformLimitToTopN transforms Limit+Sort to TopN.
func (*TransformLimitToTopN) GetPattern ¶
GetPattern implements Transformation Interface.
func (*TransformLimitToTopN) OnTransform ¶
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 ¶
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 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 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 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.