Skip to content

Commit

Permalink
table/tables: fix panic (pingcap#1952)
Browse files Browse the repository at this point in the history
fix panic
  • Loading branch information
coocood authored Nov 5, 2016
1 parent 98c5d52 commit 4a6b093
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions table/tables/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ func (c *index) Exist(rm kv.RetrieverMutator, indexedValues []types.Datum, h int
func (c *index) FetchValues(r []types.Datum) ([]types.Datum, error) {
vals := make([]types.Datum, len(c.idxInfo.Columns))
for i, ic := range c.idxInfo.Columns {
if ic.Offset < 0 || ic.Offset > len(r) {
return nil, table.ErrIndexOutBound.Gen("Index column offset out of bound")
if ic.Offset < 0 || ic.Offset >= len(r) {
return nil, table.ErrIndexOutBound.Gen("Index column %s offset out of bound, offset: %d, row: %v",
ic.Name, ic.Offset, r)
}
vals[i] = r[ic.Offset]
}
Expand Down
3 changes: 3 additions & 0 deletions table/tables/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func (s *testIndexSuite) TestIndex(c *C) {

err = txn.Commit()
c.Assert(err, IsNil)

_, err = index.FetchValues(make([]types.Datum, 0))
c.Assert(err, NotNil)
}

func (s *testIndexSuite) TestCombineIndexSeek(c *C) {
Expand Down
5 changes: 4 additions & 1 deletion table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ func (t *Table) addIndices(ctx context.Context, recordID int64, r []types.Datum,
// if index is in delete only or delete reorganization state, we can't add it.
continue
}
colVals, _ := v.FetchValues(r)
colVals, err2 := v.FetchValues(r)
if err2 != nil {
return 0, errors.Trace(err2)
}
var dupKeyErr error
if v.Meta().Unique || v.Meta().Primary {
entryKey, err1 := t.genIndexKeyStr(colVals)
Expand Down

0 comments on commit 4a6b093

Please sign in to comment.