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

Function TruncateIndexValue

pkg/tablecodec/tablecodec.go:1777–1804  ·  view source on GitHub ↗

TruncateIndexValue truncate one value in the index.

(v *types.Datum, idxCol *model.IndexColumn, tblCol *model.ColumnInfo)

Source from the content-addressed store, hash-verified

1775
1776// TruncateIndexValue truncate one value in the index.
1777func TruncateIndexValue(v *types.Datum, idxCol *model.IndexColumn, tblCol *model.ColumnInfo) {
1778 noPrefixIndex := idxCol.Length == types.UnspecifiedLength
1779 if noPrefixIndex {
1780 return
1781 }
1782 notStringType := v.Kind() != types.KindString && v.Kind() != types.KindBytes
1783 if notStringType {
1784 return
1785 }
1786 colValue := v.GetBytes()
1787 if tblCol.GetCharset() == charset.CharsetBin || tblCol.GetCharset() == charset.CharsetASCII {
1788 // Count character length by bytes if charset is binary or ascii.
1789 if len(colValue) > idxCol.Length {
1790 // truncate value and limit its length
1791 if v.Kind() == types.KindBytes {
1792 v.SetBytes(colValue[:idxCol.Length])
1793 } else {
1794 v.SetString(v.GetString()[:idxCol.Length], tblCol.GetCollate())
1795 }
1796 }
1797 } else if utf8.RuneCount(colValue) > idxCol.Length {
1798 // Count character length by characters for other rune-based charsets, they are all internally encoded as UTF-8.
1799 rs := bytes.Runes(colValue)
1800 truncateStr := string(rs[:idxCol.Length])
1801 // truncate value and limit its length
1802 v.SetString(truncateStr, tblCol.GetCollate())
1803 }
1804}
1805
1806// EncodeHandleInUniqueIndexValue encodes handle in data.
1807func EncodeHandleInUniqueIndexValue(h kv.Handle, isUntouched bool) []byte {

Callers 5

compareIndexDataFunction · 0.92
TryTruncateRestoredDataFunction · 0.92
compareDataMethod · 0.92
buildHandleFromDatumRowFunction · 0.92
TruncateIndexValuesFunction · 0.85

Calls 7

GetStringMethod · 0.65
KindMethod · 0.45
GetBytesMethod · 0.45
GetCharsetMethod · 0.45
SetBytesMethod · 0.45
SetStringMethod · 0.45
GetCollateMethod · 0.45

Tested by

no test coverage detected