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

Function DecodeRecordKey

pkg/tablecodec/tablecodec.go:143–177  ·  view source on GitHub ↗

DecodeRecordKey decodes the key and gets the tableID, handle.

(key kv.Key)

Source from the content-addressed store, hash-verified

141
142// DecodeRecordKey decodes the key and gets the tableID, handle.
143func DecodeRecordKey(key kv.Key) (tableID int64, handle kv.Handle, err error) {
144 if len(key) <= prefixLen {
145 return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q", key)
146 }
147
148 k := key
149 if !hasTablePrefix(key) {
150 return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q", k)
151 }
152
153 key = key[tablePrefixLength:]
154 key, tableID, err = codec.DecodeInt(key)
155 if err != nil {
156 return 0, nil, errors.Trace(err)
157 }
158
159 if !hasRecordPrefixSep(key) {
160 return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q", k)
161 }
162
163 key = key[recordPrefixSepLength:]
164 if len(key) == 8 {
165 var intHandle int64
166 key, intHandle, err = codec.DecodeInt(key)
167 if err != nil {
168 return 0, nil, errors.Trace(err)
169 }
170 return tableID, kv.IntHandle(intHandle), nil
171 }
172 h, err := kv.NewCommonHandle(key)
173 if err != nil {
174 return 0, nil, errInvalidRecordKey.GenWithStack("invalid record key - %q %v", k, err)
175 }
176 return tableID, h, nil
177}
178
179// DecodeIndexKey decodes the key and gets the tableID, indexID, indexValues.
180func DecodeIndexKey(key kv.Key) (tableID int64, indexID int64, indexValues []string, err error) {

Callers 14

decodeRecordKeyMethod · 0.92
prettyWriteKeyFunction · 0.92
TestRowKeyCodecFunction · 0.92
deleteDanglingIdxMethod · 0.92
BackfillDataMethod · 0.92
getAllDataForTableIDFunction · 0.92
TestShardRowIdFunction · 0.92
nextKeyFunction · 0.92

Calls 5

DecodeIntFunction · 0.92
IntHandleTypeAlias · 0.92
NewCommonHandleFunction · 0.92
hasTablePrefixFunction · 0.85
hasRecordPrefixSepFunction · 0.85

Tested by 4

TestRowKeyCodecFunction · 0.74
getAllDataForTableIDFunction · 0.74
TestShardRowIdFunction · 0.74
TestRecordKeyFunction · 0.68