rule

package
v1.1.0-beta.0...-6806af4 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 5 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) ID

func (*BaseRule) ID() uint

ID returns the basic ordinal this rule enum type.

func (*BaseRule) Match

func (*BaseRule) Match(_ base.LogicalPlan) bool

Match implements Rule interface.

func (*BaseRule) Pattern

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

Pattern implements Rule interface.

func (*BaseRule) PreCheck

func (*BaseRule) PreCheck(_ base.LogicalPlan) bool

PreCheck implements the Rule interface.

func (*BaseRule) String

func (r *BaseRule) String(writer util.StrBufferWriter)

String implements Rule interface

func (*BaseRule) XForm

func (*BaseRule) XForm(_ base.LogicalPlan) ([]base.LogicalPlan, error)

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() base.LogicalPlan

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

func (*Binder) Next

func (b *Binder) Next() base.LogicalPlan

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 Rule

type Rule interface {
	// ID return the id of this rule.
	ID() uint

	// String implements the fmt.Stringer interface, used for rule tracing process.
	String(writer util.StrBufferWriter)

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

	// PreCheck check the admission of the group expression output from binder.
	PreCheck(base.LogicalPlan) bool

	// 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(base.LogicalPlan) 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(_ base.LogicalPlan) ([]base.LogicalPlan, 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