builder

package
Version: v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProject

func GetProject(root PlanNode) string

GetProject return the project which is used in explain.

func LookupFromWhere added in v1.1.4

func LookupFromWhere(database, table, shardkey string, where *sqlparser.Where, router *router.Router) ([]router.Segment, error)

LookupFromWhere used to get the routing from the where clause.

Types

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) 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) Type

func (p *AggregatePlan) Type() ChildType

Type returns the type of the plan.

type Aggregator

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

Aggregator tuple.

type ChildPlan

type ChildPlan interface {
	Build() error
	Type() ChildType
	JSON() string
}

ChildPlan interface.

type ChildType

type ChildType string

ChildType type.

const (
	// ChildTypeOrderby enum.
	ChildTypeOrderby ChildType = "ChildTypeOrderby"

	// ChildTypeLimit enum.
	ChildTypeLimit ChildType = "ChildTypeLimit"

	// ChildTypeAggregate enum.
	ChildTypeAggregate ChildType = "ChildTypeAggregate"
)

type Comparison

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 Direction

type Direction string

Direction type.

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

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

type JoinKey

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

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' parse into CmpFilter.
	CmpFilter []Comparison

	// whether is left join.
	IsLeftJoin bool
	// whether the right node has filters in left join.
	HasRightFilter bool
	// record the `otherLeftJoin.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

func (j *JoinNode) Children() []ChildPlan

Children returns the children of the plan.

func (*JoinNode) GetQuery

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

GetQuery used to get the Querys.

func (*JoinNode) Order

func (j *JoinNode) Order() int

Order satisfies the plannode interface.

type JoinStrategy

type JoinStrategy int

JoinStrategy is Join Strategy.

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

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.Limit) *LimitPlan

NewLimitPlan used to create LimitPlan.

func (*LimitPlan) Build

func (p *LimitPlan) Build() error

Build used to build distributed querys.

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) Type

func (p *LimitPlan) Type() ChildType

Type returns the type of the plan.

type MergeNode

type MergeNode struct {

	// select ast.
	Sel sqlparser.SelectStatement

	// query and backend tuple
	Querys []xcontext.QueryTuple
	// querys with bind locations.
	ParsedQuerys []*sqlparser.ParsedQuery

	// Mode.
	ReqMode xcontext.RequestMode
	// contains filtered or unexported fields
}

MergeNode can be pushed down.

func (*MergeNode) Children

func (m *MergeNode) Children() []ChildPlan

Children returns the children of the plan.

func (*MergeNode) GenerateFieldQuery

func (m *MergeNode) GenerateFieldQuery() *sqlparser.ParsedQuery

GenerateFieldQuery generates a query with an impossible where. This will be used on the RHS node to fetch field info if the LHS returns no result.

func (*MergeNode) GetQuery

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

GetQuery used to get the Querys.

func (*MergeNode) Order

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 {

	// The indexes mark the fields to be removed.
	RemovedIdxs []int
	OrderBys    []OrderBy `json:"OrderBy(s)"`
	// contains filtered or unexported fields
}

OrderByPlan represents order-by plan.

func NewOrderByPlan

func NewOrderByPlan(log *xlog.Log, node sqlparser.OrderBy, root PlanNode) *OrderByPlan

NewOrderByPlan used to create OrderByPlan.

func (*OrderByPlan) Build

func (p *OrderByPlan) Build() error

Build used to build distributed querys.

func (*OrderByPlan) JSON

func (p *OrderByPlan) JSON() string

JSON returns the plan info.

func (*OrderByPlan) Type

func (p *OrderByPlan) Type() ChildType

Type returns the type of the plan.

type PlanNode

type PlanNode interface {
	Children() []ChildPlan

	GetQuery() []xcontext.QueryTuple

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

PlanNode interface.

func BuildNode

func BuildNode(log *xlog.Log, router *router.Router, database string, node sqlparser.SelectStatement) (PlanNode, error)

BuildNode used to build the plannode tree.

type UnionNode

type UnionNode struct {
	Left, Right PlanNode
	// Union Type.
	Typ string
	// contains filtered or unexported fields
}

UnionNode ... eg: select a, b from t1 union select t2.a,t3.b from t2 join t3 on t2.id=t3.id;

     PlanNode1
       /  \
      /    \
PlanNode2  PlanNode3

PlanNode1: UnionNode PlanNode2: MergeNode PlanNode3: JoinNode

       /  \
      /    \
MergeNode  MergeNode

PlanNode2 and PlanNode3 are two independent trees, and they are also the Left and Right of PlanNode1.

func (*UnionNode) Children

func (u *UnionNode) Children() []ChildPlan

Children returns the children of the plan.

func (*UnionNode) GetQuery

func (u *UnionNode) GetQuery() []xcontext.QueryTuple

GetQuery used to get the Querys.

func (*UnionNode) Order

func (u *UnionNode) Order() int

Order unreachable.

Jump to

Keyboard shortcuts

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