optimize

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRuleFound     = errors.New("optimize: no rule found")
	ErrDenyFullScan    = errors.New("optimize: the full-scan query is not allowed")
	ErrNoShardKeyFound = errors.New("optimize: no shard key found")
)

errors group

View Source
var Tracer = otel.Tracer("optimize")

Functions

func Hints

func Hints(tableName ast.TableName, hints []*hint.Hint, rule *rule.Rule) (hintTables rule.DatabaseTables, err error)

func IsDenyFullScanErr

func IsDenyFullScanErr(err error) bool

IsDenyFullScanErr returns true if target error is caused by DENY-FULL-SCAN.

func IsNoRuleFoundErr

func IsNoRuleFoundErr(err error) bool

IsNoRuleFoundErr returns true if target error is caused by NO-RULE-FOUND.

func IsNoShardKeyFoundErr

func IsNoShardKeyFoundErr(err error) bool

IsNoShardKeyFoundErr returns true if target error is caused by NO-SHARD-KEY-FOUND

func NewOptimizer

func NewOptimizer(rule *rule.Rule, hints []*hint.Hint, stmt ast.StmtNode, args []proto.Value) (proto.Optimizer, error)

func Register

func Register(t rast.SQLType, h Processor)

func RegisterHint

func RegisterHint(t hint.Type, h HintExecutor)

RegisterHint register hint implementation.

Types

type Calculus

type Calculus = logic.Logic[*calc.Calculus]

type CustomRoute

type CustomRoute struct{}

type Direct

type Direct struct{}

Direct force forward to db[0]

type HintExecutor

type HintExecutor interface {
	// contains filtered or unexported methods
}

type Optimizer

type Optimizer struct {
	Rule  *rule.Rule
	Hints []*hint.Hint
	Stmt  rast.Statement
	Args  []proto.Value
}

func (*Optimizer) ComputeShards

func (o *Optimizer) ComputeShards(ctx context.Context, table rast.TableName, where rast.ExpressionNode, args []proto.Value) (rule.DatabaseTables, error)

func (*Optimizer) Optimize

func (o *Optimizer) Optimize(ctx context.Context) (plan proto.Plan, err error)

type Processor

type Processor = func(ctx context.Context, o *Optimizer) (proto.Plan, error)

type ShardVisitor

type ShardVisitor struct {
	ast.BaseVisitor
	// contains filtered or unexported fields
}

func NewXSharder

func NewXSharder(ctx context.Context, ru *rule.Rule, args []proto.Value) *ShardVisitor

func (*ShardVisitor) ForSingleSelect

func (sd *ShardVisitor) ForSingleSelect(table ast.TableName, alias string, where ast.ExpressionNode) error

func (*ShardVisitor) Result

func (sd *ShardVisitor) Result() []misc.Pair[ast.TableName, *rule.Shards]

func (*ShardVisitor) SimpleShard

func (sd *ShardVisitor) SimpleShard(table ast.TableName, where ast.ExpressionNode) (rule.DatabaseTables, error)

func (*ShardVisitor) VisitAtomColumn

func (sd *ShardVisitor) VisitAtomColumn(_ ast.ColumnNameExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomConstant

func (sd *ShardVisitor) VisitAtomConstant(node *ast.ConstantExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomFunction

func (sd *ShardVisitor) VisitAtomFunction(node *ast.FunctionCallExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomInterval

func (sd *ShardVisitor) VisitAtomInterval(_ *ast.IntervalExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomMath

func (sd *ShardVisitor) VisitAtomMath(node *ast.MathExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomNested

func (sd *ShardVisitor) VisitAtomNested(node *ast.NestedExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomSystemVariable

func (sd *ShardVisitor) VisitAtomSystemVariable(_ *ast.SystemVariableExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomUnary

func (sd *ShardVisitor) VisitAtomUnary(node *ast.UnaryExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitAtomVariable

func (sd *ShardVisitor) VisitAtomVariable(node ast.VariableExpressionAtom) (interface{}, error)

func (*ShardVisitor) VisitLogicalExpression

func (sd *ShardVisitor) VisitLogicalExpression(node *ast.LogicalExpressionNode) (interface{}, error)

func (*ShardVisitor) VisitNotExpression

func (sd *ShardVisitor) VisitNotExpression(node *ast.NotExpressionNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateAtom

func (sd *ShardVisitor) VisitPredicateAtom(node *ast.AtomPredicateNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateBetween

func (sd *ShardVisitor) VisitPredicateBetween(node *ast.BetweenPredicateNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateBinaryComparison

func (sd *ShardVisitor) VisitPredicateBinaryComparison(node *ast.BinaryComparisonPredicateNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateExpression

func (sd *ShardVisitor) VisitPredicateExpression(node *ast.PredicateExpressionNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateIn

func (sd *ShardVisitor) VisitPredicateIn(node *ast.InPredicateNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateLike

func (sd *ShardVisitor) VisitPredicateLike(node *ast.LikePredicateNode) (interface{}, error)

func (*ShardVisitor) VisitPredicateRegexp

func (sd *ShardVisitor) VisitPredicateRegexp(_ *ast.RegexpPredicationNode) (interface{}, error)

func (*ShardVisitor) VisitSelectElementExpr

func (sd *ShardVisitor) VisitSelectElementExpr(node *ast.SelectElementExpr) (interface{}, error)

func (*ShardVisitor) VisitSelectStatement

func (sd *ShardVisitor) VisitSelectStatement(node *ast.SelectStatement) (interface{}, error)

Directories

Path Synopsis
dml
ext

Jump to

Keyboard shortcuts

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