From d82f06b1e6d5ab537e327eaa56882742e3519150 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Wed, 11 Sep 2024 19:25:18 +0800 Subject: [PATCH] tablecodec: optimize DecodeIndexHandle to avoid unnecessary allocation (#55987) ref pingcap/tidb#43249 --- pkg/tablecodec/tablecodec.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/tablecodec/tablecodec.go b/pkg/tablecodec/tablecodec.go index ffbfe30dc62f0..0e5c4fceaf87e 100644 --- a/pkg/tablecodec/tablecodec.go +++ b/pkg/tablecodec/tablecodec.go @@ -967,9 +967,13 @@ func DecodeIndexKV(key, value []byte, colsLen int, hdStatus HandleStatus, column // DecodeIndexHandle uses to decode the handle from index key/value. func DecodeIndexHandle(key, value []byte, colsLen int) (kv.Handle, error) { - _, b, err := CutIndexKeyNew(key, colsLen) - if err != nil { - return nil, errors.Trace(err) + var err error + b := key[prefixLen+idLen:] + for i := 0; i < colsLen; i++ { + _, b, err = codec.CutOne(b) + if err != nil { + return nil, errors.Trace(err) + } } if len(b) > 0 { return decodeHandleInIndexKey(b)