Documentation ¶
Overview ¶
Package splitquery contains the logic needed for implementing the tabletserver's SplitQuery RPC.
It defines the Splitter type that drives the query splitting procedure. It cooperates with the SplitParams type and splitAlgorithmInterface interface.
Usage Example:
1. Create a SplitParams object.
splitParams, err := NewSplitParams("SELECT * FROM table WHERE id > :id", // SQL query map[string]interface{}{id: int64(5)} // Bind Variables ["id", "user_id"], // SplitColumns schema) // See below. // Schema should be a map[string]schema.Table that maps a table name to its schema.Table // object. It's mostly used for error-checking the split columns. if (err != nil) { panic("SplitParams creation failed with: " + err) }
2. Create the SplitAlgorithmInterface object used for splitting. SplitQuery supports multiple algorithms for splitting the query. These are encapsulated as types implementing the SplitAlgorithmInterface. Currently two algorithms are supported represented by the FullScanAlgorithm and EqualSplitsAlgorithm types. See the documentation of these types for more details on each algorithm. To do the split we'll need to create an object of one of these types and pass it to the Splitter (see below). Here we use the FullScan algorithm. We also pass a type implementing the MySQLExecuter interface that the algorithm will use to send statements to MySQL.
algorithm, err := NewFullScanAlgorithm(splitParams, mySqlExecuter) if (err != nil) { panic("FullScnaAlgorithm creation failed with: " + err) }
3. Create a splitter object. Always succeeds.
splitter := NewSplitter(splitParams, algorithm)
4. Call splitter.Split() to Split the query. The result is a slice of querytypes.QuerySplit objects.
var queryParts []querytypes.QuerySplit queryParts, err = splitter.Split() if (err != nil) { panic("splitter.Split() failed with: " + err); }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SQLExecuter ¶
type SQLExecuter interface {
SQLExecute(sql string, bindVariables map[string]interface{}) (*sqltypes.Result, error)
}
SQLExecuter enacpsulates access to the MySQL database.
type SplitAlgorithmInterface ¶
type SplitAlgorithmInterface interface {
// contains filtered or unexported methods
}
SplitAlgorithmInterface defines the interface for a splitting algorithm. A splitting algorithm implements the generateBoundaries() method that returns a list of "boundary tuples". Each tuple is expected to contain values of the split columns, in the order these are defined in SplitParams.splitColumns, at a specific "boundary point". The returned list should be ordered using ascending lexicographical order. If the resulting list of boundary tuples is: {t1, t2, ..., t_k}, the splitquery.Splitter.Split() method would generate k+1 query parts. For i=0,1,...,k, the ith query-part contains the rows whose split-columns are in the range [t_i, t_i+1), where t_0 and t_k+1 are taken to be a "-infinity" tuple and a "+infinity" tuple, respectively.
type SplitParams ¶
type SplitParams struct {
// contains filtered or unexported fields
}
SplitParams stores the parameters for splitting a query.
func NewSplitParams ¶
func NewSplitParams( sql string, bindVariables map[string]interface{}, splitColumns []string, schema map[string]*schema.Table) (*SplitParams, error)
NewSplitParams returns a new SplitParams object. Parameters: 'sql' is the SQL query to split. The query must satisfy the restrictions found in the documentation of the vtgate.SplitQueryRequest.query protocol buffer field. 'bindVariables' are the bind-variables for the sql query. 'splitColumns' the list of splitColumns to use. These must adhere to the restrictions found in the documentation of the vtgate.SplitQueryRequest.split_column protocol buffer field. If splitColumns is nil, the split columns used are the primary key columns (in order).
type Splitter ¶
type Splitter struct {
// contains filtered or unexported fields
}
Splitter is used to drive the splitting procedure.
func NewSplitter ¶
func NewSplitter( splitParams *SplitParams, algorithm SplitAlgorithmInterface) *Splitter
NewSplitter creates a new Splitter object.
func (*Splitter) Split ¶
func (splitter *Splitter) Split() ([]querytypes.QuerySplit, error)
Split does the actual work of splitting the query. It returns a slice of querytypes.QuerySplit objects representing the query parts.