MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:<gshchepa Date:April 25 2007 9:01pm
Subject:bk commit into 5.0 tree (gshchepa:1.2440) BUG#27650
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of uchum. When uchum does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-04-26 02:01:23+05:00, gshchepa@stripped +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.

  mysql-test/r/innodb_mysql.result@stripped, 2007-04-26 02:01:11+05:00, gshchepa@stripped +39 -0
    Added a test case for bug #27650.

  mysql-test/t/innodb_mysql.test@stripped, 2007-04-26 02:00:53+05:00, gshchepa@stripped +47 -0
    Added a test case for bug #27650.

  sql/ha_innodb.cc@stripped, 2007-04-26 02:00:18+05:00, gshchepa@stripped +2 -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.
    ha_innobase::write_row() function has been corrected.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gshchepa
# Host:	gshchepa.loc
# Root:	/home/uchum/work/bk-trees/mysql-5.0-opt-27650

--- 1.16/mysql-test/r/innodb_mysql.result	2007-02-11 11:55:54 +04:00
+++ 1.17/mysql-test/r/innodb_mysql.result	2007-04-26 02:01:11 +05:00
@@ -446,4 +446,43 @@ a
 2
 5
 drop table t1;
+create table t1(
+id int auto_increment,
+c char(1) not null,
+counter int not null default 1,
+primary key (id),
+unique key (c)
+) engine=innodb;
+insert into t1 (id, c) values
+(NULL, 'a'),
+(NULL, 'a')
+on duplicate key update id = values(id), counter = counter + 1;
+select * from t1;
+id	c	counter
+2	a	2
+insert into t1 (id, c) values
+(NULL, 'b')
+on duplicate key update id = values(id), counter = counter + 1;
+select * from t1;
+id	c	counter
+2	a	2
+3	b	1
+truncate table t1;
+insert into t1 (id, c) values (NULL, 'a');
+select * from t1;
+id	c	counter
+1	a	1
+insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
+on duplicate key update id = values(id), c = values(c), counter = counter + 1;
+select * from t1;
+id	c	counter
+1	a	1
+3	b	2
+insert into t1 (id, c) values (NULL, 'a')
+on duplicate key update id = values(id), c = values(c), counter = counter + 1;
+select * from t1;
+id	c	counter
+3	b	2
+4	a	2
+drop table t1;
 End of 5.0 tests

--- 1.16/mysql-test/t/innodb_mysql.test	2007-02-11 11:55:54 +04:00
+++ 1.17/mysql-test/t/innodb_mysql.test	2007-04-26 02:00:53 +05:00
@@ -412,4 +412,51 @@ DROP TABLE t1;
 
 --source include/innodb_rollback_on_timeout.inc
 
+
+-- source include/have_innodb.inc
+
+#
+# Bug #27650: INSERT fails after multi-row INSERT of the form:
+# INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)
+#
+
+create table t1(
+id int auto_increment,
+c char(1) not null,
+counter int not null default 1,
+primary key (id),
+unique key (c)
+) engine=innodb;
+
+insert into t1 (id, c) values
+(NULL, 'a'),
+(NULL, 'a')
+on duplicate key update id = values(id), counter = counter + 1;
+
+select * from t1;
+
+insert into t1 (id, c) values
+(NULL, 'b')
+on duplicate key update id = values(id), counter = counter + 1;
+
+select * from t1;
+
+truncate table t1;
+
+insert into t1 (id, c) values (NULL, 'a');
+
+select * from t1;
+
+insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
+on duplicate key update id = values(id), c = values(c), counter = counter + 1;
+
+select * from t1;
+
+insert into t1 (id, c) values (NULL, 'a')
+on duplicate key update id = values(id), c = values(c), counter = counter + 1;
+
+select * from t1;
+
+drop table t1;
+
 --echo End of 5.0 tests

--- 1.311/sql/ha_innodb.cc	2007-04-12 14:46:05 +05:00
+++ 1.312/sql/ha_innodb.cc	2007-04-26 02:00:18 +05:00
@@ -3299,6 +3299,8 @@ no_commit:
         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_INSERT
+                    && user_thd->lex->duplicates == DUP_UPDATE)
                 || (user_thd->lex->sql_command == SQLCOM_LOAD
                     && user_thd->lex->duplicates == DUP_REPLACE))) {
 
Thread
bk commit into 5.0 tree (gshchepa:1.2440) BUG#27650gshchepa25 Apr