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)
| 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. |
| 866 | func 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 | |
| 905 | func buildColumnIDOffsets(allCols []rowcodec.ColInfo) map[int64]int { |
| 906 | colIDOffsets := make(map[int64]int, len(allCols)) |
no test coverage detected
searching dependent graphs…