本文整理汇总了Golang中github.com/pingcap/tidb/kv.KeyRange.StartKey方法的典型用法代码示例。如果您正苦于以下问题:Golang KeyRange.StartKey方法的具体用法?Golang KeyRange.StartKey怎么用?Golang KeyRange.StartKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/kv.KeyRange
的用法示例。
在下文中一共展示了KeyRange.StartKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: extractKVRanges
// 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
}
示例2: extractKVRanges
// 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
}
示例3: extractKVRanges
// 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
}
示例4: extractKVRanges
// 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
}
示例5: extractKVRanges
// 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
}