Documentation ¶
Index ¶
- Constants
- type DistinctDefaultPlan
- type ExplainDefaultPlan
- func (r *ExplainDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
- func (r *ExplainDefaultPlan) Explain(w format.Formatter)
- func (r *ExplainDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
- func (r *ExplainDefaultPlan) GetFields() []*field.ResultField
- type FilterDefaultPlan
- type GroupByDefaultPlan
- type HavingPlan
- type InfoSchemaPlan
- func (isp *InfoSchemaPlan) Do(ctx context.Context, iterFunc plan.RowIterFunc) error
- func (isp *InfoSchemaPlan) Explain(w format.Formatter)
- func (isp *InfoSchemaPlan) Filter(ctx context.Context, expr expression.Expression) (p plan.Plan, filtered bool, err error)
- func (isp *InfoSchemaPlan) GetFields() []*field.ResultField
- type JoinPlan
- type LimitDefaultPlan
- func (r *LimitDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)
- func (r *LimitDefaultPlan) Explain(w format.Formatter)
- func (r *LimitDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
- func (r *LimitDefaultPlan) GetFields() []*field.ResultField
- type NullPlan
- type OffsetDefaultPlan
- func (r *OffsetDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
- func (r *OffsetDefaultPlan) Explain(w format.Formatter)
- func (r *OffsetDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
- func (r *OffsetDefaultPlan) GetFields() []*field.ResultField
- type OrderByDefaultPlan
- type RowKeyEntry
- type RowKeyList
- type SelectEmptyFieldListPlan
- func (s *SelectEmptyFieldListPlan) Do(ctx context.Context, f plan.RowIterFunc) error
- func (s *SelectEmptyFieldListPlan) Explain(w format.Formatter)
- func (s *SelectEmptyFieldListPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
- func (s *SelectEmptyFieldListPlan) GetFields() []*field.ResultField
- type SelectFieldsDefaultPlan
- type SelectFinalPlan
- func (r *SelectFinalPlan) Do(ctx context.Context, f plan.RowIterFunc) error
- func (r *SelectFinalPlan) Explain(w format.Formatter)
- func (r *SelectFinalPlan) Filter(ctx context.Context, expr expression.Expression) (p plan.Plan, filtered bool, err error)
- func (r *SelectFinalPlan) GetFields() []*field.ResultField
- type SelectList
- func (s *SelectList) AddField(f *field.Field, result *field.ResultField)
- func (s *SelectList) CloneHiddenField(name string, tableFields []*field.ResultField) bool
- func (s *SelectList) GetFields() []*field.ResultField
- func (s *SelectList) UpdateAggFields(expr expression.Expression, tableFields []*field.ResultField) (expression.Expression, error)
- type SelectLockPlan
- type ShowPlan
- type TableDefaultPlan
- func (r *TableDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
- func (r *TableDefaultPlan) Explain(w format.Formatter)
- func (r *TableDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
- func (r *TableDefaultPlan) FilterForUpdateAndDelete(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
- func (r *TableDefaultPlan) GetFields() []*field.ResultField
- type TableNilPlan
- type UnionPlan
Constants ¶
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" )
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 ¶
func (r *DistinctDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)
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 ¶
func (r *DistinctDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
Filter implements the plan.Plan Filter interface.
type ExplainDefaultPlan ¶
ExplainDefaultPlan executes the explain statement, and provides debug infomations.
func (*ExplainDefaultPlan) Do ¶
func (r *ExplainDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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 ¶
func (r *ExplainDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 ¶
func (r *GroupByDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) (err error)
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 ¶
func (r *GroupByDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 ¶
Do implements plan.Plan Do interface, it executes join method accourding to given type.
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 ¶
func (r *LimitDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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) 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 ¶
func (r *OffsetDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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 ¶
func (r *OffsetDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 ¶
func (r *OrderByDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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 ¶
func (r *OrderByDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 SelectEmptyFieldListPlan ¶
SelectEmptyFieldListPlan is the plan for "select expr, expr, ..."" with no FROM.
func (*SelectEmptyFieldListPlan) Do ¶
func (s *SelectEmptyFieldListPlan) Do(ctx context.Context, f plan.RowIterFunc) error
Do implements the plan.Plan Do interface, returns empty row.
func (*SelectEmptyFieldListPlan) Explain ¶
func (s *SelectEmptyFieldListPlan) Explain(w format.Formatter)
Explain implements the plan.Plan Explain interface.
func (*SelectEmptyFieldListPlan) Filter ¶
func (s *SelectEmptyFieldListPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 ¶
func (r *SelectFieldsDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
Do implements the plan.Plan Do interface, extracts specific values by r.Fields from row data.
func (*SelectFieldsDefaultPlan) Explain ¶
func (r *SelectFieldsDefaultPlan) Explain(w format.Formatter)
Explain implements the plan.Plan Explain interface.
func (*SelectFieldsDefaultPlan) Filter ¶
func (r *SelectFieldsDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 ¶
func (r *SelectFinalPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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 ¶
SelectLockPlan handles SELECT ... FOR UPDATE, recording selected rows for acquiring locks explicitly.
func (*SelectLockPlan) Do ¶
func (r *SelectLockPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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 ¶
func (r *SelectLockPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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) 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 ¶
func (r *TableDefaultPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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 ¶
func (r *TableDefaultPlan) Filter(ctx context.Context, expr expression.Expression) (plan.Plan, bool, error)
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 ¶
TableNilPlan iterates rows but does nothing, e.g. SELECT 1 FROM t;
func (*TableNilPlan) Do ¶
func (r *TableNilPlan) Do(ctx context.Context, f plan.RowIterFunc) error
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) 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.