plans

package
v0.0.0-...-7f9930a Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2015 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CrossJoin are used to combine rows from two or more tables
	CrossJoin = "CROSS"
	// LeftJoin returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.
	LeftJoin = "LEFT"
	// RightJoin returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.
	RightJoin = "RIGHT"
	// FullJoin returns all rows from the left table (table1) and from the right table (table2).
	FullJoin = "FULL"
)

Ref: http://www.w3schools.com/sql/sql_join.asp

Variables

This section is empty.

Functions

This section is empty.

Types

type DistinctDefaultPlan

type DistinctDefaultPlan struct {
	*SelectList
	Src plan.Plan
}

DistinctDefaultPlan e.g. SELECT distinct(id) FROM t;

func (*DistinctDefaultPlan) Do

Do : Distinct plan use an in-memory temp table for storing items that has same key, the value in temp table is an array of record handles.

func (*DistinctDefaultPlan) Explain

func (r *DistinctDefaultPlan) Explain(w format.Formatter)

Explain implements the plan.Plan Explain interface.

func (*DistinctDefaultPlan) Filter

Filter implements the plan.Plan Filter interface.

type ExplainDefaultPlan

type ExplainDefaultPlan struct {
	S stmt.Statement
}

ExplainDefaultPlan executes the explain statement, and provides debug infomations.

func (*ExplainDefaultPlan) Do

Do returns explain result lines.

func (*ExplainDefaultPlan) Explain

func (r *ExplainDefaultPlan) Explain(w format.Formatter)

Explain implements the plan.Plan Explain interface.

func (*ExplainDefaultPlan) Filter

Filter implements the plan.Plan Filter interface.

func (*ExplainDefaultPlan) GetFields

func (r *ExplainDefaultPlan) GetFields() []*field.ResultField

GetFields implements the plan.Plan GetFields interface.

type FilterDefaultPlan

type FilterDefaultPlan struct {
	plan.Plan
	Expr expression.Expression
}

FilterDefaultPlan handles WHERE statement, filters rows by specific expressions.

func (*FilterDefaultPlan) Do

func (r *FilterDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)

Do implements plan.Plan Do interface.

func (*FilterDefaultPlan) Explain

