Bug #42994 | REPLACE INTO results in a DUPLICATE KEY error on the AUTO_INCREMENT primary key | ||
---|---|---|---|
Submitted: | 18 Feb 2009 21:47 | Modified: | 19 Feb 2009 23:04 |
Reporter: | Chris Calender | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 5.1.30, 5.1.31 | OS: | Any |
Assigned to: | Assigned Account | CPU Architecture: | Any |
Tags: | auto_increment, duplicate key, innodb, REPLACE |
[18 Feb 2009 21:47]
Chris Calender
[19 Feb 2009 15:02]
Mikhail Izioumtchenko
Sunny, could you have a look? In the meantime could we have the values of autoinc related variables in your testcase, mostly innodb_autoinc_lock_mode, but just in case you could do something like mysqladmin variables | grep auto
[19 Feb 2009 15:46]
Chris Calender
mysql> select version(); +------------------------------------+ | version() | +------------------------------------+ | 5.1.30-enterprise-gpl-advanced-log | +------------------------------------+ 1 row in set (0.00 sec) mysql> show global variables like '%auto%'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | innodb_autoextend_increment | 8 | | innodb_autoinc_lock_mode | 1 | | sql_auto_is_null | ON | +-----------------------------+-------+ 7 rows in set (0.00 sec) mysql> select version(); +--------------------------------+ | version() | +--------------------------------+ | 5.1.31-enterprise-gpl-advanced | +--------------------------------+ 1 row in set (0.00 sec) mysql> show global variables like '%auto%'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 2 | | autocommit | ON | | automatic_sp_privileges | ON | | innodb_autoextend_increment | 8 | | innodb_autoinc_lock_mode | 1 | | sql_auto_is_null | ON | +-----------------------------+-------+ 7 rows in set (0.00 sec) Note the fist os from 5.1.30 and the second from 5.1.31. In 5.1.31, I had to increase auto_increment_offset to 2 to trigger the bug.
[19 Feb 2009 15:58]
Chris Calender
Note: I just tested both 5.1.30 and 5.1.31 with the other values for 'innodb_autoinc_lock_mode'. The tests do not exhibit the bug with 'innodb_autoinc_lock_mode' set to 0 or 2. So thus far, the bug seems to only arise if innodb_autoinc_lock_mode=1 (which is default, btw). "The allowable values are 0, 1, or 2, for “traditional”, “consecutive”, or “interleaved” lock mode, respectively." http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_autoinc_lock_m... http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html
[19 Feb 2009 16:09]
Mikhail Izioumtchenko
Chris, thank you for the information. This sounds in fact something like Sunny fixed recently, maybe the fix is already in the patch pipeline, but I could be wrong. I'm sure Sunny will sort it out in no time.
[19 Feb 2009 20:11]
Mikhail Izioumtchenko
bug#42714 looks similar, but that one isn't fixed yet. 42714 is said not to occur in 5.1.30 but probably just because the testcase is much simpler
[19 Feb 2009 23:04]
Sunny Bains
Hi, This is a duplicate of Bug#42714. I wrote a small C program that spawned 15 threads and each thread continuously did a "REPLACE ..." . No errors or warnings were reported in the 15 minute test. This test was run against the proposed patch for Bug#42714. With the following setting in every worker thread: SET @@SESSION.AUTO_INCREMENT_INCREMENT=1 SET @@SESSION.AUTO_INCREMENT_OFFSET=5 And the variables from the MySQL server were: mysql> show global variables like 'innodb%'; +---------------------------------+------------------------+ | Variable_name | Value | +---------------------------------+------------------------+ | innodb_adaptive_hash_index | ON | | innodb_additional_mem_pool_size | 4194304 | | innodb_autoextend_increment | 8 | | innodb_autoinc_lock_mode | 1 | | innodb_buffer_pool_size | 536870912 | | innodb_checksums | ON | | innodb_commit_concurrency | 0 | | innodb_concurrency_tickets | 500 | | innodb_data_file_path | ibdata1:10M:autoextend | | innodb_data_home_dir | . | | innodb_doublewrite | ON | | innodb_fast_shutdown | 1 | | innodb_file_io_threads | 4 | | innodb_file_per_table | ON | | innodb_flush_log_at_trx_commit | 1 | | innodb_flush_method | O_DIRECT | | innodb_force_recovery | 0 | | innodb_lock_wait_timeout | 50 | | innodb_locks_unsafe_for_binlog | OFF | | innodb_log_buffer_size | 393216 | | innodb_log_file_size | 16777216 | | innodb_log_files_in_group | 2 | | innodb_log_group_home_dir | . | | innodb_max_dirty_pages_pct | 90 | | innodb_max_purge_lag | 0 | | innodb_mirrored_log_groups | 1 | | innodb_open_files | 300 | | innodb_rollback_on_timeout | OFF | | innodb_stats_on_metadata | ON | | innodb_support_xa | ON | | innodb_sync_spin_loops | 20 | | innodb_table_locks | ON | | innodb_thread_concurrency | 8 | | innodb_thread_sleep_delay | 10000 | +---------------------------------+------------------------+ Thanks for the excellent test case. Regards, -sunny