mariadb/mysql-test/suite/innodb/t/auto_increment_dup.test

166 lines
3.5 KiB
Text
Raw Normal View History

This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
##########################################################################
# LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE +
# innodb_autoinc_lock_mode=1 is broken
##########################################################################
--source include/have_innodb.inc
--source include/have_debug.inc
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
--source include/have_debug_sync.inc
--source include/innodb_binlog.inc
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
let $stmt= `SELECT @@GLOBAL.log_bin`;
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
set global transaction isolation level repeatable read;
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
CREATE TABLE t1(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
k INT,
c CHAR(1),
UNIQUE KEY(k)) ENGINE=InnoDB;
SHOW CREATE TABLE t1;
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
--enable_info
--echo #
--echo # Sequential execution
--echo #
INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1';
--echo #
--echo # 1 duplicate
--echo #
INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
--echo #
--echo # 5 rows, consecutive auto_inc values
--echo #
SELECT * FROM t1 order by k;
DROP TABLE t1;
CREATE TABLE t1(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
k INT,
c CHAR(1),
UNIQUE KEY(k)) ENGINE=InnoDB;
--echo #
--echo # Sequential execution 2
--echo #
INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
--echo #
--echo # 1 duplicate
--echo #
INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1';
--echo #
--echo # 5 rows, consecutive auto_inc values
--echo #
SELECT * FROM t1 order by k;
DROP TABLE t1;
CREATE TABLE t1(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
k INT,
c CHAR(1),
UNIQUE KEY(k)) ENGINE=InnoDB;
--echo #
--echo # Parallel execution
--echo #
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
--connect(con2, localhost, root)
--send SET DEBUG_SYNC='now WAIT_FOR write_row_done'
--connect(con1, localhost, root)
SET DEBUG_SYNC='ha_write_row_end SIGNAL write_row_done WAIT_FOR continue';
--send INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1'
--connection con2
--reap
SET DEBUG_SYNC='execute_command_after_close_tables SIGNAL continue';
if ($stmt) {
--error ER_LOCK_WAIT_TIMEOUT
INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
}
if (!$stmt) {
INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
}
--connection con1
--echo #
--echo # 2 duplicates
--echo #
--reap
--connection default
--echo #
--echo # 3 rows
--echo #
SELECT * FROM t1 order by k;
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
SELECT * FROM t1 order by k;
--disable_info
--disconnect con1
--disconnect con2
--connection default
DROP TABLE t1;
--echo #
--echo # Parallel test with read_committed
--echo #
set global transaction isolation level read committed;
--disable_warnings
drop table if exists t1;
--enable_warnings
CREATE TABLE t1(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
k INT,
c CHAR(1),
UNIQUE KEY(k)) ENGINE=InnoDB;
--enable_info
--connect(con1, localhost, root)
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
SET DEBUG_SYNC='ha_write_row_end SIGNAL continue2 WAIT_FOR continue1';
--send INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1'
--connect(con2, localhost, root)
SET DEBUG_SYNC='ha_write_row_start WAIT_FOR continue2';
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
SET DEBUG_SYNC='after_mysql_insert SIGNAL continue1';
INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
--disconnect con2
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
--connection con1
--reap
--disable_info
SET DEBUG_SYNC='RESET';
--echo #
--echo # 5 rows, gap in autoinc values
--echo #
This fix+comments was originally made by Alexey Kopytov LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE + innodb_autoinc_lock_mode=1 is broken The problem was that when certain INSERT ... ON DUPLICATE KEY UPDATE were executed concurrently on a table containing an AUTO_INCREMENT column as a primary key, InnoDB would correctly reserve non-overlapping AUTO_INCREMENT intervals for each statement, but when the server encountered the first duplicate key error on the secondary key in one of the statements and performed an UPDATE, it also updated the internal AUTO_INCREMENT value to the one from the existing row that caused a duplicate key error, even though the AUTO_INCREMENT value was not specified explicitly in the UPDATE clause. It would then proceed with using AUTO_INCREMENT values the range reserved previously by another statement, causing duplicate key errors on the AUTO_INCREMENT column. Fixed by changing write_record() to ensure that in case of a duplicate key error the internal AUTO_INCREMENT counter is only updated when the AUTO_INCREMENT value was explicitly updated by the UPDATE clause. Otherwise it is restored to what it was before the duplicate key error, as that value is unused and can be reused for subsequent successfully inserted rows. sql/sql_insert.cc: Don't update next_insert_id to the value of a row found during ON DUPLICATE KEY UPDATE. sql/sql_parse.cc: Added DBUG_SYNC sql/table.h: Added next_number_field_updated flag to detect changing of auto increment fields. Moved fields a bit to get bool fields after each other (better alignment)
2012-09-18 23:34:16 +03:00
SELECT * FROM t1 ORDER BY k;
--disconnect con1
--connection default
DROP TABLE t1;
set global transaction isolation level repeatable read;