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

Function DecodeTableID

pkg/tablecodec/tablecodec.go:309–327  ·  view source on GitHub ↗

DecodeTableID decodes the table ID of the key, if the key is not table key, returns 0.

(key kv.Key)

Source from the content-addressed store, hash-verified

307
308// DecodeTableID decodes the table ID of the key, if the key is not table key, returns 0.
309func DecodeTableID(key kv.Key) int64 {
310 if !key.HasPrefix(tablePrefix) {
311 // If the key is in API V2, then ignore the prefix
312 _, k, err := tikv.DecodeKey(key, kvrpcpb.APIVersion_V2)
313 if err != nil {
314 terror.Log(errors.Trace(err))
315 return 0
316 }
317 key = k
318 if !key.HasPrefix(tablePrefix) {
319 return 0
320 }
321 }
322 key = key[len(tablePrefix):]
323 _, tableID, err := codec.DecodeInt(key)
324 // TODO: return error.
325 terror.Log(errors.Trace(err))
326 return tableID
327}
328
329// DecodeRowKey decodes the key and gets the handle.
330func DecodeRowKey(key kv.Key) (kv.Handle, error) {

Callers 15

ValidateFileRewriteRuleFunction · 0.92
GetRewriteTableIDFunction · 0.92
FindMatchedRewriteRuleFunction · 0.92
GetRewriteRawKeysFunction · 0.92
GetRewriteEncodedKeysFunction · 0.92
RewriteRangeFunction · 0.92
TableIDMethod · 0.92
TestCreateTablesFunction · 0.92
getProgressRangeMethod · 0.92
ReadSchemasFilesMethod · 0.92
SearchPlacementRuleFunction · 0.92
decodeKeyFromStringMethod · 0.92

Calls 3

LogFunction · 0.92
DecodeIntFunction · 0.92
HasPrefixMethod · 0.80

Tested by 6

TestCreateTablesFunction · 0.74
TestResourceGroupTagFunction · 0.74
noNewTablesAfterFunction · 0.74
TestRecordKeyFunction · 0.68
TestPrefixFunction · 0.68
TestV2TableCodecFunction · 0.68