planbuilder

package
v2.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2016 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTooComplex indicates given sql query is too complex.
	ErrTooComplex = errors.New("Complex")
)

Functions

func FormatImpossible

func FormatImpossible(buf *sqlparser.TrackedBuffer, node sqlparser.SQLNode)

FormatImpossible is a callback function used by TrackedBuffer to generate a modified version of the query where all selects have impossible where clauses. It overrides a few node types and passes the rest down to the default FormatNode.

func GenerateDeleteOuterQuery

func GenerateDeleteOuterQuery(del *sqlparser.Delete) *sqlparser.ParsedQuery

GenerateDeleteOuterQuery generates the outer query for deletes.

func GenerateDeleteSubquery

func GenerateDeleteSubquery(del *sqlparser.Delete, tableInfo *schema.Table) *sqlparser.ParsedQuery

GenerateDeleteSubquery generates the subquery for deletes.

func GenerateFieldQuery

func GenerateFieldQuery(statement sqlparser.Statement) *sqlparser.ParsedQuery

GenerateFieldQuery generates a query to just fetch the field info by adding impossible where clauses as needed.

func GenerateFullQuery

func GenerateFullQuery(statement sqlparser.Statement) *sqlparser.ParsedQuery

GenerateFullQuery generates the full query from the ast.

func GenerateInsertOuterQuery

func GenerateInsertOuterQuery(ins *sqlparser.Insert) *sqlparser.ParsedQuery

GenerateInsertOuterQuery generates the outer query for inserts.

func GenerateSelectLimitQuery

func GenerateSelectLimitQuery(selStmt sqlparser.SelectStatement) *sqlparser.ParsedQuery

GenerateSelectLimitQuery generates a select query with a limit clause.

func GenerateSubquery

func GenerateSubquery(columns []cistring.CIString, table *sqlparser.AliasedTableExpr, where *sqlparser.Where, order sqlparser.OrderBy, limit *sqlparser.Limit, forUpdate bool) *sqlparser.ParsedQuery

GenerateSubquery generates a subquery based on the input parameters.

func GenerateUpdateOuterQuery

func GenerateUpdateOuterQuery(upd *sqlparser.Update) *sqlparser.ParsedQuery

GenerateUpdateOuterQuery generates the outer query for updates.

func GenerateUpdateSubquery

func GenerateUpdateSubquery(upd *sqlparser.Update, tableInfo *schema.Table) *sqlparser.ParsedQuery

GenerateUpdateSubquery generates the subquery for updats.

Types

type DDLPlan

type DDLPlan struct {
	Action    string
	TableName string
	NewName   string
}

DDLPlan provides a plan for DDLs.

func DDLParse

func DDLParse(sql string) (plan *DDLPlan)

DDLParse parses a DDL and produces a DDLPlan.

type ExecPlan

type ExecPlan struct {
	PlanID    PlanType
	Reason    ReasonType `json:",omitempty"`
	TableName string     `json:",omitempty"`

	// FieldQuery is used to fetch field info
	FieldQuery *sqlparser.ParsedQuery `json:",omitempty"`

	// FullQuery will be set for all plans.
	FullQuery *sqlparser.ParsedQuery `json:",omitempty"`

	// For PK plans, only OuterQuery is set.
	// For SUBQUERY plans, Subquery is also set.
	OuterQuery  *sqlparser.ParsedQuery `json:",omitempty"`
	Subquery    *sqlparser.ParsedQuery `json:",omitempty"`
	UpsertQuery *sqlparser.ParsedQuery `json:",omitempty"`

	// PlanInsertSubquery: columns to be inserted.
	ColumnNumbers []int `json:",omitempty"`

	// PlanDMLPK: where clause values.
	// PlanInsertPK: values clause.
	PKValues []interface{} `json:",omitempty"`

	// For update: set clause if pk is changing.
	SecondaryPKValues []interface{} `json:",omitempty"`

	// For PlanInsertSubquery: pk columns in the subquery result.
	SubqueryPKColumns []int `json:",omitempty"`
}

ExecPlan is built for selects and DMLs. PK Values values within ExecPlan can be: sqltypes.Value: sourced form the query, or string: bind variable name starting with ':', or nil if no value was specified

func GetExecPlan

func GetExecPlan(sql string, getTable TableGetter) (plan *ExecPlan, err error)

GetExecPlan generates a ExecPlan given a sql query and a TableGetter.

func GetStreamExecPlan

func GetStreamExecPlan(sql string, getTable TableGetter) (plan *ExecPlan, err error)

GetStreamExecPlan generates a ExecPlan given a sql query and a TableGetter.

type PlanType

type PlanType int

PlanType indicates a query plan type.

const (
	// PlanPassSelect is pass through select statements. This is the
	// default plan for select statements.
	PlanPassSelect PlanType = iota
	// PlanSelectLock is for a select that locks.
	PlanSelectLock
	// PlanNextval is for NEXTVAL
	PlanNextval
	// PlanPassDML is pass through update & delete statements. This is
	// the default plan for update and delete statements.
	PlanPassDML
	// PlanDMLPK is an update or delete with an equality where clause(s)
	// on primary key(s)
	PlanDMLPK
	// PlanDMLSubquery is an update or delete with a subselect statement
	PlanDMLSubquery
	// PlanInsertPK is insert statement where the PK value is
	// supplied with the query
	PlanInsertPK
	// PlanInsertSubquery is same as PlanDMLSubquery but for inserts
	PlanInsertSubquery
	// PlanUpsertPK is for insert ... on duplicate key constructs
	PlanUpsertPK
	// PlanSet is for SET statements
	PlanSet
	// PlanDDL is for DDL statements
	PlanDDL
	// PlanSelectStream is used for streaming queries
	PlanSelectStream
	// PlanOther is for SHOW, DESCRIBE & EXPLAIN statements
	PlanOther
	// NumPlans stores the total number of plans
	NumPlans
)

func PlanByName

func PlanByName(s string) (pt PlanType, ok bool)

PlanByName find a PlanType by its string name.

func (PlanType) IsSelect

func (pt PlanType) IsSelect() bool

IsSelect returns true if PlanType is about a select query.

func (PlanType) MarshalJSON

func (pt PlanType) MarshalJSON() ([]byte, error)

MarshalJSON returns a json string for PlanType.

func (PlanType) MinRole

func (pt PlanType) MinRole() tableacl.Role

MinRole is the minimum Role required to execute this PlanType.

func (PlanType) String

func (pt PlanType) String() string

type ReasonType

type ReasonType int

ReasonType indicates why a query plan fails to build

const (
	ReasonDefault ReasonType = iota
	ReasonTable
	ReasonTableNoIndex
	ReasonPKChange
	ReasonComplexExpr
	ReasonUpsert
)

Reason codes give a hint about why a certain plan was chosen.

func (ReasonType) MarshalJSON

func (rt ReasonType) MarshalJSON() ([]byte, error)

MarshalJSON returns a json string for ReasonType.

func (ReasonType) String

func (rt ReasonType) String() string

String returns a string representation of a ReasonType.

type TableGetter

type TableGetter func(tableName string) (*schema.Table, bool)

TableGetter returns a schema.Table given the table name.

Jump to

Keyboard shortcuts

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