// extractKVRanges extracts kv.KeyRanges slice from ctx.keyRanges, and also returns if it is in descending order. func (rs *localRegion) extractKVRanges(ctx *selectContext) (kvRanges []kv.KeyRange) { for _, kran := range ctx.keyRanges { upperKey := kran.EndKey if bytes.Compare(upperKey, rs.startKey) <= 0 { continue } lowerKey := kran.StartKey if bytes.Compare(lowerKey, rs.endKey) >= 0 { break } var kvr kv.KeyRange if bytes.Compare(lowerKey, rs.startKey) <= 0 { kvr.StartKey = rs.startKey } else { kvr.StartKey = lowerKey } if bytes.Compare(upperKey, rs.endKey) <= 0 { kvr.EndKey = upperKey } else { kvr.EndKey = rs.endKey } kvRanges = append(kvRanges, kvr) } if ctx.descScan { reverseKVRanges(kvRanges) } return }
// extractKVRanges extracts kv.KeyRanges slice from ctx.keyRanges, and also returns if it is in descending order. func (rs *localRegion) extractKVRanges(ctx *selectContext) (kvRanges []kv.KeyRange, desc bool) { sel := ctx.sel for _, kran := range ctx.keyRanges { upperKey := kran.EndKey if bytes.Compare(upperKey, rs.startKey) <= 0 { continue } lowerKey := kran.StartKey if bytes.Compare(lowerKey, rs.endKey) >= 0 { break } var kvr kv.KeyRange if bytes.Compare(lowerKey, rs.startKey) <= 0 { kvr.StartKey = rs.startKey } else { kvr.StartKey = lowerKey } if bytes.Compare(upperKey, rs.endKey) <= 0 { kvr.EndKey = upperKey } else { kvr.EndKey = rs.endKey } kvRanges = append(kvRanges, kvr) } if sel.OrderBy != nil { desc = sel.OrderBy[0].Desc } if desc { reverseKVRanges(kvRanges) } return }
// extractKVRanges extracts kv.KeyRanges slice from a SelectRequest, and also returns if it is in descending order. func (rs *localRegion) extractKVRanges(sel *tipb.SelectRequest) (kvRanges []kv.KeyRange, desc bool) { var ( tid int64 idxID int64 ) if sel.IndexInfo != nil { tid = sel.IndexInfo.GetTableId() idxID = sel.IndexInfo.GetIndexId() } else { tid = sel.TableInfo.GetTableId() } for _, kran := range sel.Ranges { var upperKey, lowerKey kv.Key if idxID == 0 { upperKey = tablecodec.EncodeRowKey(tid, kran.GetHigh()) if bytes.Compare(upperKey, rs.startKey) <= 0 { continue } lowerKey = tablecodec.EncodeRowKey(tid, kran.GetLow()) } else { upperKey = tablecodec.EncodeIndexSeekKey(tid, idxID, kran.GetHigh()) if bytes.Compare(upperKey, rs.startKey) <= 0 { continue } lowerKey = tablecodec.EncodeIndexSeekKey(tid, idxID, kran.GetLow()) } if bytes.Compare(lowerKey, rs.endKey) >= 0 { break } var kvr kv.KeyRange if bytes.Compare(lowerKey, rs.startKey) <= 0 { kvr.StartKey = rs.startKey } else { kvr.StartKey = lowerKey } if bytes.Compare(upperKey, rs.endKey) <= 0 { kvr.EndKey = upperKey } else { kvr.EndKey = rs.endKey } kvRanges = append(kvRanges, kvr) } if sel.OrderBy != nil { desc = *sel.OrderBy[0].Desc } if desc { reverseKVRanges(kvRanges) } return }
// extractKVRanges extracts kv.KeyRanges slice from a SelectRequest, and also returns if it is in descending order. func (h *rpcHandler) extractKVRanges(sel *tipb.SelectRequest) (kvRanges []kv.KeyRange, desc bool) { var ( tid int64 idxID int64 ) if sel.IndexInfo != nil { tid = sel.IndexInfo.GetTableId() idxID = sel.IndexInfo.GetIndexId() } else { tid = sel.TableInfo.GetTableId() } for _, kran := range sel.Ranges { var upperKey, lowerKey kv.Key if idxID == 0 { upperKey = tablecodec.EncodeRowKey(tid, kran.GetHigh()) if bytes.Compare(upperKey, h.startKey) <= 0 { continue } lowerKey = tablecodec.EncodeRowKey(tid, kran.GetLow()) } else { upperKey = tablecodec.EncodeIndexSeekKey(tid, idxID, kran.GetHigh()) if bytes.Compare(upperKey, h.startKey) <= 0 { continue } lowerKey = tablecodec.EncodeIndexSeekKey(tid, idxID, kran.GetLow()) } if len(h.endKey) != 0 && bytes.Compare([]byte(lowerKey), h.endKey) >= 0 { break } var kvr kv.KeyRange kvr.StartKey = kv.Key(maxStartKey(lowerKey, h.startKey)) kvr.EndKey = kv.Key(minEndKey(upperKey, h.endKey)) kvRanges = append(kvRanges, kvr) } if sel.OrderBy != nil { desc = *sel.OrderBy[0].Desc } if desc { reverseKVRanges(kvRanges) } return }
// extractKVRanges extracts kv.KeyRanges slice from a SelectRequest, and also returns if it is in descending order. func (h *rpcHandler) extractKVRanges(ctx *selectContext) (kvRanges []kv.KeyRange, desc bool) { sel := ctx.sel for _, kran := range ctx.keyRanges { upperKey := kran.GetEnd() if bytes.Compare(upperKey, h.startKey) <= 0 { continue } lowerKey := kran.GetStart() if len(h.endKey) != 0 && bytes.Compare([]byte(lowerKey), h.endKey) >= 0 { break } var kvr kv.KeyRange kvr.StartKey = kv.Key(maxStartKey(lowerKey, h.startKey)) kvr.EndKey = kv.Key(minEndKey(upperKey, h.endKey)) kvRanges = append(kvRanges, kvr) } if sel.OrderBy != nil { desc = sel.OrderBy[0].Desc } if desc { reverseKVRanges(kvRanges) } return }