Skip to content

Commit

Permalink
Speed up decoding column id (#10188)
Browse files Browse the repository at this point in the history
* codec: speed up decoding column id by removing a redundant decoding of varint

* add a comment for skipped flag
  • Loading branch information
ngaut authored Apr 18, 2019
1 parent a19f4d6 commit 1c63151
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,25 +372,23 @@ func CutRowNew(data []byte, colIDs map[int64]int) ([][]byte, error) {
cnt int
b []byte
err error
cid int64
)
row := make([][]byte, len(colIDs))
for len(data) > 0 && cnt < len(colIDs) {
// Get col id.
b, data, err = codec.CutOne(data)
if err != nil {
return nil, errors.Trace(err)
}
_, cid, err := codec.DecodeOne(b)
data, cid, err = codec.CutColumnID(data)
if err != nil {
return nil, errors.Trace(err)
}

// Get col value.
b, data, err = codec.CutOne(data)
if err != nil {
return nil, errors.Trace(err)
}
id := cid.GetInt64()
offset, ok := colIDs[id]

offset, ok := colIDs[cid]
if ok {
row[offset] = b
cnt++
Expand Down
11 changes: 11 additions & 0 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ func CutOne(b []byte) (data []byte, remain []byte, err error) {
return b[:l], b[l:], nil
}

// CutColumnID cuts the column ID from b.
// It will return the remains as byte slice and column ID
func CutColumnID(b []byte) (remain []byte, n int64, err error) {
if len(b) < 1 {
return nil, 0, errors.New("invalid encoded key")
}
// skip the flag
b = b[1:]
return DecodeVarint(b)
}

// SetRawValues set raw datum values from a row data.
func SetRawValues(data []byte, values []types.Datum) error {
for i := 0; i < len(values); i++ {
Expand Down

0 comments on commit 1c63151

Please sign in to comment.