planbuilder

package
v2.0.0-alpha3+incompat... Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NO_MATCH      = scoreValue(-1)
	PERFECT_SCORE = scoreValue(0)
)

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 GenerateSelectOuterQuery

func GenerateSelectOuterQuery(sel *sqlparser.Select, tableInfo *schema.Table) *sqlparser.ParsedQuery

GenerateSelectOuterQuery generates the outer query for dmls.

func GenerateSelectSubquery

func GenerateSelectSubquery(sel *sqlparser.Select, tableInfo *schema.Table, index string) *sqlparser.ParsedQuery

GenerateSelectSubquery generates the subquery for selects.

func GenerateSubquery

func GenerateSubquery(columns []string, 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
}

func DDLParse

func DDLParse(sql string) (plan *DDLPlan)

type ExecPlan

type ExecPlan struct {
	PlanId    PlanType
	Reason    ReasonType
	TableName string

	// FieldQuery is used to fetch field info
	FieldQuery *sqlparser.ParsedQuery

	// FullQuery will be set for all plans.
	FullQuery *sqlparser.ParsedQuery

	// For PK plans, only OuterQuery is set.
	// For SUBQUERY plans, Subquery is also set.
	// IndexUsed is set only for PLAN_SELECT_SUBQUERY
	OuterQuery  *sqlparser.ParsedQuery
	Subquery    *sqlparser.ParsedQuery
	UpsertQuery *sqlparser.ParsedQuery
	IndexUsed   string

	// For selects, columns to be returned
	// For PLAN_INSERT_SUBQUERY, columns to be inserted
	ColumnNumbers []int

	// PLAN_PK_IN, PLAN_DML_PK: where clause values
	// PLAN_INSERT_PK: values clause
	PKValues []interface{}

	// PK_IN. Limit clause value.
	Limit interface{}

	// For update: set clause if pk is changing
	SecondaryPKValues []interface{}

	// For PLAN_INSERT_SUBQUERY: pk columns in the subquery result
	SubqueryPKColumns []int

	// PLAN_SET
	SetKey   string
	SetValue interface{}
}

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 IndexScore

type IndexScore struct {
	Index       *schema.Index
	ColumnMatch []bool
	MatchFailed bool
}

func NewIndexScore

func NewIndexScore(index *schema.Index) *IndexScore

func NewIndexScoreList

func NewIndexScoreList(indexes []*schema.Index) []*IndexScore

func (*IndexScore) FindMatch

func (is *IndexScore) FindMatch(columnName string) int

func (*IndexScore) GetScore

func (is *IndexScore) GetScore() scoreValue

type PlanType

type PlanType int

PlanType indicates a query plan type.

const (
	// PLAN_PASS_SELECT is pass through select statements. This is the
	// default plan for select statements.
	PLAN_PASS_SELECT PlanType = iota
	// PLAN_PASS_DML is pass through update & delete statements. This is
	// the default plan for update and delete statements.
	PLAN_PASS_DML
	// PLAN_PK_EQUAL is deprecated. Use PLAN_PK_IN instead.
	PLAN_PK_EQUAL
	// PLAN_PK_IN is select statement with a single IN clause on primary key
	PLAN_PK_IN
	// PLAN_SELECT_SUBQUERY is select statement with a subselect statement
	PLAN_SELECT_SUBQUERY
	// PLAN_DML_PK is an update or delete with an equality where clause(s)
	// on primary key(s)
	PLAN_DML_PK
	// PLAN_DML_SUBQUERY is an update or delete with a subselect statement
	PLAN_DML_SUBQUERY
	// PLAN_INSERT_PK is insert statement where the PK value is
	// supplied with the query
	PLAN_INSERT_PK
	// PLAN_INSERT_SUBQUERY is same as PLAN_DML_SUBQUERY but for inserts
	PLAN_INSERT_SUBQUERY
	// PLAN_SET is for SET statements
	PLAN_SET
	// PLAN_DDL is for DDL statements
	PLAN_DDL
	// PLAN_SELECT_STREAM is used for streaming queries
	PLAN_SELECT_STREAM
	// PLAN_OTHER is for SHOW, DESCRIBE & EXPLAIN statements
	PLAN_OTHER
	// PLAN_UPSERT_PK is for insert ... on duplicate key constructs
	PLAN_UPSERT_PK
	// 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 (
	REASON_DEFAULT ReasonType = iota
	REASON_SELECT
	REASON_TABLE
	REASON_NOCACHE
	REASON_SELECT_LIST
	REASON_LOCK
	REASON_WHERE
	REASON_ORDER
	REASON_LIMIT
	REASON_PKINDEX
	REASON_COVERING
	REASON_NOINDEX_MATCH
	REASON_TABLE_NOINDEX
	REASON_PK_CHANGE
	REASON_HAS_HINTS
	REASON_COMPLEX_EXPR
	REASON_UPSERT
)

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