go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletserver/planbuilder Index | Files

package planbuilder

import "gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletserver/planbuilder"


Package Files

ddl.go dml.go permission.go plan.go query_gen.go


var (
    // ErrTooComplex indicates given sql query is too complex.
    ErrTooComplex = vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "Complex")

    // PassthroughDMLs will return PlanPassDML for all update or delete statements
    PassthroughDMLs = false

func GenerateDeleteOuterQuery Uses

func GenerateDeleteOuterQuery(del *sqlparser.Delete, aliased *sqlparser.AliasedTableExpr) *sqlparser.ParsedQuery

GenerateDeleteOuterQuery generates the outer query for deletes.

func GenerateDeleteSubquery Uses

func GenerateDeleteSubquery(del *sqlparser.Delete, table *schema.Table, aliased *sqlparser.AliasedTableExpr) *sqlparser.ParsedQuery

GenerateDeleteSubquery generates the subquery for deletes.

func GenerateFieldQuery Uses

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 Uses

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

GenerateFullQuery generates the full query from the ast.

func GenerateInsertOuterQuery Uses

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

GenerateInsertOuterQuery generates the outer query for inserts.

func GenerateLimitQuery Uses

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

GenerateLimitQuery generates a select query with a limit clause.

func GenerateSubquery Uses

func GenerateSubquery(columns []sqlparser.ColIdent, 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 Uses

func GenerateUpdateOuterQuery(upd *sqlparser.Update, aliased *sqlparser.AliasedTableExpr, formatter sqlparser.NodeFormatter) *sqlparser.ParsedQuery

GenerateUpdateOuterQuery generates the outer query for updates. If there is no custom formatting needed, formatter can be nil.

func GenerateUpdateSubquery Uses

func GenerateUpdateSubquery(upd *sqlparser.Update, table *schema.Table, aliased *sqlparser.AliasedTableExpr) *sqlparser.ParsedQuery

GenerateUpdateSubquery generates the subquery for updates.

type DDLPlan Uses

type DDLPlan struct {
    Action string

DDLPlan provides a plan for DDLs.

func DDLParse Uses

func DDLParse(sql string) (plan *DDLPlan)

DDLParse parses a DDL and produces a DDLPlan.

type Permission Uses

type Permission struct {
    TableName string
    Role      tableacl.Role

Permission associates the required access permission for each table.

func BuildPermissions Uses

func BuildPermissions(stmt sqlparser.Statement) []Permission

BuildPermissions builds the list of required permissions for all the tables referenced in a query.

type Plan Uses

type Plan struct {
    PlanID PlanType
    Reason ReasonType
    Table  *schema.Table
    // NewName is the new name of the table. Set for DDLs which create or change the table.
    NewName sqlparser.TableIdent

    // Permissions stores the permissions for the tables accessed in the query.
    Permissions []Permission

    // 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.
    OuterQuery  *sqlparser.ParsedQuery
    Subquery    *sqlparser.ParsedQuery
    UpsertQuery *sqlparser.ParsedQuery

    // PlanInsertSubquery: columns to be inserted.
    ColumnNumbers []int

    // PKValues is an sqltypes.Value if it's sourced
    // from the query. If it's a bind var then it's
    // a string including the ':' prefix(es).
    // PlanDMLPK: where clause values.
    // PlanInsertPK: values clause.
    // PlanNextVal: increment.
    PKValues []sqltypes.PlanValue

    // For update: set clause if pk is changing.
    SecondaryPKValues []sqltypes.PlanValue

    // WhereClause is set for DMLs. It is used by the hot row protection
    // to serialize e.g. UPDATEs going to the same row.
    WhereClause *sqlparser.ParsedQuery

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

Plan is built for selects and DMLs.

func Build Uses

func Build(statement sqlparser.Statement, tables map[string]*schema.Table) (*Plan, error)

Build builds a plan based on the schema.

func BuildMessageStreaming Uses

func BuildMessageStreaming(name string, tables map[string]*schema.Table) (*Plan, error)

BuildMessageStreaming builds a plan for message streaming.

func BuildStreaming Uses

func BuildStreaming(sql string, tables map[string]*schema.Table) (*Plan, error)

BuildStreaming builds a streaming plan based on the schema.

func (*Plan) TableName Uses

func (plan *Plan) TableName() sqlparser.TableIdent

TableName returns the table name for the plan.

type PlanType Uses

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.
    // PlanNextval is for NEXTVAL.
    // PlanPassDML is pass through update & delete statements. This is
    // the default plan for update and delete statements.
    // If PassthroughDMLs is true, then it is used for all DML statements
    // and is valid in all replication modes.
    // Otherwise is only allowed in row based replication mode
    // PlanDMLPK is an update or delete with an equality where clause(s)
    // on primary key(s).
    // PlanDMLSubquery is an update or delete with a subselect statement
    // PlanInsertPK is insert statement where the PK value is
    // supplied with the query.
    // PlanInsertSubquery is same as PlanDMLSubquery but for inserts.
    // PlanUpsertPK is for insert ... on duplicate key constructs.
    // PlanInsertMessage is for inserting into message tables.
    // PlanSet is for SET statements.
    // PlanDDL is for DDL statements.
    // PlanSelectStream is used for streaming queries.
    // PlanOtherRead is for SHOW, DESCRIBE & EXPLAIN statements.
    // PlanOtherAdmin is for REPAIR, OPTIMIZE and TRUNCATE statements.
    // PlanMessageStream is used for streaming messages.
    // PlanSelectImpossible is used for where or having clauses that can never be true.
    // NumPlans stores the total number of plans

func PlanByName Uses

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

PlanByName find a PlanType by its string name.

func (PlanType) IsSelect Uses

func (pt PlanType) IsSelect() bool

IsSelect returns true if PlanType is about a select query.

func (PlanType) MarshalJSON Uses

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

MarshalJSON returns a json string for PlanType.

func (PlanType) String Uses

func (pt PlanType) String() string

type ReasonType Uses

type ReasonType int

ReasonType indicates why a query plan fails to build

const (
    ReasonDefault ReasonType = iota

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

func (ReasonType) MarshalJSON Uses

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

MarshalJSON returns a json string for ReasonType.

func (ReasonType) String Uses

func (rt ReasonType) String() string

String returns a string representation of a ReasonType.

Package planbuilder imports 9 packages (graph) and is imported by 2 packages. Updated 2019-06-13. Refresh now. Tools for package owners.