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

package memo

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


Package Files

expr_iterator.go group.go group_expr.go implementation.go pattern.go


const (
    // EngineTiDBOnly is the EngineTypeSet for EngineTiDB only.
    EngineTiDBOnly = EngineTypeSet(EngineTiDB)
    // EngineTiKVOnly is the EngineTypeSet for EngineTiKV only.
    EngineTiKVOnly = EngineTypeSet(EngineTiKV)
    // EngineTiFlashOnly is the EngineTypeSet for EngineTiFlash only.
    EngineTiFlashOnly = EngineTypeSet(EngineTiFlash)
    // EngineTiKVOrTiFlash is the EngineTypeSet for (EngineTiKV | EngineTiFlash).
    EngineTiKVOrTiFlash = EngineTypeSet(EngineTiKV | EngineTiFlash)
    // EngineAll is the EngineTypeSet for all of the EngineTypes.
    EngineAll = EngineTypeSet(EngineTiDB | EngineTiKV | EngineTiFlash)

type EngineType Uses

type EngineType uint

EngineType is determined by whether it's above or below `Gather`s. Plan will choose the different engine to be implemented/executed on according to its EngineType. Different engine may support different operators with different cost, so we should design different transformation and implementation rules for each engine.

const (
    // EngineTiDB stands for groups which is above `Gather`s and will be executed in TiDB layer.
    EngineTiDB EngineType = 1 << iota
    // EngineTiKV stands for groups which is below `Gather`s and will be executed in TiKV layer.
    // EngineTiFlash stands for groups which is below `Gather`s and will be executed in TiFlash layer.

func (EngineType) String Uses

func (e EngineType) String() string

String implements fmt.Stringer interface.

type EngineTypeSet Uses

type EngineTypeSet uint

EngineTypeSet is the bit set of EngineTypes.

func (EngineTypeSet) Contains Uses

func (e EngineTypeSet) Contains(tp EngineType) bool

Contains checks whether the EngineTypeSet contains the EngineType.

type ExploreMark Uses

type ExploreMark int

ExploreMark is uses to mark whether a Group or GroupExpr has been fully explored by a transformation rule batch.

func (*ExploreMark) Explored Uses

func (m *ExploreMark) Explored(round int) bool

Explored returns whether the roundth bit has been set.

func (*ExploreMark) SetExplored Uses

func (m *ExploreMark) SetExplored(round int)

SetExplored sets the roundth bit.

func (*ExploreMark) SetUnexplored Uses

func (m *ExploreMark) SetUnexplored(round int)

SetUnexplored unsets the roundth bit.

type ExprIter Uses

type ExprIter struct {
    // Group and Element solely identify a Group expression.

    // Pattern describes the node of pattern tree.
    // The Operand type of the Group expression and the EngineType of the Group
    // must be matched with it.

    // Children is used to iterate the child expressions.
    Children []*ExprIter
    // contains filtered or unexported fields

ExprIter enumerates all the equivalent expressions in the Group according to the expression pattern.

func NewExprIterFromGroupElem Uses

func NewExprIterFromGroupElem(elem *list.Element, p *Pattern) *ExprIter

NewExprIterFromGroupElem creates the iterator on the Group Element.

func (*ExprIter) GetExpr Uses

func (iter *ExprIter) GetExpr() *GroupExpr

GetExpr returns the root GroupExpr of the iterator.

func (*ExprIter) Matched Uses

func (iter *ExprIter) Matched() bool

Matched returns whether the iterator founds a Group expression matches the pattern.

func (*ExprIter) Next Uses

func (iter *ExprIter) Next() (found bool)

Next returns the next Group expression matches the pattern.

func (*ExprIter) Reset Uses

func (iter *ExprIter) Reset() (findMatch bool)

Reset resets the iterator to the first matched Group expression.

type Group Uses

type Group struct {
    Equivalents *list.List

    FirstExpr    map[Operand]*list.Element
    Fingerprints map[string]*list.Element

    ImplMap map[string]Implementation
    Prop    *property.LogicalProperty

    EngineType EngineType

    SelfFingerprint string

    // ExploreMark is uses to mark whether this Group has been explored
    // by a transformation rule batch in a certain round.
    // contains filtered or unexported fields

Group is short for expression Group, which is used to store all the logically equivalent expressions. It's a set of GroupExpr.

func Convert2Group Uses

func Convert2Group(node plannercore.LogicalPlan) *Group

Convert2Group converts a logical plan to a Group.

func NewGroupWithSchema Uses

func NewGroupWithSchema(e *GroupExpr, s *expression.Schema) *Group

NewGroupWithSchema creates a new Group with given schema.

func (*Group) BuildKeyInfo Uses

func (g *Group) BuildKeyInfo()

BuildKeyInfo recursively builds UniqueKey and MaxOneRow info in the LogicalProperty.

func (*Group) Delete Uses

func (g *Group) Delete(e *GroupExpr)

Delete an existing Group expression.

func (*Group) DeleteAll Uses

func (g *Group) DeleteAll()

DeleteAll deletes all of the GroupExprs in the Group.

func (*Group) Exists Uses

func (g *Group) Exists(e *GroupExpr) bool

Exists checks whether a Group expression existed in a Group.

func (*Group) FingerPrint Uses

func (g *Group) FingerPrint() string

FingerPrint returns the unique fingerprint of the Group.

func (*Group) GetFirstElem Uses

func (g *Group) GetFirstElem(operand Operand) *list.Element

GetFirstElem returns the first Group expression which matches the Operand. Return a nil pointer if there isn't.

func (*Group) GetImpl Uses

func (g *Group) GetImpl(prop *property.PhysicalProperty) Implementation

GetImpl returns the best Implementation satisfy the physical property.

func (*Group) Insert Uses

func (g *Group) Insert(e *GroupExpr) bool

Insert a nonexistent Group expression.

func (*Group) InsertImpl Uses

func (g *Group) InsertImpl(prop *property.PhysicalProperty, impl Implementation)

InsertImpl inserts the best Implementation satisfy the physical property.

func (*Group) SetEngineType Uses

func (g *Group) SetEngineType(e EngineType) *Group

SetEngineType sets the engine type of the group.

type GroupExpr Uses

type GroupExpr struct {
    ExprNode plannercore.LogicalPlan
    Children []*Group
    Group    *Group

    // ExploreMark is uses to mark whether this GroupExpr has been fully
    // explored by a transformation rule batch in a certain round.
    // contains filtered or unexported fields

GroupExpr is used to store all the logically equivalent expressions which have the same root operator. Different from a normal expression, the Children of a Group expression are expression Groups, not expressions. Another property of Group expression is that the child Group references will never be changed once the Group expression is created.

func Convert2GroupExpr Uses

func Convert2GroupExpr(node plannercore.LogicalPlan) *GroupExpr

Convert2GroupExpr converts a logical plan to a GroupExpr.

func NewGroupExpr Uses

func NewGroupExpr(node plannercore.LogicalPlan) *GroupExpr

NewGroupExpr creates a GroupExpr based on a logical plan node.

func (*GroupExpr) AddAppliedRule Uses

func (e *GroupExpr) AddAppliedRule(rule interface{})

AddAppliedRule adds a rule into the appliedRuleSet.

func (*GroupExpr) FingerPrint Uses

func (e *GroupExpr) FingerPrint() string

FingerPrint gets the unique fingerprint of the Group expression.

func (*GroupExpr) HasAppliedRule Uses

func (e *GroupExpr) HasAppliedRule(rule interface{}) bool

HasAppliedRule returns if the rule has been applied.

func (*GroupExpr) Schema Uses

func (e *GroupExpr) Schema() *expression.Schema

Schema gets GroupExpr's Schema.

func (*GroupExpr) SetChildren Uses

func (e *GroupExpr) SetChildren(children ...*Group)

SetChildren sets Children of the GroupExpr.

type Implementation Uses

type Implementation interface {
    CalcCost(outCount float64, children ...Implementation) float64
    SetCost(cost float64)
    GetCost() float64
    GetPlan() plannercore.PhysicalPlan

    // AttachChildren is used to attach children implementations and returns it self.
    AttachChildren(children ...Implementation) Implementation

    // GetCostLimit gets the costLimit for implementing the next childGroup.
    GetCostLimit(costLimit float64, children ...Implementation) float64

Implementation defines the interface for cost of physical plan.

type Operand Uses

type Operand int

Operand is the node of a pattern tree, it represents a logical expression operator. Different from logical plan operator which holds the full information about an expression operator, Operand only stores the type information. An Operand may correspond to a concrete logical plan operator, or it can has special meaning, e.g, a placeholder for any logical plan operator.

const (
    // OperandAny is a placeholder for any Operand.
    OperandAny Operand = iota
    // OperandJoin is the operand for LogicalJoin.
    // OperandAggregation is the operand for LogicalAggregation.
    // OperandProjection is the operand for LogicalProjection.
    // OperandSelection is the operand for LogicalSelection.
    // OperandApply is the operand for LogicalApply.
    // OperandMaxOneRow is the operand for LogicalMaxOneRow.
    // OperandTableDual is the operand for LogicalTableDual.
    // OperandDataSource is the operand for DataSource.
    // OperandUnionScan is the operand for LogicalUnionScan.
    // OperandUnionAll is the operand for LogicalUnionAll.
    // OperandSort is the operand for LogicalSort.
    // OperandTopN is the operand for LogicalTopN.
    // OperandLock is the operand for LogicalLock.
    // OperandLimit is the operand for LogicalLimit.
    // OperandTiKVSingleGather is the operand for TiKVSingleGather.
    // OperandMemTableScan is the operand for MemTableScan.
    // OperandTableScan is the operand for TableScan.
    // OperandIndexScan is the operand for IndexScan.
    // OperandShow is the operand for Show.
    // OperandWindow is the operand for window function.
    // OperandUnsupported is the operand for unsupported operators.

func GetOperand Uses

func GetOperand(p plannercore.LogicalPlan) Operand

GetOperand maps logical plan operator to Operand.

func (Operand) Match Uses

func (o Operand) Match(t Operand) bool

Match checks if current Operand matches specified one.

type Pattern Uses

type Pattern struct {
    Children []*Pattern

Pattern defines the match pattern for a rule. It's a tree-like structure which is a piece of a logical expression. Each node in the Pattern tree is defined by an Operand and EngineType pair.

func BuildPattern Uses

func BuildPattern(operand Operand, engineTypeSet EngineTypeSet, children ...*Pattern) *Pattern

BuildPattern builds a Pattern from Operand, EngineType and child Patterns. Used in GetPattern() of Transformation interface to generate a Pattern.

func NewPattern Uses

func NewPattern(operand Operand, engineTypeSet EngineTypeSet) *Pattern

NewPattern creates a pattern node according to the Operand and EngineType.

func (*Pattern) Match Uses

func (p *Pattern) Match(o Operand, e EngineType) bool

Match checks whether the EngineTypeSet contains the given EngineType and whether the two Operands match.

func (*Pattern) MatchOperandAny Uses

func (p *Pattern) MatchOperandAny(e EngineType) bool

MatchOperandAny checks whether the pattern's Operand is OperandAny and the EngineTypeSet contains the given EngineType.

func (*Pattern) SetChildren Uses

func (p *Pattern) SetChildren(children ...*Pattern)

SetChildren sets the Children information for a pattern node.

Package memo imports 7 packages (graph) and is imported by 14 packages. Updated 2020-05-15. Refresh now. Tools for package owners.