Skip to content

Commit

Permalink
util: support clustered index for table scan (pingcap#17616)
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored Jun 3, 2020
1 parent e5ba8f4 commit 1758f86
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca h1:3fECS8atRjByijiI8yYiuwLwQ2ZxXobW7ua/8GRB3pI=
github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
Expand Down
9 changes: 6 additions & 3 deletions tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ func DecodeTableID(key kv.Key) int64 {

// DecodeRowKey decodes the key and gets the handle.
func DecodeRowKey(key kv.Key) (kv.Handle, error) {
if len(key) != RecordRowKeyLen || !hasTablePrefix(key) || !hasRecordPrefixSep(key[prefixLen-2:]) {
if len(key) < RecordRowKeyLen || !hasTablePrefix(key) || !hasRecordPrefixSep(key[prefixLen-2:]) {
return kv.IntHandle(0), errInvalidKey.GenWithStack("invalid key - %q", key)
}
u := binary.BigEndian.Uint64(key[prefixLen:])
return kv.IntHandle(codec.DecodeCmpUintToInt(u)), nil
if len(key) == RecordRowKeyLen {
u := binary.BigEndian.Uint64(key[prefixLen:])
return kv.IntHandle(codec.DecodeCmpUintToInt(u)), nil
}
return kv.NewCommonHandle(key[prefixLen:])
}

// EncodeValue encodes a go value to bytes.
Expand Down
11 changes: 10 additions & 1 deletion util/rowcodec/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,19 @@ func (decoder *ChunkDecoder) tryAppendHandleColumn(colIdx int, col *ColInfo, han
if handle == nil {
return false
}
if col.ID == decoder.handleColIDs[0] {
if handle.IsInt() && col.ID == decoder.handleColIDs[0] {
chk.AppendInt64(colIdx, handle.IntValue())
return true
}
for i, id := range decoder.handleColIDs {
if col.ID == id {
coder := codec.NewDecoder(chk, decoder.loc)
_, err := coder.DecodeOne(handle.EncodedCol(i), colIdx, col.Ft)
if err != nil {
return false
}
}
}
return false
}

Expand Down

0 comments on commit 1758f86

Please sign in to comment.