planner

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggrType

type AggrType string

AggrType type.

const (
	// AggrTypeNull enum.
	AggrTypeNull AggrType = ""

	// AggrTypeCount enum.
	AggrTypeCount AggrType = "COUNT"

	// AggrTypeSum enum.
	AggrTypeSum AggrType = "SUM"

	// AggrTypeMin enum.
	AggrTypeMin AggrType = "MIN"

	// AggrTypeMax enum.
	AggrTypeMax AggrType = "MAX"

	// AggrTypeAvg enum.
	AggrTypeAvg AggrType = "AVG"

	// AggrTypeGroupBy enum.
	AggrTypeGroupBy AggrType = "GROUP BY"
)

type AggregatePlan

type AggregatePlan struct {

	// IsPushDown whether aggfunc can be pushed down.
	IsPushDown bool
	// contains filtered or unexported fields
}

AggregatePlan represents order-by plan.

func NewAggregatePlan

func NewAggregatePlan(log *xlog.Log, exprs []sqlparser.SelectExpr, tuples, groups []selectTuple, isPushDown bool) *AggregatePlan

NewAggregatePlan used to create AggregatePlan.

func (*AggregatePlan) Build

func (p *AggregatePlan) Build() error

Build used to build distributed querys.

func (*AggregatePlan) Children

func (p *AggregatePlan) Children() *PlanTree

Children returns the children of the plan.

func (*AggregatePlan) Empty

func (p *AggregatePlan) Empty() bool

Empty returns the aggregator number more than zero.

func (*AggregatePlan) GroupAggregators

func (p *AggregatePlan) GroupAggregators() []Aggregator

GroupAggregators returns the group aggregators.

func (*AggregatePlan) JSON

func (p *AggregatePlan) JSON() string

JSON returns the plan info.

func (*AggregatePlan) NormalAggregators

func (p *AggregatePlan) NormalAggregators() []Aggregator

NormalAggregators returns the aggregators.

func (*AggregatePlan) ReWritten

func (p *AggregatePlan) ReWritten() sqlparser.SelectExprs

ReWritten used to re-write the SelectExprs clause.

func (*AggregatePlan) Size

func (p *AggregatePlan) Size() int

Size returns the memory size.

func (*AggregatePlan) Type

func (p *AggregatePlan) Type() PlanType

Type returns the type of the plan.

type Aggregator

type Aggregator struct {
	Field    string
	Index    int
	Type     AggrType
	Distinct bool
}

Aggregator tuple.

type Comparison added in v1.0.6

type Comparison struct {
	// index in left and right node's fields.
	Left, Right int
	Operator    string
	// left expr may in right node.
	Exchange bool
}

Comparison is record the sqlparser.Comparison info.

type DDLPlan

type DDLPlan struct {

	// raw query
	RawQuery string

	// mode
	ReqMode xcontext.RequestMode

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// contains filtered or unexported fields
}

DDLPlan represents a CREATE, ALTER, DROP or RENAME plan

func NewDDLPlan

func NewDDLPlan(log *xlog.Log, database string, query string, node *sqlparser.DDL, router *router.Router) *DDLPlan

NewDDLPlan used to create DDLPlan

func (*DDLPlan) Build

func (p *DDLPlan) Build() error

Build used to build DDL distributed querys. sqlparser.DDL is a simple grammar ast, it just parses database and table name in the prefix.

func (*DDLPlan) Children

func (p *DDLPlan) Children() *PlanTree

Children returns the children of the plan.

func (*DDLPlan) JSON

func (p *DDLPlan) JSON() string

JSON returns the plan info.

func (*DDLPlan) Size

func (p *DDLPlan) Size() int

Size returns the memory size.

func (*DDLPlan) Type

func (p *DDLPlan) Type() PlanType

Type returns the type of the plan.

type DeletePlan

type DeletePlan struct {

	// raw query
	RawQuery string

	// mode
	ReqMode xcontext.RequestMode

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// contains filtered or unexported fields
}

DeletePlan represents delete plan

func NewDeletePlan

func NewDeletePlan(log *xlog.Log, database string, query string, node *sqlparser.Delete, router *router.Router) *DeletePlan

