engine

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NormalJoin = JoinOpcode(iota)
	LeftJoin
)

This is the list of JoinOpcode values.

View Source
const (
	NoCode = RouteOpcode(iota)
	// SelectUnsharded is the opcode for routing a
	// select statement to an unsharded database.
	SelectUnsharded
	// SelectEqualUnique is for routing a query to
	// a single shard. Requires: A Unique Vindex, and
	// a single Value.
	SelectEqualUnique
	// SelectEqual is for routing a query using a
	// non-unique vindex. Requires: A Vindex, and
	// a single Value.
	SelectEqual
	// SelectIN is for routing a query that has an IN
	// clause using a Vindex. Requires: A Vindex,
	// and a Values list.
	SelectIN
	// SelectScatter is for routing a scatter query
	// to all shards of a keyspace.
	SelectScatter
	// UpdateUnsharded is for routing an update statement
	// to an unsharded keyspace.
	UpdateUnsharded
	// UpdateEqual is for routing an update statement
	// to a single shard: Requires: A Vindex, and
	// a single Value.
	UpdateEqual
	// DeleteUnsharded is for routing a delete statement
	// to an unsharded keyspace.
	DeleteUnsharded
	// DeleteEqual is for routing a delete statement
	// to a single shard. Requires: A Vindex, a single
	// Value, and a Subquery, which will be used to
	// determine if lookup rows need to be deleted.
	DeleteEqual
	// InsertUnsharded is for routing an insert statement
	// to an unsharded keyspace.
	InsertUnsharded
	// InsertUnsharded is for routing an insert statement
	// to a single shard. Requires: A list of Values, one
	// for each ColVindex. If the table has an Autoinc column,
	// A Generate subplan must be created.
	InsertSharded
	// Show is a pseudo-opcode used for SHOW commands
	Show
	// NumCodes is the total number of opcodes for routes.
	NumCodes
)

This is the list of RouteOpcode values. The opcode dictates which fields must be set in the Route. All routes require the Query and a Keyspace to be correctly set. For any Select opcode, the FieldQuery is set to a statement with an impossible where clause. This gets used to build the field info in situations where joins end up returning no rows. In the case of a join, Joinvars will also be set. These are variables that will be supplied by the Join primitive when it invokes a Route. All DMLs must have the Table field set. The ColVindexes in the field will be used to perform various computations and sanity checks. The rest of the fields depend on the opcode.

View Source
const ListVarName = "__vals"

ListVarName is a reserved bind var name for list vars. This is used for sending different IN clause values to different shards.

View Source
const SeqVarName = "__seq"

SeqVarName is a reserved bind var name for sequence values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generate

type Generate struct {
	// Opcode can only be SelectUnsharded for now.
	Opcode   RouteOpcode
	Keyspace *vindexes.Keyspace
	Query    string
	// Value is the supplied value. A new value will be generated
	// only if Value was NULL. Otherwise, the supplied value will
	// be used.
	Value interface{}
}

Generate represents the instruction to generate a value from a sequence. We cannot reuse a Route for this because this needs to be always executed outside a transaction.

func (*Generate) MarshalJSON

func (gen *Generate) MarshalJSON() ([]byte, error)

MarshalJSON serializes Generate into a JSON representation. It's used for testing and diagnostics.

type Join

type Join struct {
	Opcode JoinOpcode
	// Left and Right are the LHS and RHS primitives
	// of the Join. They can be any primitive.
	Left, Right Primitive `json:",omitempty"`
	// Cols defines which columns from the left
	// or right results should be used to build the
	// return result. For results coming from the
	// left query, the index values go as -1, -2, etc.
	// For the right query, they're 1, 2, etc.
	// If Cols is {-1, -2, 1, 2}, it means that
	// the returned result will be {Left0, Left1, Right0, Right1}.
	Cols []int `json:",omitempty"`
	// Vars defines the list of JoinVars that need to
	// be built from the LHS result before invoking
	// the RHS subqquery.
	Vars map[string]int `json:",omitempty"`
}

Join specifies the parameters for a join primitive.

func (*Join) Execute

func (jn *Join) Execute(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}, wantfields bool) (*sqltypes.Result, error)

Execute performs a non-streaming exec.

func (*Join) GetFields

func (jn *Join) GetFields(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}) (*sqltypes.Result, error)

GetFields fetches the field info.

func (*Join) StreamExecute

