rule

package
v1.1.0-beta.0...-d13e52e Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultNone indicates this is none rule.
	DefaultNone ruleType = iota
	// XFJoinToApply refers to join to a apply rule.
	XFJoinToApply
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRule

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

BaseRule is the abstract parent class of rule.

func NewBaseRule

func NewBaseRule(tp ruleType, pattern *pattern.Pattern) *BaseRule

NewBaseRule creates a new BaseRule.

func (*BaseRule) Match

Match implements Rule interface.

func (*BaseRule) Pattern

func (r *BaseRule) Pattern() *pattern.Pattern

Pattern implements Rule interface.

func (*BaseRule) String

func (r *BaseRule) String() string

String implements Rule interface

func (*BaseRule) XForm

XForm implements Rule interface.

type Binder

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

Binder is leveled status structure used to bind the logical subtree with special given pattern.

func NewBinder

func NewBinder(p *pattern.Pattern, gE *memo.GroupExpression) *Binder

NewBinder creates a new Binder.

func (*Binder) GetHolder

func (b *Binder) GetHolder() *GroupExprHolder

GetHolder returns the current group expression stored in dynamic placeholder element field.

func (*Binder) Next

func (b *Binder) Next() bool

Next tries to find the next matched group expression from the Binder structure. Binder core logic is trying to iterate a matched **Next** concrete logical plan from group tree. It will try to match the child pattern with the child group if any, get the matched child group expression and return it back to upper caller to form a valid logical plan(across pattern up and down).

Like:

     Join
    /    \
	 G1(e1)  G2(e1,e2,e3)

Pattern z: Join{ANY1, ANY2}

When matching a Join pattern z above, current groupExpression's children is Group structure, when we want to apply join commutative rule, actually we don't care about what the concrete expression inside the group, so for this rule, we don't need to iterate concrete expression inside the G1, G2 group. just adding a new join expression with G2 and G1 as children is enough.

Like:

     Join
    /    \
	 G1(e1)  G2(e1,e2,e3)
                / \ (check e?: should be a join operator)
               /   \
		       G3(e5) G4(e6)

Pattern z: Join{ANY1, Join{ANY2, ANY3}}

But for some other rules, like join associativity, we need to iterate the concrete expression inside the G2 group to make sure e? should be a Join operator to match the rule requirement, that's means to need to pinned G1, then iterate G2's equivalent expression to find the matched Join(e2) like we say, next we got a concrete expression: Join(G1, Join(G3, G4)), then we can apply the join associativity rule to transform the expression to Join(Join(G1, G3), G4) or other forms.

type GroupExprHolder

type GroupExprHolder struct {
	Cur  *memo.GroupExpression
	Subs []*GroupExprHolder
}

GroupExprHolder is dynamic placeholder for *list.element subtree holding which comes from binder process.

type Rule

type Rule interface {
	// String implements the fmt.Stringer interface, used for rule tracing process.
	String() string

	// Pattern return the initialized pattern of a specific rule when it created.
	Pattern() *pattern.Pattern

	// Match checks whether the GroupExpr satisfies all the requirements of the specific 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(holder *GroupExprHolder, sctx sessionctx.Context) bool

	// XForm does the real work of the optimization rule. The returned group expressions list
	// indicates the new GroupExprs generated by the transformation rule.
	XForm(holder *GroupExprHolder, sctx sessionctx.Context) ([]*memo.GroupExpression, error)
}

Rule regular the common rule interface for the memo optimization.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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