NewDeletePlan used to create DeletePlan

func (*DeletePlan) Build

func (p *DeletePlan) Build() error

Build used to build distributed querys.

func (*DeletePlan) Children

func (p *DeletePlan) Children() *PlanTree

Children returns the children of the plan.

func (*DeletePlan) JSON

func (p *DeletePlan) JSON() string

JSON returns the plan info.

func (*DeletePlan) Size

func (p *DeletePlan) Size() int

Size returns the memory size.

func (*DeletePlan) Type

func (p *DeletePlan) Type() PlanType

Type returns the type of the plan.

type Direction

type Direction string

Direction type.

const (
	// ASC enum.
	ASC Direction = "ASC"

	// DESC enum.
	DESC Direction = "DESC"
)

type InsertPlan

type InsertPlan struct {

	// raw query
	RawQuery string

	// type
	Typ PlanType

	// mode
	ReqMode xcontext.RequestMode

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// contains filtered or unexported fields
}

InsertPlan represents insertion plan

func NewInsertPlan

func NewInsertPlan(log *xlog.Log, database string, query string, node *sqlparser.Insert, router *router.Router) *InsertPlan

NewInsertPlan used to create InsertPlan

func (*InsertPlan) Build

func (p *InsertPlan) Build() error

Build used to build distributed querys.

func (*InsertPlan) Children

func (p *InsertPlan) Children() *PlanTree

Children returns the children of the plan.

func (*InsertPlan) JSON

func (p *InsertPlan) JSON() string

JSON returns the plan info.

func (*InsertPlan) Size

func (p *InsertPlan) Size() int

Size returns the memory size.

func (*InsertPlan) Type

func (p *InsertPlan) Type() PlanType

Type returns the type of the plan.

type JoinKey added in v1.0.6

type JoinKey struct {
	// field name.
	Field string
	// table name.
	Table string
	// index in the fields.
	Index int
}

JoinKey is the column info in the on conditions.

type JoinNode added in v1.0.5

type JoinNode struct {

	// Left and Right are the nodes for the join.
	Left, Right PlanNode
	// join strategy.
	Strategy JoinStrategy

	// Cols defines which columns from left or right results used to build the return result.
	// For results coming from left, the values go as -1, -2, etc. For right, they're 1, 2, etc.
	// If Cols is {-1, -2, 1, 2}, it means the returned result is {Left0, Left1, Right0, Right1}.
	Cols []int `json:",omitempty"`

	// eg: from t1 join t2 on t1.a=t2.b, 't1.a' put in LeftKeys, 't2.a' in RightKeys.
	LeftKeys, RightKeys []JoinKey
	// eg: t1 join t2 on t1.a>t2.a, 't1.a>t2.a' parser into CmpFilter.
	CmpFilter []Comparison

	// whether is left join.
	IsLeftJoin bool
	// whether the right node has filters in left join.
	HasRightFilter bool
	// record the `otherJoin.left`'s index in left.fields.
	LeftTmpCols []int
	// record the `rightNull`'s index in right.fields.
	RightTmpCols []int

	// Vars defines the list of joinVars that need to be built
	// from the Left result before invoking the Right subqquery.
	Vars map[string]int
	// contains filtered or unexported fields
}

JoinNode cannot be pushed down.

func (*JoinNode) Children added in v1.0.5

func (j *JoinNode) Children() *PlanTree

Children returns the children of the plan.

func (*JoinNode) GetQuery added in v1.0.5

func (j *JoinNode) GetQuery() []xcontext.QueryTuple

GetQuery used to get the Querys.

func (*JoinNode) Order added in v1.0.6

func (j *JoinNode) Order() int

Order satisfies the plannode interface.

type JoinStrategy added in v1.0.6

type JoinStrategy int

JoinStrategy is Join Strategy.

const (
	// Cartesian product.
	Cartesian JoinStrategy = iota
	// SortMerge Join.
	SortMerge
	// NestedLoop Join.
	NestedLoop
)

type LimitPlan

type LimitPlan struct {
	Offset int
	Limit  int
	// contains filtered or unexported fields
}

LimitPlan represents order-by plan.

