diff --git a/stmt/stmts/insert.go b/stmt/stmts/insert.go index dcf3e830c6..ff83f31ec3 100644 --- a/stmt/stmts/insert.go +++ b/stmt/stmts/insert.go @@ -199,17 +199,17 @@ func (s *InsertIntoStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) } for i, row := range rows { - // Notes: incompatible with mysql - // MySQL will set last insert id to the first row, as follows: - // `t(id int AUTO_INCREMENT, c1 int, PRIMARY KEY (id))` - // `insert t (c1) values(1),(2),(3);` - // Last insert id will be 1, not 3. if len(s.OnDuplicate) == 0 { txn.SetOption(kv.PresumeKeyNotExists, nil) } h, err := t.AddRecord(ctx, row, recordIDs[i]) txn.DelOption(kv.PresumeKeyNotExists) if err == nil { + // Notes: incompatible with mysql + // MySQL will set last insert id to the first row, as follows: + // `t(id int AUTO_INCREMENT, c1 int, PRIMARY KEY (id))` + // `insert t (c1) values(1),(2),(3);` + // Last insert id will be 1, not 3. variable.GetSessionVars(ctx).SetLastInsertID(uint64(recordIDs[i])) continue } diff --git a/table/table.go b/table/table.go index 932f6bd193..a5044c9e96 100644 --- a/table/table.go +++ b/table/table.go @@ -77,7 +77,7 @@ type Table interface { // Truncate truncates the table. Truncate(ctx context.Context) (err error) - // AddRecord inserts a row into the table. + // AddRecord inserts a row into the table. Is h is 0, it will alloc an unique id inside. AddRecord(ctx context.Context, r []interface{}, h int64) (recordID int64, err error) // UpdateRecord updates a row in the table.