MCPcopy Index your code
hub / github.com/pingcap/tidb / TestDecodeIndexKey

Function TestDecodeIndexKey

pkg/tablecodec/tablecodec_test.go:477–509  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

475}
476
477func TestDecodeIndexKey(t *testing.T) {
478 tableID := int64(4)
479 indexID := int64(5)
480 values := []types.Datum{
481 types.NewIntDatum(1),
482 types.NewBytesDatum([]byte("abc")),
483 types.NewFloat64Datum(123.45),
484 // MysqlTime is not supported.
485 // types.NewTimeDatum(types.Time{
486 // Time: types.FromGoTime(time.Now()),
487 // Fsp: 6,
488 // Type: mysql.TypeTimestamp,
489 // }),
490 }
491 valueStrs := make([]string, 0, len(values))
492 for _, v := range values {
493 str, err := v.ToString()
494 if err != nil {
495 str = fmt.Sprintf("%d-%v", v.Kind(), v.GetValue())
496 }
497 valueStrs = append(valueStrs, str)
498 }
499 sc := stmtctx.NewStmtCtxWithTimeZone(time.UTC)
500 encodedValue, err := codec.EncodeKey(sc.TimeZone(), nil, values...)
501 require.NoError(t, err)
502 indexKey := EncodeIndexSeekKey(tableID, indexID, encodedValue)
503
504 decodeTableID, decodeIndexID, decodeValues, err := DecodeIndexKey(indexKey)
505 require.NoError(t, err)
506 require.Equal(t, tableID, decodeTableID)
507 require.Equal(t, indexID, decodeIndexID)
508 require.Equal(t, valueStrs, decodeValues)
509}
510
511func TestCutPrefix(t *testing.T) {
512 key := EncodeTableIndexPrefix(42, 666)

Callers

nothing calls this directly

Calls 12

NewIntDatumFunction · 0.92
NewBytesDatumFunction · 0.92
NewFloat64DatumFunction · 0.92
NewStmtCtxWithTimeZoneFunction · 0.92
EncodeKeyFunction · 0.92
EncodeIndexSeekKeyFunction · 0.85
DecodeIndexKeyFunction · 0.85
TimeZoneMethod · 0.80
ToStringMethod · 0.65
GetValueMethod · 0.65
EqualMethod · 0.65
KindMethod · 0.45

Tested by

no test coverage detected