Skip to content

Commit

Permalink
reverse the ranges in localstore
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 committed Apr 21, 2016
1 parent e06f3aa commit f0de648
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 4 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,8 @@ func (s *testSuite) TestIndexReverseOrder(c *C) {
tk.MustExec("insert t (b) values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)")
result := tk.MustQuery("select b from t order by b desc")
result.Check(testkit.Rows("9", "8", "7", "6", "5", "4", "3", "2", "1", "0"))
result = tk.MustQuery("select b from t where b <3 or (b >=6 and b < 8) order by b desc")
result.Check(testkit.Rows("7", "6", "2", "1", "0"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int, b int, index idx (b, a))")
Expand All @@ -1055,6 +1057,8 @@ func (s *testSuite) TestIndexReverseOrder(c *C) {
tk.MustExec("insert t (b) values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)")
result = tk.MustQuery("select b from t order by b desc")
result.Check(testkit.Rows("9", "8", "7", "6", "5", "4", "3", "2", "1", "0"))
result = tk.MustQuery("select b from t where b <3 or (b >=6 and b < 8) order by b desc")
result.Check(testkit.Rows("7", "6", "2", "1", "0"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int, b int, index idx (b, a))")
Expand Down
1 change: 0 additions & 1 deletion executor/executor_xapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ func (e *XSelectIndexExec) doIndexRequest() (*xapi.SelectResult, error) {
selIdxReq.StartTs = &startTs
selIdxReq.IndexInfo = tablecodec.IndexToProto(e.table.Meta(), e.indexPlan.Index)
selIdxReq.Limit = e.indexPlan.LimitCount
selIdxReq.OrderBy = make([]*tipb.ByItem, 0)
selIdxReq.OrderBy = append(selIdxReq.OrderBy, &tipb.ByItem{Desc: &e.indexPlan.Desc})
fieldTypes := make([]*types.FieldType, len(e.indexPlan.Index.Columns))
for i, v := range e.indexPlan.Index.Columns {
Expand Down
6 changes: 1 addition & 5 deletions store/localstore/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ func (c *dbClient) SupportRequestType(reqType, subType int64) bool {
return false
}

func (c *dbClient) SetSupportDesc(flag bool) {
SupportDesc = flag
}

func supportExpr(exprType tipb.ExprType) bool {
switch exprType {
case tipb.ExprType_Null, tipb.ExprType_Int64, tipb.ExprType_Uint64, tipb.ExprType_Float32,
Expand Down Expand Up @@ -184,7 +180,7 @@ func buildRegionTasks(client *dbClient, req *kv.Request) (tasks []*task) {
}
}
if req.Desc && SupportDesc {
for i := 0; i < len(tasks); i++ {
for i := 0; i < len(tasks)/2; i++ {
j := len(tasks) - i - 1
tasks[i], tasks[j] = tasks[j], tasks[i]
}
Expand Down
19 changes: 10 additions & 9 deletions store/localstore/local_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,24 @@ func (rs *localRegion) getRowsFromIndexReq(txn kv.Transaction, sel *tipb.SelectR
desc = *sel.OrderBy[0].Desc
}
for _, ran := range kvRanges {
ranRows, err := getIndexRowFromRange(sel.IndexInfo, txn, ran, desc)
ranRows, err := getIndexRowFromRange(sel.IndexInfo, txn, ran)
if err != nil {
return nil, errors.Trace(err)
}
rows = append(rows, ranRows...)
}

if desc && SupportDesc {
for i := 0; i < len(rows)/2; i++ {
j := len(rows) - i - 1
rows[i], rows[j] = rows[j], rows[i]
}
}

return rows, nil
}

func getIndexRowFromRange(idxInfo *tipb.IndexInfo, txn kv.Transaction, ran kv.KeyRange, Desc bool) ([]*tipb.Row, error) {
func getIndexRowFromRange(idxInfo *tipb.IndexInfo, txn kv.Transaction, ran kv.KeyRange) ([]*tipb.Row, error) {
var rows []*tipb.Row
seekKey := ran.StartKey
for {
Expand Down Expand Up @@ -375,13 +383,6 @@ func getIndexRowFromRange(idxInfo *tipb.IndexInfo, txn kv.Transaction, ran kv.Ke
rows = append(rows, row)
}

if Desc && SupportDesc {
for i := 0; i < len(rows)/2; i++ {
j := len(rows) - i - 1
rows[i], rows[j] = rows[j], rows[i]
}
}

return rows, nil
}

Expand Down

0 comments on commit f0de648

Please sign in to comment.