зеркало из https://github.com/github/vitess-gh.git
Fix full_scan_algorithm comments.
Adjust comments to show that split query no longer preserves WHERE clause. Add ORDER BY clause to comments. Adjust LIMIT to be numRowsPerQueryPart-1, 1 for correctness.
This commit is contained in:
Родитель
4e46b98f08
Коммит
24a38cc202
|
@ -15,15 +15,15 @@ import (
|
|||
// It iteratively executes the following query over the replica’s database (recall that MySQL
|
||||
// performs tuple comparisons lexicographically):
|
||||
// SELECT <split_columns> FROM <table>
|
||||
// WHERE (<where>) AND (:prev_boundary <= (<split_columns>))
|
||||
// WHERE :prev_boundary <= (<split_columns>)
|
||||
// ORDER BY <split_columns>
|
||||
// LIMIT <num_rows_per_query_part>, 1
|
||||
// where <split_columns> denotes the ordered list of split columns, and <table> and <where> are the
|
||||
// values of the FROM and WHERE clauses of the input query, respectefully.
|
||||
// where <split_columns> denotes the ordered list of split columns, and <table> is the
|
||||
// value of the FROM and WHERE clauses of the input query, respectfully.
|
||||
// The 'prev_boundary' bind variable holds a tuple consisting of split column values.
|
||||
// It is updated after each iteration with the result of the query. In the query executed in the
|
||||
// first iteration (the initial query) the term 'AND (:prev_boundary <= (<split_columns>))' is
|
||||
// ommitted.
|
||||
// first iteration (the initial query) the term ':prev_boundary <= (<split_columns>)' is
|
||||
// omitted.
|
||||
// The algorithm stops when the query returns no results. The result of this algorithm is the list
|
||||
// consisting of the result of each query in order.
|
||||
//
|
||||
|
@ -108,8 +108,8 @@ func (a *FullScanAlgorithm) populatePrevTupleInBindVariables(
|
|||
// "SELECT <select exprs> FROM <table> WHERE <where>",
|
||||
// the Sql field of the result will be:
|
||||
// "SELECT sc_1,sc_2,...,sc_n FROM <table>
|
||||
// WHERE <where>
|
||||
// LIMIT splitParams.numRowsPerQueryPart, 1",
|
||||
// ORDER BY <split_columns>
|
||||
// LIMIT splitParams.numRowsPerQueryPart-1, 1",
|
||||
// The BindVariables field of the result will contain a deep-copy of splitParams.BindVariables.
|
||||
func buildInitialQuery(splitParams *SplitParams) *querytypes.BoundQuery {
|
||||
resultSelectAST := buildInitialQueryAST(splitParams)
|
||||
|
@ -128,7 +128,7 @@ func buildInitialQueryAST(splitParams *SplitParams) *sqlparser.Select {
|
|||
resultSelectAST := *splitParams.selectAST
|
||||
resultSelectAST.Where = nil
|
||||
resultSelectAST.SelectExprs = convertColumnsToSelectExprs(splitParams.splitColumns)
|
||||
resultSelectAST.Limit = buildLimitClause(splitParams.numRowsPerQueryPart, 1)
|
||||
resultSelectAST.Limit = buildLimitClause(splitParams.numRowsPerQueryPart-1, 1)
|
||||
resultSelectAST.OrderBy = buildOrderByClause(splitParams.splitColumns)
|
||||
return &resultSelectAST
|
||||
}
|
||||
|
@ -139,7 +139,8 @@ func buildInitialQueryAST(splitParams *SplitParams) *sqlparser.Select {
|
|||
// "SELECT <select exprs> FROM <table> WHERE <where>",
|
||||
// the Sql field of the result will be:
|
||||
// "SELECT sc_1,sc_2,...,sc_n FROM <table>
|
||||
// WHERE (<where>) AND (:prev_sc_1,...,:prev_sc_n) <= (sc_1,...,sc_n)
|
||||
// WHERE :prev_sc_1,...,:prev_sc_n) <= (sc_1,...,sc_n)
|
||||
// ORDER BY <split_columns>
|
||||
// LIMIT splitParams.numRowsPerQueryPart, 1",
|
||||
// where sc_1,...,sc_n are the split columns,
|
||||
// and :prev_sc_1,...,:_prev_sc_n are the bind variable names for the previous tuple.
|
||||
|
|
|
@ -31,7 +31,7 @@ func TestMultipleBoundaries(t *testing.T) {
|
|||
expectedCall1 := mockSQLExecuter.EXPECT().SQLExecute(
|
||||
"select id, user_id from test_table"+
|
||||
" order by id asc, user_id asc"+
|
||||
" limit 1000, 1",
|
||||
" limit 999, 1",
|
||||
map[string]interface{}{})
|
||||
expectedCall1.Return(
|
||||
&sqltypes.Result{
|
||||
|
@ -45,7 +45,7 @@ func TestMultipleBoundaries(t *testing.T) {
|
|||
" :_splitquery_prev_id < id or"+
|
||||
" (:_splitquery_prev_id = id and :_splitquery_prev_user_id <= user_id)"+
|
||||
" order by id asc, user_id asc"+
|
||||
" limit 1000, 1",
|
||||
" limit 999, 1",
|
||||
map[string]interface{}{
|
||||
"_splitquery_prev_id": int64(1),
|
||||
"_splitquery_prev_user_id": int64(1),
|
||||
|
@ -63,7 +63,7 @@ func TestMultipleBoundaries(t *testing.T) {
|
|||
" :_splitquery_prev_id < id or"+
|
||||
" (:_splitquery_prev_id = id and :_splitquery_prev_user_id <= user_id)"+
|
||||
" order by id asc, user_id asc"+
|
||||
" limit 1000, 1",
|
||||
" limit 999, 1",
|
||||
map[string]interface{}{
|
||||
"_splitquery_prev_id": int64(2),
|
||||
"_splitquery_prev_user_id": int64(10),
|
||||
|
@ -109,7 +109,7 @@ func TestSmallNumberOfRows(t *testing.T) {
|
|||
expectedCall1 := mockSQLExecuter.EXPECT().SQLExecute(
|
||||
"select id, user_id from test_table"+
|
||||
" order by id asc, user_id asc"+
|
||||
" limit 1000, 1",
|
||||
" limit 999, 1",
|
||||
map[string]interface{}{})
|
||||
expectedCall1.Return(
|
||||
&sqltypes.Result{Rows: [][]sqltypes.Value{}}, nil)
|
||||
|
@ -148,7 +148,7 @@ func TestSQLExecuterReturnsError(t *testing.T) {
|
|||
expectedCall1 := mockSQLExecuter.EXPECT().SQLExecute(
|
||||
"select id, user_id from test_table"+
|
||||
" order by id asc, user_id asc"+
|
||||
" limit 1000, 1",
|
||||
" limit 999, 1",
|
||||
map[string]interface{}{})
|
||||
expectedCall1.Return(
|
||||
&sqltypes.Result{
|
||||
|
@ -162,7 +162,7 @@ func TestSQLExecuterReturnsError(t *testing.T) {
|
|||
" :_splitquery_prev_id < id or"+
|
||||
" (:_splitquery_prev_id = id and :_splitquery_prev_user_id <= user_id)"+
|
||||
" order by id asc, user_id asc"+
|
||||
" limit 1000, 1",
|
||||
" limit 999, 1",
|
||||
map[string]interface{}{
|
||||
"_splitquery_prev_id": int64(1),
|
||||
"_splitquery_prev_user_id": int64(1),
|
||||
|
|
Загрузка…
Ссылка в новой задаче