MCPcopy Create free account
hub / github.com/pingcap/tidb / EncodeOldRow

Function EncodeOldRow

pkg/tablecodec/tablecodec.go:376–397  ·  view source on GitHub ↗

EncodeOldRow encode row data and column ids into a slice of byte. Row layout: colID1, value1, colID2, value2, ..... valBuf and values pass by caller, for reducing EncodeOldRow allocates temporary bufs. If you pass valBuf and values as nil, EncodeOldRow will allocate it.

(loc *time.Location, row []types.Datum, colIDs []int64, valBuf []byte, values []types.Datum)

Source from the content-addressed store, hash-verified

374// valBuf and values pass by caller, for reducing EncodeOldRow allocates temporary bufs. If you pass valBuf and values as nil,
375// EncodeOldRow will allocate it.
376func EncodeOldRow(loc *time.Location, row []types.Datum, colIDs []int64, valBuf []byte, values []types.Datum) ([]byte, error) {
377 if len(row) != len(colIDs) {
378 return nil, errors.Errorf("EncodeRow error: data and columnID count not match %d vs %d", len(row), len(colIDs))
379 }
380 valBuf = valBuf[:0]
381 if values == nil {
382 values = make([]types.Datum, len(row)*2)
383 }
384 for i, c := range row {
385 id := colIDs[i]
386 values[2*i].SetInt64(id)
387 err := flatten(loc, c, &values[2*i+1])
388 if err != nil {
389 return valBuf, errors.Trace(err)
390 }
391 }
392 if len(values) == 0 {
393 // We could not set nil value into kv.
394 return append(valBuf, codec.NilFlag), nil
395 }
396 return codec.EncodeValue(loc, valBuf, values...)
397}
398
399func flatten(loc *time.Location, data types.Datum, ret *types.Datum) error {
400 switch data.Kind() {

Callers 9

TestEncodeRowFunction · 0.92
EncodeBinlogRowDataMethod · 0.92
TestCodecUtilFunction · 0.92
TestOldRowCodecFunction · 0.92
TestRowCodecFunction · 0.85
TestDecodeColumnValueFunction · 0.85
TestCutRowFunction · 0.85
EncodeRowFunction · 0.85

Calls 4

EncodeValueFunction · 0.92
flattenFunction · 0.70
ErrorfMethod · 0.65
SetInt64Method · 0.45

Tested by 7

TestEncodeRowFunction · 0.74
TestCodecUtilFunction · 0.74
TestOldRowCodecFunction · 0.74
TestRowCodecFunction · 0.68
TestDecodeColumnValueFunction · 0.68
TestCutRowFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…