From 4a6b093dffbeff215c631fc4e2617c950dc088c5 Mon Sep 17 00:00:00 2001 From: Ewan Chou Date: Sat, 5 Nov 2016 10:04:42 +0800 Subject: [PATCH] table/tables: fix panic (#1952) fix panic --- table/tables/index.go | 5 +++-- table/tables/index_test.go | 3 +++ table/tables/tables.go | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/table/tables/index.go b/table/tables/index.go index c8491241a5..b0711a3eea 100644 --- a/table/tables/index.go +++ b/table/tables/index.go @@ -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] } diff --git a/table/tables/index_test.go b/table/tables/index_test.go index 87528c8da5..e68a56ec52 100644 --- a/table/tables/index_test.go +++ b/table/tables/index_test.go @@ -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) { diff --git a/table/tables/tables.go b/table/tables/tables.go index 6d17f698bc..51f1f121d1 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -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)