planner

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Optimize

func Optimize(s *stream.Stream, tx *database.Transaction, params []expr.Param) (*stream.Stream, error)

Optimize takes a tree, applies a list of optimization rules and returns an optimized tree. Depending on the rule, the tree may be modified in place or replaced by a new one.

func PrecalculateExprRule

func PrecalculateExprRule(s *stream.Stream, _ *database.Transaction, params []expr.Param) (*stream.Stream, error)

PrecalculateExprRule evaluates any constant sub-expression that can be evaluated before running the query and replaces it by the result of the evaluation. The result of constant sub-expressions, like "3 + 4", is always the same and thus can be precalculated. Examples:

3 + 4 --> 7
3 + 1 > 10 - a --> 4 > 10 - a

func RemoveUnnecessaryDistinctNodeRule

func RemoveUnnecessaryDistinctNodeRule(s *stream.Stream, tx *database.Transaction, _ []expr.Param) (*stream.Stream, error)

RemoveUnnecessaryDistinctNodeRule removes any Dedup nodes where projection is already unique.

func RemoveUnnecessaryFilterNodesRule

func RemoveUnnecessaryFilterNodesRule(s *stream.Stream, _ *database.Transaction, _ []expr.Param) (*stream.Stream, error)

RemoveUnnecessaryFilterNodesRule removes any filter node whose condition is a constant expression that evaluates to a truthy value. if it evaluates to a falsy value, it considers that the tree will not stream any document, so it returns an empty tree.

func RemoveUnnecessaryProjection

func RemoveUnnecessaryProjection(s *stream.Stream, _ *database.Transaction, _ []expr.Param) (*stream.Stream, error)

RemoveUnnecessaryProjection removes any project node whose expression is a wildcard only.

func SplitANDConditionRule

func SplitANDConditionRule(s *stream.Stream, _ *database.Transaction, _ []expr.Param) (*stream.Stream, error)

SplitANDConditionRule splits any filter node whose condition is one or more AND operators into one or more filter nodes. The condition won't be split if the expression tree contains an OR operation. Example:

this:
  filter(a > 2 AND b != 3 AND c < 2)
becomes this:
  filter(a > 2)
  filter(b != 3)
  filter(c < 2)

func UseIndexBasedOnFilterNodeRule

func UseIndexBasedOnFilterNodeRule(s *stream.Stream, tx *database.Transaction, params []expr.Param) (*stream.Stream, error)

UseIndexBasedOnFilterNodeRule scans the tree for filter nodes whose conditions are operators that satisfies the following criterias: - is a comparison operator - one of its operands is a path expression that is indexed - the other operand is a literal value or a parameter

If one or many are found, it will replace the input node by an indexInputNode using this index, removing the now irrelevant filter nodes.

TODO(asdine): add support for ORDER BY TODO(jh): clarify cost code in composite indexes case

Types

type ExplainStmt

type ExplainStmt struct {
	Statement query.Statement
}

ExplainStmt is a query.Statement that displays information about how a statement is going to be executed, without executing it.

func (*ExplainStmt) IsReadOnly

func (s *ExplainStmt) IsReadOnly() bool

IsReadOnly indicates that this statement doesn't write anything into the database.

func (*ExplainStmt) Run

func (s *ExplainStmt) Run(tx *database.Transaction, params []expr.Param) (query.Result, error)

Run analyses the inner statement and displays its execution plan. If the statement is a stream, Optimize will be called prior to displaying all the operations. Explain currently only works on SELECT, UPDATE, INSERT and DELETE statements.

type Statement

type Statement struct {
	Stream   *stream.Stream
	ReadOnly bool
}

Statement is a query.Statement using a Stream.

func (*Statement) IsReadOnly

func (s *Statement) IsReadOnly() bool

IsReadOnly reports whether the stream will modify the database or only read it.

func (*Statement) Run

func (s *Statement) Run(tx *database.Transaction, params []expr.Param) (query.Result, error)

Run returns a result containing the stream. The stream will be executed by calling the Iterate method of the result.

func (*Statement) String

func (s *Statement) String() string

Jump to

Keyboard shortcuts

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