func (r *FilterDefaultPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

type GroupByDefaultPlan

type GroupByDefaultPlan struct {
	*SelectList
	Src plan.Plan
	By  []expression.Expression
}

GroupByDefaultPlan handles GROUP BY statement, GroupByDefaultPlan uses an in-memory table to aggregate values.

func (*GroupByDefaultPlan) Do

Do implements plan.Plan Do interface. Table: Subject_Selection Subject Semester Attendee --------------------------------- ITB001 1 John ITB001 1 Bob ITB001 1 Mickey ITB001 2 Jenny ITB001 2 James MKB114 1 John MKB114 1 Erica refs: http://stackoverflow.com/questions/2421388/using-group-by-on-multiple-columns

func (*GroupByDefaultPlan) Explain

func (r *GroupByDefaultPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*GroupByDefaultPlan) Filter

Filter implements plan.Plan Filter interface.

type HavingPlan

type HavingPlan struct {
	Src  plan.Plan
	Expr expression.Expression
}

HavingPlan executes the HAVING statement, HavingPlan's behavior is almost the same as FilterDefaultPlan.

func (*HavingPlan) Do

func (r *HavingPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)

Do implements plan.Plan Do interface. It scans rows over SrcPlan and check if it meets all conditions in Expr.

func (*HavingPlan) Explain

func (r *HavingPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*HavingPlan) Filter

func (r *HavingPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

Filter implements plan.Plan Filter interface.

func (*HavingPlan) GetFields

func (r *HavingPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type InfoSchemaPlan

type InfoSchemaPlan struct {
	TableName string
}

InfoSchemaPlan handles information_schema query, simulates the behavior of MySQL.

func NewInfoSchemaPlan

func NewInfoSchemaPlan(tableName string) (isp *InfoSchemaPlan, err error)

NewInfoSchemaPlan returns new InfoSchemaPlan instance, and checks if the given table name is valid.

func (*InfoSchemaPlan) Do

func (isp *InfoSchemaPlan) Do(ctx context.Context, iterFunc plan.RowIterFunc) error

Do implements plan.Plan Do interface, constructs result data.

func (*InfoSchemaPlan) Explain

func (isp *InfoSchemaPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*InfoSchemaPlan) Filter

func (isp *InfoSchemaPlan) Filter(ctx context.Context, expr expression.Expression) (p plan.Plan, filtered bool, err error)

Filter implements plan.Plan Filter interface.

func (*InfoSchemaPlan) GetFields

func (isp *InfoSchemaPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface, simulates MySQL's output.

type JoinPlan

type JoinPlan struct {
	Left  plan.Plan
	Right plan.Plan

	Type string

	Fields []*field.ResultField
	On     expression.Expression
}

JoinPlan handles JOIN query. The whole join plan is a tree e.g, from (t1 left join t2 on t1.c1 = t2.c2), (t3 right join t4 on t3.c1 = t4.c1) the executing order maylook:

     Table Result
          |
    -------------
   |             |
t1 x t2       t3 x t4

TODO: add Parent field, optimize join plan

func (*JoinPlan) Do

func (r *JoinPlan) Do(ctx context.Context, f plan.RowIterFunc) error

Do implements plan.Plan Do interface, it executes join method accourding to given type.

func (*JoinPlan) Explain

func (r *JoinPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*JoinPlan) Filter

func (r *JoinPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

Filter implements plan.Plan Filter interface, it returns one of the two plans' Filter result, maybe we could do some optimizations here.

func (*JoinPlan) GetFields

func (r *JoinPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type LimitDefaultPlan

type LimitDefaultPlan struct {
	Count  uint64
	Src    plan.Plan
	Fields []*field.ResultField
}

LimitDefaultPlan handles queries like SELECT .. FROM ... LIMIT N, returns at most N results.

func (*LimitDefaultPlan) Do

func (r *LimitDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)

Do implements plan.Plan Do interface, counts the number of results, if the number > N, returns.

func (*LimitDefaultPlan) Explain

func (r *LimitDefaultPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*LimitDefaultPlan) Filter

Filter implements plan.Plan Filter interface.

func (*LimitDefaultPlan) GetFields

func (r *LimitDefaultPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type NullPlan

type NullPlan struct {
	Fields []*field.ResultField
}

NullPlan is empty plan, if we can affirm that the resultset is empty, we could just return a NullPlan directly, no need to scan any table. e.g. SELECT * FROM t WHERE i > 0 and i < 0;

func (*NullPlan) Do

Do implements plan.Plan Do interface. Do nothing.

func (*NullPlan) Explain

func (r *NullPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*NullPlan) Filter

func (r *NullPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

Filter implements plan.Plan Filter interface.

func (*NullPlan) GetFields

func (r *NullPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type OffsetDefaultPlan

type OffsetDefaultPlan struct {
	Count  uint64
	Src    plan.Plan
	Fields []*field.ResultField
}

OffsetDefaultPlan handles SELECT ... FROM ... OFFSET N, skips N records.

func (*OffsetDefaultPlan) Do

Do implements plan.Plan Do interface, skips N records.

func (*OffsetDefaultPlan) Explain

func (r *OffsetDefaultPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*OffsetDefaultPlan) Filter

Filter implements plan.Plan Filter interface.

func (*OffsetDefaultPlan) GetFields

func (r *OffsetDefaultPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type OrderByDefaultPlan

type OrderByDefaultPlan struct {
	*SelectList
	By   []expression.Expression
	Ascs []bool
	Src  plan.Plan
}

OrderByDefaultPlan handles ORDER BY statement, it uses an array to store results temporarily, and sorts them by given expression.

func (*OrderByDefaultPlan) Do

Do implements plan.Plan Do interface, all records are added into an in-memory array, and sorted in ASC/DESC order.

func (*OrderByDefaultPlan) Explain

func (r *OrderByDefaultPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*OrderByDefaultPlan) Filter

Filter implements plan.Plan Filter interface.

type RowKeyEntry

type RowKeyEntry struct {
	// The table which this row come from
	Tbl table.Table
	// Row handle
	Key string
}

RowKeyEntry is designed for Delete statement in multi-table mode, we should know which table this row comes from

type RowKeyList

type RowKeyList struct {
	Keys []*RowKeyEntry
}

RowKeyList is list of RowKeyEntry

type SelectEmptyFieldListPlan

type SelectEmptyFieldListPlan struct {
	Fields []*field.Field
}

SelectEmptyFieldListPlan is the plan for "select expr, expr, ..."" with no FROM.

func (*SelectEmptyFieldListPlan) Do

Do implements the plan.Plan Do interface, returns empty row.

func (*SelectEmptyFieldListPlan) Explain

Explain implements the plan.Plan Explain interface.

func (*SelectEmptyFieldListPlan) Filter

Filter implements the plan.Plan Filter interface.

func (*SelectEmptyFieldListPlan) GetFields

func (s *SelectEmptyFieldListPlan) GetFields() []*field.ResultField

GetFields implements the plan.Plan GetFields interface.

type SelectFieldsDefaultPlan

type SelectFieldsDefaultPlan struct {
	*SelectList
	Src plan.Plan
}

SelectFieldsDefaultPlan extracts specific fields from Src Plan.

func (*SelectFieldsDefaultPlan) Do

Do implements the plan.Plan Do interface, extracts specific values by r.Fields from row data.

func (*SelectFieldsDefaultPlan) Explain

Explain implements the plan.Plan Explain interface.

func (*SelectFieldsDefaultPlan) Filter

Filter implements the plan.Plan Filter interface.

type SelectFinalPlan

type SelectFinalPlan struct {
	*SelectList

	Src plan.Plan
	// contains filtered or unexported fields
}

SelectFinalPlan sets info field for resuilt.

func (*SelectFinalPlan) Do

Do implements the plan.Plan Do interface, and sets result info field.

func (*SelectFinalPlan) Explain

func (r *SelectFinalPlan) Explain(w format.Formatter)

Explain implements the plan.Plan Explain interface.

func (*SelectFinalPlan) Filter

func (r *SelectFinalPlan) Filter(ctx context.Context, expr expression.Expression) (p plan.Plan, filtered bool, err error)

Filter implements the plan.Plan Filter interface.

func (*SelectFinalPlan) GetFields

func (r *SelectFinalPlan) GetFields() []*field.ResultField

GetFields implements the plan.Plan GetFields interface.

type SelectList

type SelectList struct {
	Fields       []*field.Field
	ResultFields []*field.ResultField
	AggFields    map[int]struct{}

	// HiddenFieldOffset distinguishes select field list and hidden fields for internal use.
	// We will use this to get select filed list and calculate distinct key.
	HiddenFieldOffset int
}

SelectList contains real select list defined in select statement which will be output to client and hidden list which will just be used internally for order by, having clause, etc, why? After we do where phase in select, the left flow are group by -> having -> select fields -> order by -> limit -> final. for MySQL, order by may use values not in select fields, e.g select c1 from t order by c2, to support this, we should add extra fields in select list, and we will use HiddenOffset to control these fields not to be output.

func ResolveSelectList

func ResolveSelectList(selectFields []*field.Field, srcFields []*field.ResultField) (*SelectList, error)

ResolveSelectList gets fields and result fields from selectFields and srcFields, including field validity check and wildcard field processing.

func (*SelectList) AddField

func (s *SelectList) AddField(f *field.Field, result *field.ResultField)

AddField adds Field and ResultField objects to SelectList, and if result is nil, constructs a new ResultField.

func (*SelectList) CloneHiddenField

func (s *SelectList) CloneHiddenField(name string, tableFields []*field.ResultField) bool

CloneHiddenField checks and clones field and result field from table fields, and adds them to hidden field of select list.

func (*SelectList) GetFields

func (s *SelectList) GetFields() []*field.ResultField

GetFields returns ResultField.

func (*SelectList) UpdateAggFields

func (s *SelectList) UpdateAggFields(expr expression.Expression, tableFields []*field.ResultField) (expression.Expression, error)

UpdateAggFields adds aggregate function resultfield to select result field list.

type SelectLockPlan

type SelectLockPlan struct {
	Src  plan.Plan
	Lock coldef.LockType
}

SelectLockPlan handles SELECT ... FOR UPDATE, recording selected rows for acquiring locks explicitly.

func (*SelectLockPlan) Do

Do implements plan.Plan Do interface, acquiring locks.

func (*SelectLockPlan) Explain

func (r *SelectLockPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*SelectLockPlan) Filter

Filter implements plan.Plan Filter interface.

func (*SelectLockPlan) GetFields

func (r *SelectLockPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type ShowPlan

type ShowPlan struct {
	Target     int
	DBName     string
	TableName  string
	ColumnName string
	Flag       int
	Full       bool
}

ShowPlan is used for show statements

func (*ShowPlan) Do

func (s *ShowPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)

Do implements plan.Plan Do interface.

func (*ShowPlan) Explain

func (s *ShowPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*ShowPlan) Filter

func (s *ShowPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

Filter implements plan.Plan Filter interface.

func (*ShowPlan) GetFields

func (s *ShowPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

type TableDefaultPlan

type TableDefaultPlan struct {
	T      table.Table
	Fields []*field.ResultField
}

TableDefaultPlan iterates rows from a table, in general case it performs a full table scan, but using Filter function, it will return a new IndexPlan if an index is found in Filter function.

func (*TableDefaultPlan) Do

Do scans over rows' kv pair in the table, and constructs them into row data.

func (*TableDefaultPlan) Explain

func (r *TableDefaultPlan) Explain(w format.Formatter)

Explain implements the plan.Plan Explain interface.

func (*TableDefaultPlan) Filter

Filter implements plan.Plan Filter interface.

func (*TableDefaultPlan) FilterForUpdateAndDelete

func (r *TableDefaultPlan) FilterForUpdateAndDelete(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

FilterForUpdateAndDelete is for updating and deleting (without checking return columns), in order to check whether if we can use IndexPlan or not.

func (*TableDefaultPlan) GetFields

func (r *TableDefaultPlan) GetFields() []*field.ResultField

GetFields implements the plan.Plan GetFields interface.

type TableNilPlan

type TableNilPlan struct {
	T table.Table
}

TableNilPlan iterates rows but does nothing, e.g. SELECT 1 FROM t;

func (*TableNilPlan) Do

Do implements the plan.Plan interface, iterates rows but does nothing.

func (*TableNilPlan) Explain

func (r *TableNilPlan) Explain(w format.Formatter)

Explain implements the plan.Plan interface.

func (*TableNilPlan) Filter

func (r *TableNilPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

Filter implements the plan.Plan Filter interface.

func (*TableNilPlan) GetFields

func (r *TableNilPlan) GetFields() []*field.ResultField

GetFields implements the plan.Plan interface.

type UnionPlan

type UnionPlan struct {
	Srcs      []plan.Plan
	Distincts []bool
	RFields   []*field.ResultField
}

UnionPlan handles UNION query, merges results from different plans.

func (*UnionPlan) Do

Do implements plan.Plan Do interface. In union plan, we should evaluate each selects from left to right, and union them according to distinct option Use the first select ResultFields as the final ResultFields but we should adjust its Flen for the rest Select ResultFields.

func (*UnionPlan) Explain

func (p *UnionPlan) Explain(w format.Formatter)

Explain implements plan.Plan Explain interface.

func (*UnionPlan) Filter

func (p *UnionPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)

Filter implements plan.Plan Filter interface.

func (*UnionPlan) GetFields

func (p *UnionPlan) GetFields() []*field.ResultField

GetFields implements plan.Plan GetFields interface.

Jump to

Keyboard shortcuts

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