Skip to content

Commit

Permalink
fix load data rowCount should added first before call colsToRow(). (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AilinKid authored and winkyao committed Sep 3, 2019
1 parent 1e28af7 commit 7d5971b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion executor/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ func (e *LoadDataInfo) InsertData(prevData, curData []byte) ([]byte, bool, error
if err != nil {
return nil, false, errors.Trace(err)
}
rows = append(rows, e.colsToRow(cols))
// rowCount will be used in fillRow(), last insert ID will be assigned according to the rowCount = 1.
// So should add first here.
e.rowCount++
rows = append(rows, e.colsToRow(cols))
if e.maxRowsInBatch != 0 && e.rowCount%e.maxRowsInBatch == 0 {
reachLimit = true
logutil.Logger(context.Background()).Info("batch limit hit when inserting rows", zap.Int("maxBatchRows", e.maxChunkSize),
Expand Down
4 changes: 2 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func runTestLoadData(c *C, server *Server) {
dbt.Assert(err, IsNil)
lastID, err = rs.LastInsertId()
dbt.Assert(err, IsNil)
dbt.Assert(lastID, Equals, int64(7))
dbt.Assert(lastID, Equals, int64(6))
affectedRows, err = rs.RowsAffected()
dbt.Assert(err, IsNil)
dbt.Assert(affectedRows, Equals, int64(4))
Expand Down Expand Up @@ -466,7 +466,7 @@ func runTestLoadData(c *C, server *Server) {
dbt.Assert(err, IsNil)
lastID, err = rs.LastInsertId()
dbt.Assert(err, IsNil)
dbt.Assert(lastID, Equals, int64(11))
dbt.Assert(lastID, Equals, int64(10))
affectedRows, err = rs.RowsAffected()
dbt.Assert(err, IsNil)
dbt.Assert(affectedRows, Equals, int64(799))
Expand Down

0 comments on commit 7d5971b

Please sign in to comment.