func (jn *Join) StreamExecute(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}, wantfields bool, callback func(*sqltypes.Result) error) error

StreamExecute performs a streaming exec.

type JoinOpcode

type JoinOpcode int

JoinOpcode is a number representing the opcode for the Join primitive.

func (JoinOpcode) MarshalJSON

func (code JoinOpcode) MarshalJSON() ([]byte, error)

MarshalJSON serializes the JoinOpcode as a JSON string. It's used for testing and diagnostics.

func (JoinOpcode) String

func (code JoinOpcode) String() string

type Plan

type Plan struct {
	// Original is the original query.
	Original string `json:",omitempty"`
	// Instructions contains the instructions needed to
	// fulfil the query.
	Instructions Primitive `json:",omitempty"`
}

Plan represents the execution strategy for a given query. For now it's a simple wrapper around the real instructions. An instruction (aka Primitive) is typically a tree where each node does its part by combining the results of the sub-nodes.

func (*Plan) Size

func (pln *Plan) Size() int

Size is defined so that Plan can be given to a cache.LRUCache. VTGate needs to maintain a cache of plans. It uses LRUCache, which in turn requires its objects to define a Size function.

type Primitive

type Primitive interface {
	Execute(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}, wantfields bool) (*sqltypes.Result, error)
	StreamExecute(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}, wantields bool, callback func(*sqltypes.Result) error) error
	GetFields(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}) (*sqltypes.Result, error)
}

Primitive is the interface that needs to be satisfied by all primitives of a plan.

type Route

type Route struct {
	Opcode     RouteOpcode
	Keyspace   *vindexes.Keyspace
	Query      string
	FieldQuery string
	Vindex     vindexes.Vindex
	Values     interface{}
	JoinVars   map[string]struct{}
	Table      *vindexes.Table
	Subquery   string
	Generate   *Generate
	Prefix     string
	Mid        []string
	Suffix     string
}

Route represents the instructions to route a query to one or many vttablets. The meaning and values for the the fields are described in the RouteOpcode values comments.

func (*Route) Execute

func (route *Route) Execute(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}, wantfields bool) (*sqltypes.Result, error)

Execute performs a non-streaming exec.

func (*Route) GetFields

func (route *Route) GetFields(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}) (*sqltypes.Result, error)

GetFields fetches the field info.

func (*Route) MarshalJSON

func (route *Route) MarshalJSON() ([]byte, error)

MarshalJSON serializes the Route into a JSON representation. It's used for testing and diagnostics.

func (*Route) StreamExecute

func (route *Route) StreamExecute(vcursor VCursor, queryConstruct *queryinfo.QueryConstruct, joinvars map[string]interface{}, wantfields bool, callback func(*sqltypes.Result) error) error

StreamExecute performs a streaming exec.

type RouteOpcode

type RouteOpcode int

RouteOpcode is a number representing the opcode for the Route primitve.

func (RouteOpcode) MarshalJSON

func (code RouteOpcode) MarshalJSON() ([]byte, error)

MarshalJSON serializes the RouteOpcode as a JSON string. It's used for testing and diagnostics.

func (RouteOpcode) String

func (code RouteOpcode) String() string

type VCursor

type VCursor interface {
	ExecuteMultiShard(keyspace string, shardQueries map[string]querytypes.BoundQuery, notInTransaction bool) (*sqltypes.Result, error)
	StreamExecuteMulti(query string, keyspace string, shardVars map[string]map[string]interface{}, callback func(reply *sqltypes.Result) error) error
	GetAnyShard(keyspace string) (ks, shard string, err error)
	ScatterConnExecute(query string, bindVars map[string]interface{}, keyspace string, shards []string, notInTransaction bool) (*sqltypes.Result, error)
	GetKeyspaceShards(keyspace string) (string, *topodatapb.SrvKeyspace, []*topodatapb.ShardReference, error)
	GetShardForKeyspaceID(allShards []*topodatapb.ShardReference, keyspaceID []byte) (string, error)
	ExecuteShard(keyspace string, shardQueries map[string]querytypes.BoundQuery) (*sqltypes.Result, error)
	Execute(query string, bindvars map[string]interface{}) (*sqltypes.Result, error)
	ExecuteShow(query string, bindvars map[string]interface{}, keyspace string) (*sqltypes.Result, error)
}

VCursor defines the interface the engine will use to execute routes.

Jump to

Keyboard shortcuts

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