From c37818c8e6e746c4c9f222a06182e4adc19be6cc Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Jun 2005 11:51:27 +0300 Subject: [PATCH 1/4] ha_innodb.cc: Update the InnoDB internal auto-inc counter in ::write_row() if the statement is a REPLACE that fails in a duplicate key error: REPLACE will handle duplicate key error, and the insert will eventually succeed; note that we did NOT change InnoDB's behavior in an UPDATE, because updating the auto-inc counter in an UPDATE would require a bigger patch (Bug #11005) sql/ha_innodb.cc: Update the InnoDB internal auto-inc counter in ::write_row() if the statement is a REPLACE that fails in a duplicate key error: REPLACE will handle duplicate key error, and the insert will eventually succeed; note that we did NOT change InnoDB's behavior in an UPDATE, because updating the auto-inc counter in an UPDATE would require a bigger patch (Bug #11005) --- sql/ha_innodb.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index ecd7a8d42c2..4ed005874f1 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -3221,6 +3221,23 @@ no_commit: } } + /* A REPLACE command and LOAD DATA INFILE REPLACE handle a duplicate + key error themselves, and we must update the autoinc counter if we are + performing those statements. */ + + if (error == DB_DUPLICATE_KEY && auto_inc_used + && (user_thd->lex->sql_command == SQLCOM_REPLACE + || user_thd->lex->sql_command == SQLCOM_REPLACE_SELECT + || (user_thd->lex->sql_command == SQLCOM_LOAD + && user_thd->lex->duplicates == DUP_REPLACE))) { + + auto_inc = table->next_number_field->val_int(); + + if (auto_inc != 0) { + dict_table_autoinc_update(prebuilt->table, auto_inc); + } + } + innodb_srv_conc_exit_innodb(prebuilt->trx); error = convert_error_code_to_mysql(error, user_thd); From 092389719bc92937b0bb8427fe19b3fb468ec1ec Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Jun 2005 12:27:37 +0300 Subject: [PATCH 2/4] innodb.result, innodb.test: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 mysql-test/t/innodb.test: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 mysql-test/r/innodb.result: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 --- mysql-test/r/innodb.result | 11 +++++++++++ mysql-test/t/innodb.test | 13 ++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index de0bc8d3230..ea634c7447d 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -2457,6 +2457,17 @@ rowid val 1 1 2 2 drop table t1; +create table t1 (rowid int not null auto_increment, val int not null,primary +key (rowid), unique(val)) engine=innodb; +replace into t1 (val) values ('1'),('2'); +replace into t1 (val) values ('1'),('2'); +insert into t1 (val) values ('1'),('2'); +ERROR 23000: Duplicate entry '1' for key 2 +select * from t1; +rowid val +3 1 +4 2 +drop table t1; create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB; insert into t1 (val) values (1); update t1 set a=2 where a=1; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index e2d098618f5..65191f8af8a 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -1350,16 +1350,12 @@ drop table t1; CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb; insert into t1 (b) values (1); -# We shouldn't get the following error ---error 1062 replace into t1 (b) values (2), (1), (3); select * from t1; truncate table t1; insert into t1 (b) values (1); replace into t1 (b) values (2); replace into t1 (b) values (1); -# We shouldn't get the following error ---error 1062 replace into t1 (b) values (3); select * from t1; drop table t1; @@ -1367,24 +1363,23 @@ drop table t1; create table t1 (rowid int not null auto_increment, val int not null,primary key (rowid), unique(val)) engine=innodb; replace into t1 (val) values ('1'),('2'); -# We shouldn't get the following error ---error 1062 replace into t1 (val) values ('1'),('2'); ---error 1062 insert into t1 (val) values ('1'),('2'); +--error 1062 select * from t1; drop table t1; # -# Test that update changes internal auto-increment value +# Test that update does not change internal auto-increment value # create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB; insert into t1 (val) values (1); update t1 set a=2 where a=1; -# We shouldn't get the following error +# We should get the following error because InnoDB does not update the counter --error 1062 insert into t1 (val) values (1); +--error 1062 select * from t1; drop table t1; From 44e96d7d2887483597b84845cf7c1cd6deb7a394 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Jun 2005 12:29:49 +0300 Subject: [PATCH 3/4] innodb.test: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 mysql-test/t/innodb.test: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 --- mysql-test/t/innodb.test | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index 65191f8af8a..7b27d589ec3 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -1364,8 +1364,8 @@ create table t1 (rowid int not null auto_increment, val int not null,primary key (rowid), unique(val)) engine=innodb; replace into t1 (val) values ('1'),('2'); replace into t1 (val) values ('1'),('2'); -insert into t1 (val) values ('1'),('2'); --error 1062 +insert into t1 (val) values ('1'),('2'); select * from t1; drop table t1; @@ -1380,6 +1380,5 @@ update t1 set a=2 where a=1; # We should get the following error because InnoDB does not update the counter --error 1062 insert into t1 (val) values (1); ---error 1062 select * from t1; drop table t1; From e70af5bef09d5aa9e72aaf8146b67128c094da2d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Jun 2005 12:32:39 +0300 Subject: [PATCH 4/4] innodb.result: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 mysql-test/r/innodb.result: Update Monty's tests for AUTO-INC bug #11080 and bug #11005 --- mysql-test/r/innodb.result | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index ea634c7447d..31480e32c16 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -2430,32 +2430,21 @@ drop table t1; CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb; insert into t1 (b) values (1); replace into t1 (b) values (2), (1), (3); -ERROR 23000: Duplicate entry '3' for key 1 select * from t1; a b -1 1 +3 1 +2 2 +4 3 truncate table t1; insert into t1 (b) values (1); replace into t1 (b) values (2); replace into t1 (b) values (1); replace into t1 (b) values (3); -ERROR 23000: Duplicate entry '3' for key 1 select * from t1; a b 3 1 2 2 -drop table t1; -create table t1 (rowid int not null auto_increment, val int not null,primary -key (rowid), unique(val)) engine=innodb; -replace into t1 (val) values ('1'),('2'); -replace into t1 (val) values ('1'),('2'); -ERROR 23000: Duplicate entry '3' for key 1 -insert into t1 (val) values ('1'),('2'); -ERROR 23000: Duplicate entry '1' for key 2 -select * from t1; -rowid val -1 1 -2 2 +4 3 drop table t1; create table t1 (rowid int not null auto_increment, val int not null,primary key (rowid), unique(val)) engine=innodb;