Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Jul 29, 2020
1 parent e53603e commit 67a0c89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion executor/batch_point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error {
keys := make([]kv.Key, 0, len(e.idxVals))
for _, idxVals := range e.idxVals {
physID := getPhysID(e.tblInfo, idxVals[e.partPos].GetInt64())
idxKey, err1 := encodeIndexKey(e.base(), e.tblInfo, e.idxInfo, idxVals, physID)
idxKey, nonExist, err1 := encodeIndexKey(e.base(), e.tblInfo, e.idxInfo, idxVals, physID)
if nonExist {
continue
}
if err1 != nil && !kv.ErrNotExist.Equal(err1) {
return err1
}
Expand Down
18 changes: 11 additions & 7 deletions executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ func (e *PointGetExecutor) Next(ctx context.Context, req *chunk.Chunk) error {
tblID = e.tblInfo.ID
}
if e.idxInfo != nil {
e.idxKey, err = encodeIndexKey(e.base(), e.tblInfo, e.idxInfo, e.idxVals, tblID)
nonExist := false
e.idxKey, nonExist, err = encodeIndexKey(e.base(), e.tblInfo, e.idxInfo, e.idxVals, tblID)
if nonExist {
return nil
}
if err != nil && !kv.ErrNotExist.Equal(err) {
return err
}
Expand Down Expand Up @@ -299,11 +303,11 @@ func (e *PointGetExecutor) get(ctx context.Context, key kv.Key) ([]byte, error)
return e.snapshot.Get(ctx, key)
}

func encodeIndexKey(e *baseExecutor, tblInfo *model.TableInfo, idxInfo *model.IndexInfo, idxVals []types.Datum, tID int64) (_ []byte, err error) {
func encodeIndexKey(e *baseExecutor, tblInfo *model.TableInfo, idxInfo *model.IndexInfo, idxVals []types.Datum, tID int64) (_ []byte, nonExisted bool, err error) {
sc := e.ctx.GetSessionVars().StmtCtx
for i := range idxVals {
if idxVals[i].IsNull() {
continue
return nil, true, nil
}
colInfo := tblInfo.Columns[idxInfo.Columns[i].Offset]
// table.CastValue will append 0x0 if the string value's length is smaller than the BINARY column's length.
Expand All @@ -316,19 +320,19 @@ func encodeIndexKey(e *baseExecutor, tblInfo *model.TableInfo, idxInfo *model.In
} else {
idxVals[i], err = table.CastValue(e.ctx, idxVals[i], colInfo, true, false)
if types.ErrOverflow.Equal(err) {
return nil, kv.ErrNotExist
return nil, false, kv.ErrNotExist
}
}
if err != nil {
return nil, err
return nil, false, err
}
}

encodedIdxVals, err := codec.EncodeKey(sc, nil, idxVals...)
if err != nil {
return nil, err
return nil, false, err
}
return tablecodec.EncodeIndexSeekKey(tID, idxInfo.ID, encodedIdxVals), nil
return tablecodec.EncodeIndexSeekKey(tID, idxInfo.ID, encodedIdxVals), false, nil
}

func decodeRowValToChunk(e *baseExecutor, tblInfo *model.TableInfo, handle int64, rowVal []byte, chk *chunk.Chunk, rd *rowcodec.ChunkDecoder) error {
Expand Down

0 comments on commit 67a0c89

Please sign in to comment.