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

Method DecodeOne

pkg/tablecodec/tablecodec.go:1482–1531  ·  view source on GitHub ↗

DecodeOne decodes one temp index value element.

(b []byte)

Source from the content-addressed store, hash-verified

1480
1481// DecodeOne decodes one temp index value element.
1482func (v *TempIndexValueElem) DecodeOne(b []byte) (remain []byte, err error) {
1483 flag := TempIndexValueFlag(b[0])
1484 b = b[1:]
1485 switch flag {
1486 case TempIndexValueFlagNormal:
1487 vLen := (uint16(b[0]) << 8) + uint16(b[1])
1488 b = b[2:]
1489 v.Value = b[:vLen]
1490 b = b[vLen:]
1491 v.KeyVer = b[0]
1492 b = b[1:]
1493 v.Distinct = true
1494 return b, err
1495 case TempIndexValueFlagNonDistinctNormal:
1496 v.Value = b[:len(b)-1]
1497 v.KeyVer = b[len(b)-1]
1498 return nil, nil
1499 case TempIndexValueFlagDeleted:
1500 hLen := (uint16(b[0]) << 8) + uint16(b[1])
1501 b = b[2:]
1502 if hLen == idLen {
1503 v.Handle = DecodeIntHandleInIndexValue(b[:idLen])
1504 } else {
1505 v.Handle, _ = kv.NewCommonHandle(b[:hLen])
1506 }
1507 b = b[hLen:]
1508 if b[0] == TempIndexKeyTypePartitionIDFlag {
1509 v.Global = true
1510 var pid int64
1511 _, pid, err = codec.DecodeInt(b[1:9])
1512 if err != nil {
1513 return nil, err
1514 }
1515 v.Handle = kv.NewPartitionHandle(pid, v.Handle)
1516 b = b[9:]
1517 }
1518 v.KeyVer = b[0]
1519 b = b[1:]
1520 v.Distinct = true
1521 v.Delete = true
1522 return b, nil
1523 case TempIndexValueFlagNonDistinctDeleted:
1524 v.KeyVer = b[0]
1525 b = b[1:]
1526 v.Delete = true
1527 return b, nil
1528 default:
1529 return nil, errors.New("invalid temp index value")
1530 }
1531}
1532
1533// TempIndexValueIsUntouched returns true if the value is untouched.
1534// All the temp index value has the suffix of temp key version.

Callers 2

TestTempIndexValueCodecFunction · 0.95
DecodeTempIndexValueFunction · 0.95

Calls 6

NewCommonHandleFunction · 0.92
DecodeIntFunction · 0.92
NewPartitionHandleFunction · 0.92
TempIndexValueFlagTypeAlias · 0.85
NewMethod · 0.65

Tested by 1

TestTempIndexValueCodecFunction · 0.76