code: func TableHandlesToKVRanges(tid int64, handles []int64) []kv.KeyRange {
  	krs := make([]kv.KeyRange, 0, len(handles))
  	i := 0
  	for i < len(handles) {
  		j := i + 1
  		for ; j < len(handles) && handles[j-1] != math.MaxInt64; j++ {
  			if handles[j] != handles[j-1]+1 {
  				break
  			}
  		}
  		low := codec.EncodeInt(nil, handles[i])
  		high := codec.EncodeInt(nil, handles[j-1])
  		high = []byte(kv.Key(high).PrefixNext())
  		startKey := tablecodec.EncodeRowKey(tid, low)
  		endKey := tablecodec.EncodeRowKey(tid, high)
  		krs = append(krs, kv.KeyRange{StartKey: startKey, EndKey: endKey})
  		i = j
  	}
  	return krs
  }
docs: // TableHandlesToKVRanges converts sorted handle to kv ranges.
  // For continuous handles, we should merge them to a single key range.