Documentation ¶
Index ¶
- Constants
- type Generate
- type Join
- func (jn *Join) Execute(vcursor VCursor, joinvars map[string]interface{}, wantfields bool) (*sqltypes.Result, error)
- func (jn *Join) GetFields(vcursor VCursor, joinvars map[string]interface{}) (*sqltypes.Result, error)
- func (jn *Join) StreamExecute(vcursor VCursor, joinvars map[string]interface{}, wantfields bool, ...) error
- type JoinOpcode
- type Plan
- type Primitive
- type Route
- func (rt *Route) Execute(vcursor VCursor, joinvars map[string]interface{}, wantields bool) (*sqltypes.Result, error)
- func (rt *Route) GetFields(vcursor VCursor, joinvars map[string]interface{}) (*sqltypes.Result, error)
- func (rt *Route) MarshalJSON() ([]byte, error)
- func (rt *Route) StreamExecute(vcursor VCursor, joinvars map[string]interface{}, wantfields bool, ...) error
- type RouteOpcode
- type VCursor
Constants ¶
const ( NormalJoin = JoinOpcode(iota) LeftJoin )
This is the list of JoinOpcode values.
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 // 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.
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.
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 ¶
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, joinvars map[string]interface{}, wantfields bool) (*sqltypes.Result, error)
Execute performs a non-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.
type Primitive ¶
type Primitive interface { Execute(vcursor VCursor, joinvars map[string]interface{}, wantields bool) (*sqltypes.Result, error) StreamExecute(vcursor VCursor, joinvars map[string]interface{}, wantields bool, sendReply func(*sqltypes.Result) error) error GetFields(vcursor VCursor, 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 }
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 (rt *Route) Execute(vcursor VCursor, joinvars map[string]interface{}, wantields bool) (*sqltypes.Result, error)
Execute performs a non-streaming exec.
func (*Route) GetFields ¶
func (rt *Route) GetFields(vcursor VCursor, joinvars map[string]interface{}) (*sqltypes.Result, error)
GetFields fetches the field info.
func (*Route) MarshalJSON ¶
MarshalJSON serializes the Route into a JSON representation. It's used for testing and diagnostics.
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 ¶ added in v0.12.0
func (code RouteOpcode) String() string
type VCursor ¶
type VCursor interface { ExecuteRoute(route *Route, joinvars map[string]interface{}) (*sqltypes.Result, error) StreamExecuteRoute(route *Route, joinvars map[string]interface{}, sendReply func(*sqltypes.Result) error) error GetRouteFields(route *Route, joinvars map[string]interface{}) (*sqltypes.Result, error) }
VCursor defines the interface the engine will use to execute routes.