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

Function decodeRestoredValuesV5

pkg/tablecodec/tablecodec.go:866–903  ·  view source on GitHub ↗

decodeRestoredValuesV5 decodes index values whose format is introduced in TiDB 5.0. Unlike the format in TiDB 4.0, the new format is optimized for storage space: 1. If the index is a composed index, only the non-binary string column's value need to write to value, not all. 2. If a string column's co

(columns []rowcodec.ColInfo, results [][]byte, restoredVal []byte)

Source from the content-addressed store, hash-verified

864// 2. If a string column's collation is _bin, then we only write the number of the truncated spaces to value.
865// 3. If a string column is char, not varchar, then we use the sortKey directly.
866func decodeRestoredValuesV5(columns []rowcodec.ColInfo, results [][]byte, restoredVal []byte) ([][]byte, error) {
867 colIDOffsets := buildColumnIDOffsets(columns)
868 colInfosNeedRestore := buildRestoredColumn(columns)
869 rd := rowcodec.NewByteDecoder(colInfosNeedRestore, nil, nil, nil)
870 newResults, err := rd.DecodeToBytesNoHandle(colIDOffsets, restoredVal)
871 if err != nil {
872 return nil, errors.Trace(err)
873 }
874 for i := range newResults {
875 noRestoreData := len(newResults[i]) == 0
876 if noRestoreData {
877 newResults[i] = results[i]
878 continue
879 }
880 if collate.IsBinCollation(columns[i].Ft.GetCollate()) {
881 noPaddingDatum, err := DecodeColumnValue(results[i], columns[i].Ft, nil)
882 if err != nil {
883 return nil, errors.Trace(err)
884 }
885 paddingCountDatum, err := DecodeColumnValue(newResults[i], types.NewFieldType(mysql.TypeLonglong), nil)
886 if err != nil {
887 return nil, errors.Trace(err)
888 }
889 noPaddingStr, paddingCount := noPaddingDatum.GetString(), int(paddingCountDatum.GetInt64())
890 // Skip if padding count is 0.
891 if paddingCount == 0 {
892 newResults[i] = results[i]
893 continue
894 }
895 newDatum := &noPaddingDatum
896 newDatum.SetString(noPaddingStr+strings.Repeat(" ", paddingCount), newDatum.Collation())
897 newResults[i] = newResults[i][:0]
898 newResults[i] = append(newResults[i], rowcodec.BytesFlag)
899 newResults[i] = codec.EncodeBytes(newResults[i], newDatum.GetBytes())
900 }
901 }
902 return newResults, nil
903}
904
905func buildColumnIDOffsets(allCols []rowcodec.ColInfo) map[int64]int {
906 colIDOffsets := make(map[int64]int, len(allCols))

Calls 14

NewByteDecoderFunction · 0.92
IsBinCollationFunction · 0.92
NewFieldTypeFunction · 0.92
EncodeBytesFunction · 0.92
buildColumnIDOffsetsFunction · 0.85
buildRestoredColumnFunction · 0.85
DecodeColumnValueFunction · 0.85
DecodeToBytesNoHandleMethod · 0.80
CollationMethod · 0.80
GetStringMethod · 0.65
GetCollateMethod · 0.45
GetInt64Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…