MCPcopy
hub / github.com/pingcap/tidb / DecodeKeyHead

Function DecodeKeyHead

pkg/tablecodec/tablecodec.go:261–293  ·  view source on GitHub ↗

DecodeKeyHead decodes the key's head and gets the tableID, indexID. isRecordKey is true when is a record key.

(key kv.Key)

Source from the content-addressed store, hash-verified

259
260// DecodeKeyHead decodes the key's head and gets the tableID, indexID. isRecordKey is true when is a record key.
261func DecodeKeyHead(key kv.Key) (tableID int64, indexID int64, isRecordKey bool, err error) {
262 isRecordKey = false
263 k := key
264 if !key.HasPrefix(tablePrefix) {
265 err = errInvalidKey.GenWithStack("invalid key - %q", k)
266 return
267 }
268
269 key = key[len(tablePrefix):]
270 key, tableID, err = codec.DecodeInt(key)
271 if err != nil {
272 err = errors.Trace(err)
273 return
274 }
275
276 if key.HasPrefix(recordPrefixSep) {
277 isRecordKey = true
278 return
279 }
280 if !key.HasPrefix(indexPrefixSep) {
281 err = errInvalidKey.GenWithStack("invalid key - %q", k)
282 return
283 }
284
285 key = key[len(indexPrefixSep):]
286
287 key, indexID, err = codec.DecodeInt(key)
288 if err != nil {
289 err = errors.Trace(err)
290 return
291 }
292 return
293}
294
295// DecodeIndexID decodes indexID from the key.
296// this method simply extract index id part, and no other checking.

Callers 14

NeedsMergeFunction · 0.92
decodeIndexKeyMethod · 0.92
extractKeyExistsErrMethod · 0.92
decodeIndexKeyValueMethod · 0.92
decodeIndexKeyFunction · 0.92
TestBuildDupTaskFunction · 0.92
DecodeKeyFunction · 0.92
getDuplicateMessageMethod · 0.92
TestIndexKeyFunction · 0.85
TestRecordKeyFunction · 0.85
TestPrefixFunction · 0.85

Calls 2

DecodeIntFunction · 0.92
HasPrefixMethod · 0.80

Tested by 6

decodeIndexKeyFunction · 0.74
TestBuildDupTaskFunction · 0.74
TestIndexKeyFunction · 0.68
TestRecordKeyFunction · 0.68
TestPrefixFunction · 0.68
TestTempIndexKeyFunction · 0.68