func NewLimitPlan

func NewLimitPlan(log *xlog.Log, node *sqlparser.Select) *LimitPlan

NewLimitPlan used to create LimitPlan.

func (*LimitPlan) Build

func (p *LimitPlan) Build() error

Build used to build distributed querys.

func (*LimitPlan) Children

func (p *LimitPlan) Children() *PlanTree

Children returns the children of the plan.

func (*LimitPlan) JSON

func (p *LimitPlan) JSON() string

JSON returns the plan info.

func (*LimitPlan) ReWritten

func (p *LimitPlan) ReWritten() *sqlparser.Limit

ReWritten used to re-write the limit clause.

func (*LimitPlan) Size

func (p *LimitPlan) Size() int

Size returns the memory size.

func (*LimitPlan) Type

func (p *LimitPlan) Type() PlanType

Type returns the type of the plan.

type MergeNode added in v1.0.5

type MergeNode struct {

	// select ast.
	Sel *sqlparser.Select

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// querys with bind locations.
	ParsedQuerys []*sqlparser.ParsedQuery
	// contains filtered or unexported fields
}

MergeNode can be pushed down.

func (*MergeNode) Children added in v1.0.5

func (m *MergeNode) Children() *PlanTree

Children returns the children of the plan.

func (*MergeNode) GetQuery added in v1.0.5

func (m *MergeNode) GetQuery() []xcontext.QueryTuple

GetQuery used to get the Querys.

func (*MergeNode) Order added in v1.0.6

func (m *MergeNode) Order() int

Order satisfies the plannode interface.

type OrderBy

type OrderBy struct {
	Field     string
	Table     string
	Direction Direction
}

OrderBy tuple.

type OrderByPlan

type OrderByPlan struct {
	OrderBys []OrderBy `json:"OrderBy(s)"`
	// contains filtered or unexported fields
}

OrderByPlan represents order-by plan.

func NewOrderByPlan

func NewOrderByPlan(log *xlog.Log, node *sqlparser.Select, tuples []selectTuple, tbInfos map[string]*TableInfo) *OrderByPlan

NewOrderByPlan used to create OrderByPlan.

func (*OrderByPlan) Build

func (p *OrderByPlan) Build() error

Build used to build distributed querys.

func (*OrderByPlan) Children

func (p *OrderByPlan) Children() *PlanTree

Children returns the children of the plan.

func (*OrderByPlan) JSON

func (p *OrderByPlan) JSON() string

JSON returns the plan info.

func (*OrderByPlan) Size

func (p *OrderByPlan) Size() int

Size returns the memory size.

func (*OrderByPlan) Type

func (p *OrderByPlan) Type() PlanType

Type returns the type of the plan.

type OthersPlan added in v1.0.6

type OthersPlan struct {

	// raw query
	RawQuery string

	// mode
	ReqMode xcontext.RequestMode

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// contains filtered or unexported fields
}

OthersPlan -- represents a special plan.

func NewOthersPlan added in v1.0.6

func NewOthersPlan(log *xlog.Log, database string, query string, node sqlparser.Statement, router *router.Router) *OthersPlan

NewOthersPlan -- used to create OthersPlan.

func (*OthersPlan) Build added in v1.0.6

func (p *OthersPlan) Build() error

Build used to build distributed querys.

func (*OthersPlan) Children added in v1.0.6

func (p *OthersPlan) Children() *PlanTree

Children returns the children of the plan.

func (*OthersPlan) JSON added in v1.0.6

func (p *OthersPlan) JSON() string

JSON returns the plan info.

func (*OthersPlan) Size added in v1.0.6

func (p *OthersPlan) Size() int

Size returns the memory size.

func (*OthersPlan) Type added in v1.0.6

func (p *OthersPlan) Type() PlanType

Type returns the type of the plan.

type Plan

type Plan interface {
	Build() error
	Type() PlanType
	JSON() string
	Size() int
	Children() *PlanTree
}

Plan interface.

type PlanNode added in v1.0.5

type PlanNode interface {
	Children() *PlanTree

	GetQuery() []xcontext.QueryTuple

	Order() int
	// contains filtered or unexported methods
}

PlanNode interface.

