Bug #27650 | ON DUPLICATE KEY UPDATE fails when setting UNIQUE values with multi row inserts | ||
---|---|---|---|
Submitted: | 4 Apr 2007 13:24 | Modified: | 1 May 2007 17:45 |
Reporter: | Mark Leith | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S1 (Critical) |
Version: | 5.0.38, 5.x | OS: | Any |
Assigned to: | Gleb Shchepa | CPU Architecture: | Any |
Tags: | bfsm_2007_04_19, ON DUPLICATE KEY UPDATE |
[4 Apr 2007 13:24]
Mark Leith
[4 Apr 2007 13:31]
Mark Leith
Testcase
Attachment: bug17650_testcase.c (text/plain), 4.61 KiB.
[4 Apr 2007 13:38]
Mark Leith
Second test case, generated word "heartbeat's" seems a problem
Attachment: bug17650_testcase.c (text/plain), 4.60 KiB.
[4 Apr 2007 14:08]
Mark Leith
Hmm.. issues with C testcase. Simplified: drop table if exists `t1`; create table `t1` (`c1` int auto_increment, `c2` int unsigned not null, `c3` varchar(100) not null, counter int not null default 1, primary key (c1), unique key (`c2`, `c3`)) engine = innodb; insert into t1 (c1, c2, c3) values (NULL, 0, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 6, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 6, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 5, 'Tewell'), (NULL, 1, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 2, 'cohosting'), (NULL, 4, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 4, 'cohosting'), (NULL, 4, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 5, 'Tewell') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; select * from t1; mysql> drop table if exists `t1`; Query OK, 0 rows affected (0.11 sec) mysql> create table `t1` (`c1` int auto_increment, `c2` int unsigned not null, `c3` varchar(100) not null, counter int not null default 1, p rimary key (c1), unique key (`c2`, `c3`)) engine = innodb; Query OK, 0 rows affected (0.23 sec) mysql> insert into t1 (c1, c2, c3) values (NULL, 0, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; Query OK, 1 row affected (0.07 sec) mysql> insert into t1 (c1, c2, c3) values (NULL, 6, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; Query OK, 1 row affected (0.03 sec) mysql> insert into t1 (c1, c2, c3) values (NULL, 6, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; Query OK, 2 rows affected (0.02 sec) mysql> insert into t1 (c1, c2, c3) values (NULL, 5, 'Tewell'), (NULL, 1, 'heartbeat') on duplicate key update c1 = values(c1), c2 = values(c 2), counter = counter + 1; Query OK, 3 rows affected (0.03 sec) Records: 2 Duplicates: 1 Warnings: 0 mysql> insert into t1 (c1, c2, c3) values (NULL, 2, 'cohosting'), (NULL, 4, 'heartbeat') on duplicate key update c1 = values(c1), c2 = value s(c2), counter = counter + 1; Query OK, 2 rows affected (0.02 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> insert into t1 (c1, c2, c3) values (NULL, 4, 'cohosting'), (NULL, 4, 'heartbeat') on duplicate key update c1 = values(c1), c2 = value s(c2), counter = counter + 1; Query OK, 3 rows affected (0.02 sec) Records: 2 Duplicates: 1 Warnings: 0 mysql> insert into t1 (c1, c2, c3) values (NULL, 5, 'Tewell') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; ERROR 1062 (23000): Duplicate entry '5-heartbeat' for key 2 mysql> mysql> select * from t1;
[4 Apr 2007 14:23]
MySQL Verification Team
When `t1` is InnoDB, the duplicate key occurs. When `t1` is MyISAM, no error occurs. drop table if exists `t1`; create table `t1` (`c1` int auto_increment, `c2` int unsigned not null, `c3` varchar(100) not null, counter int not null default 1, primary key (c1), unique key (`c2`, `c3`)) engine = innodb; insert into t1 (c1, c2, c3) values (NULL, 1, 'a') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 2, 'a') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 1, 'a') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1; insert into t1 (c1, c2, c3) values (NULL, 2, 'a') on duplicate key update c1 = values(c1), c2 = values(c2), counter = counter + 1;
[4 Apr 2007 14:27]
Mark Leith
Changing to InnoDB category.
[4 Apr 2007 15:45]
Heikki Tuuri
If the bug appears first in 5.0.38, could it be that the fix of: http://bugs.mysql.com/bug.php?id=27210 has broken 5.0.38? Or is this associated: http://bugs.mysql.com/bug.php?id=27033 ? Since InnoDB does not do the actual ON DUPLICATE KEY UPDATE processing at a high level, this is probably a MySQL server bug.
[10 Apr 2007 15:08]
MySQL Verification Team
5.0.36 doesn't show the problem. 5.0.38 does - so this is a regression.
[25 Apr 2007 17:48]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/25432 ChangeSet@1.2461, 2007-04-25 22:56:59+05:00, gshchepa@gshchepa.loc +3 -0 Bug#27650: InnoDB handler doesn't save next autoincrement value after updating of auto_increment column ('auto' in the samples below) with NULL values inside multi-row INSERT via ON DUPLICATE KEY UPDATE using auto=VALUES(auto). InnoDB handler fixed.
[25 Apr 2007 18:26]
Timothy Smith
Gleb, I've spoken with Igor, and we have approval from Heikki (and tacit approval from Sunny), so please do push your fix for this. I've also notified the InnoDB team that we will be pushing our fix for this bug. Thank you, Timothy
[25 Apr 2007 20:15]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/25453 ChangeSet@1.2440, 2007-04-26 01:24:40+05:00, gshchepa@gshchepa.loc +3 -0 Fixed bug #27650: INSERT into InnoDB table may cause "ERROR 1062 (23000): Duplicate entry..." errors or lost records after multi-row INSERT of the form: "INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)", where "id" is an AUTO_INCREMENT column.
[25 Apr 2007 20:52]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/25458 ChangeSet@1.2440, 2007-04-26 02:01:23+05:00, gshchepa@gshchepa.loc +3 -0 Fixed bug #27650: INSERT into InnoDB table may cause "ERROR 1062 (23000): Duplicate entry..." errors or lost records after multi-row INSERT of the form: "INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)", where "id" is an AUTO_INCREMENT column. It happens because InnoDB handler forgets to save next insert id after updating of auto_increment column with new values. As result of that last insert id stored inside InnoDB dictionary tables differs from it's cached thd->next_insert_id value.
[30 Apr 2007 12:58]
Bugs System
Pushed into 5.0.42
[30 Apr 2007 12:59]
Bugs System
Pushed into 5.1.18-beta
[1 May 2007 17:45]
Paul DuBois
Noted in 5.0.42, 5.1.18 changelogs.
[30 Aug 2007 19:13]
Jeremy Cole
Any idea if this regression actually occurred in 5.0.37 or 5.0.38?
[10 Sep 2008 4:17]
James Day
The fix for this bug caused bug #28781. That's fixed in 5.0.48 and 5.1.22 or 23.