Bug #23233 | NO_AUTO_VALUE_ON_ZERO and INSERT...ON DUPLICATE cause insertion failure | ||
---|---|---|---|
Submitted: | 12 Oct 2006 22:28 | Modified: | 4 Apr 2007 4:03 |
Reporter: | Peter Andrews | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 5.1.11-beta and 5.0.26/5.0BK/5.1BK | OS: | Windows (WINDOWS) |
Assigned to: | Evgeny Potemkin | CPU Architecture: | Any |
Tags: | auto_increment, insert, NO_AUTO_VALUE_ON_ZERO, SQL_MODE |
[12 Oct 2006 22:28]
Peter Andrews
[13 Oct 2006 13:12]
Peter Andrews
Just wanted to make this absolutely clear: this bug only occurs when the SQL_MODE is set to NO_AUTO_VALUE_ON_ZERO at time of function/procedure definition. It does not matter whether it is set during table creation time.
[13 Oct 2006 13:44]
Peter Andrews
replicated the error exactly on 5.0.26
[19 Oct 2006 13:36]
Peter Andrews
Why has no one looked at this bug?
[19 Oct 2006 14:23]
Peter Andrews
I have a suspicion that the NO_AUTO_VALUE_ON_ZERO is not a cause of the bug but instead causes the bug to be unmasked. In other words, the bug has to do with incorrectly inserting a row with id 0. When NO_AUTO_VALUE_ON_ZERO is not set, then the bug would appear not to happen because the insert of id 0 will automatically be changed to insert at the next id.
[19 Oct 2006 14:44]
MySQL Verification Team
Thank you for the bug report. Verfied as described.
[19 Mar 2007 15:26]
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/22278 ChangeSet@1.2477, 2007-03-19 18:24:50+03:00, evgen@moonbone.local +3 -0 Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the NO_AUTO_VALUE_ON_ZERO mode. In the NO_AUTO_VALUE_ON_ZERO mode the table->auto_increment_field_not_null variable is used to indicate that the LAST_INSERT_ID value is set. But the open_table() function doesn't initialize it. When an INSERT .. ON DUPLICATE query that updates the auto_increment field is issued it sets the table->auto_increment_field_not_null variable to TRUE. This makes each subsequent query treat the LAST_INSERT_ID value as already set while it isn't and using 0 as the LAST_INSERT_ID value. Now the open_table() function initializes the table->auto_increment_field_not_null variable at the table opening.
[21 Mar 2007 17:25]
Guilhem Bichot
comments sent by mail
[21 Mar 2007 19:23]
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/22529 ChangeSet@1.2477, 2007-03-21 22:22:12+03:00, evgen@moonbone.local +3 -0 Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the NO_AUTO_VALUE_ON_ZERO mode. In the NO_AUTO_VALUE_ON_ZERO mode the table->auto_increment_field_not_null variable is used to indicate that a non-NULL value was specified by the user for an auto_increment column. When an INSERT .. ON DUPLICATE updates the auto_increment field this variable is set to true and stays unchanged for the next insert operation. This makes the next inserted row to wrongly have 0 as the value of the auto_increment field. Now the write_record() function resets the table->auto_increment_field_not_null variable after inserting or updating a row.
[26 Mar 2007 20:27]
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/22964 ChangeSet@1.2477, 2007-03-27 00:26:08+04:00, evgen@moonbone.local +5 -0 Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the NO_AUTO_VALUE_ON_ZERO mode. In the NO_AUTO_VALUE_ON_ZERO mode the table->auto_increment_field_not_null variable is used to indicate that a non-NULL value was specified by the user for an auto_increment column. When an INSERT .. ON DUPLICATE updates the auto_increment field this variable is set to true and stays unchanged for the next insert operation. This makes the next inserted row sometimes wrongly have 0 as the value of the auto_increment field. Now the fill_record() function resets the table->auto_increment_field_not_null variable before filling the record.
[28 Mar 2007 14:53]
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/23167 ChangeSet@1.2477, 2007-03-28 18:51:21+04:00, evgen@moonbone.local +9 -0 Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the NO_AUTO_VALUE_ON_ZERO mode. In the NO_AUTO_VALUE_ON_ZERO mode the table->auto_increment_field_not_null variable is used to indicate that a non-NULL value was specified by the user for an auto_increment column. When an INSERT .. ON DUPLICATE updates the auto_increment field this variable is set to true and stays unchanged for the next insert operation. This makes the next inserted row sometimes wrongly have 0 as the value of the auto_increment field. Now the fill_record() function resets the table->auto_increment_field_not_null variable before filling the record. The table->auto_increment_field_not_null variable is also reset by the open_table() function for a case if we missed some auto_increment_field_not_null handling bug.
[30 Mar 2007 13:30]
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/23413 ChangeSet@1.2424, 2007-03-30 17:28:15+04:00, evgen@sunlight.local +9 -0 Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the NO_AUTO_VALUE_ON_ZERO mode. In the NO_AUTO_VALUE_ON_ZERO mode the table->auto_increment_field_not_null variable is used to indicate that a non-NULL value was specified by the user for an auto_increment column. When an INSERT .. ON DUPLICATE updates the auto_increment field this variable is set to true and stays unchanged for the next insert operation. This makes the next inserted row sometimes wrongly have 0 as the value of the auto_increment field. Now the fill_record() function resets the table->auto_increment_field_not_null variable before filling the record. The table->auto_increment_field_not_null variable is also reset by the open_table() function for a case if we missed some auto_increment_field_not_null handling bug. Now the table->auto_increment_field_not_null is reset at the end of the mysql_load() function. Reset the table->auto_increment_field_not_null variable after each write_row() call in the copy_data_between_tables() function.
[30 Mar 2007 17:25]
Guilhem Bichot
yes, the patch is approved, provided Evgeny made modifications agreed upon via IRC. Mar 30 16:10:34 <guilhem> your latest cset + your fix (reset after write_record() in read_sep_field/read_fixed_length) + a testcase + a new bug report = approved. where "new bug report" and "your fix" and "a testcase" refer to a new bug found in LOAD DATA INFILE together with Evgeny.
[31 Mar 2007 8:39]
Bugs System
Pushed into 5.1.18-beta
[31 Mar 2007 8:44]
Bugs System
Pushed into 5.0.40
[4 Apr 2007 4:03]
Paul DuBois
Noted in 5.0.40, 5.1.18 changelogs. With the NO_AUTO_VALUE_ON_ZERO SQL mode enabled, LAST_INSERT_ID() could return 0 after INSERT ... ON DUPLICATE KEY UPDATE.