type PlanTree

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

PlanTree is a container for all plans

func NewPlanTree

func NewPlanTree() *PlanTree

NewPlanTree creates the new plan tree.

func (*PlanTree) Add

func (pt *PlanTree) Add(plan Plan) error

Add used to add new plan to the tree.

func (*PlanTree) Build

func (pt *PlanTree) Build() error

Build used to build plans(we won't build sub-plans in this plan).

func (*PlanTree) Plans

func (pt *PlanTree) Plans() []Plan

Plans returns all the plans of the tree.

func (*PlanTree) Size

func (pt *PlanTree) Size() int

Size used to measure the memory usage for this plantree.

type PlanType

type PlanType string

PlanType type.

const (
	// PlanTypeDDL enum.
	PlanTypeDDL PlanType = "PlanTypeDDL"

	// PlanTypeInsert enum.
	PlanTypeInsert PlanType = "PlanTypeInsert"

	// PlanTypeDelete enum.
	PlanTypeDelete PlanType = "PlanTypeDelete"

	// PlanTypeUpdate enum.
	PlanTypeUpdate PlanType = "PlanTypeUpdate"

	// PlanTypeSelect enum.
	PlanTypeSelect PlanType = "PlanTypeSelect"

	// PlanTypeOrderby enum.
	PlanTypeOrderby PlanType = "PlanTypeOrderby"

	// PlanTypeLimit enum.
	PlanTypeLimit PlanType = "PlanTypeLimit"

	// PlanTypeAggregate enum.
	PlanTypeAggregate PlanType = "PlanTypeAggregate"

	// PlanTypeJoin enum.
	PlanTypeJoin PlanType = "PlanTypeJoin"

	// PlanTypeDistinct enum.
	PlanTypeDistinct PlanType = "PlanTypeDistinct"

	// PlanTypeOthers enum.
	PlanTypeOthers PlanType = "PlanTypeOthers"
)

type SelectPlan

type SelectPlan struct {

	// raw query
	RawQuery string

	// mode
	ReqMode xcontext.RequestMode

	Root PlanNode
	// contains filtered or unexported fields
}

SelectPlan represents select plan.

func NewSelectPlan

func NewSelectPlan(log *xlog.Log, database string, query string, node *sqlparser.Select, router *router.Router) *SelectPlan

NewSelectPlan used to create SelectPlan.

func (*SelectPlan) Build

func (p *SelectPlan) Build() error

Build used to build distributed querys. For now, we don't support subquery in select.

func (*SelectPlan) Children

func (p *SelectPlan) Children() *PlanTree

Children returns the children of the plan.

func (*SelectPlan) JSON

func (p *SelectPlan) JSON() string

JSON returns the plan info.

func (*SelectPlan) Size

func (p *SelectPlan) Size() int

Size returns the memory size.

func (*SelectPlan) Type

func (p *SelectPlan) Type() PlanType

Type returns the type of the plan.

type TableInfo added in v1.0.3

type TableInfo struct {

	// table's route.
	Segments []router.Segment `json:",omitempty"`
	// contains filtered or unexported fields
}

TableInfo represents one table information.

type UpdatePlan

type UpdatePlan struct {

	// raw query
	RawQuery string

	// mode
	ReqMode xcontext.RequestMode

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// contains filtered or unexported fields
}

UpdatePlan represents delete plan

func NewUpdatePlan

func NewUpdatePlan(log *xlog.Log, database string, query string, node *sqlparser.Update, router *router.Router) *UpdatePlan

NewUpdatePlan used to create UpdatePlan

func (*UpdatePlan) Build

func (p *UpdatePlan) Build() error

Build used to build distributed querys.

func (*UpdatePlan) Children

func (p *UpdatePlan) Children() *PlanTree

Children returns the children of the plan.

func (*UpdatePlan) JSON

func (p *UpdatePlan) JSON() string

JSON returns the plan info.

func (*UpdatePlan) Size

func (p *UpdatePlan) Size() int

Size returns the memory size.

func (*UpdatePlan) Type

func (p *UpdatePlan) Type() PlanType

Type returns the type of the plan.

Jump to

Keyboard shortcuts

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