List:Commits« Previous MessageNext Message »
From:eugene Date:June 11 2007 11:29pm
Subject:bk commit into 5.0 tree (evgen:1.2529) BUG#28904
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen 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-06-12 01:29:28+04:00, evgen@stripped +3 -0
  Bug#28904: INSERT .. ON DUPLICATE was silently updating rows when it shouldn't.
  
  When the INSERT .. ON DUPLICATE KEY UPDATE has to update a matched row but
  the new data is the same as in the record then it returns as if
  no rows were inserted nor updated. Nevertheless the row was silently
  updated. This leads to a situation when zero updated rows are reported 
  in the case when data has actually been changed.
  
  Now the write_record function updates a row only if new data differs from
  that in the record.

  mysql-test/r/insert_update.result@stripped, 2007-06-12 01:28:31+04:00, evgen@stripped
+14 -0
    Added a test case for the bug#28904: INSERT .. ON DUPLICATE was silently
    updating rows when it shouldn't.

  mysql-test/t/insert_update.test@stripped, 2007-06-12 01:28:42+04:00, evgen@stripped
+16 -0
    Added a test case for the bug#28904: INSERT .. ON DUPLICATE was silently
    updating rows when it shouldn't.

  sql/sql_insert.cc@stripped, 2007-06-12 01:28:09+04:00, evgen@stripped +13 -13
    Bug#28904: INSERT .. ON DUPLICATE was silently updating rows when it shouldn't.
    Now the write_record function updates a row only if new data differs from
    that in the record.

# 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:	evgen
# Host:	moonbone.local
# Root:	/mnt/gentoo64/work/test-5.0-opt-mysql

--- 1.240/sql/sql_insert.cc	2007-06-07 00:29:51 +04:00
+++ 1.241/sql/sql_insert.cc	2007-06-12 01:28:09 +04:00
@@ -1404,23 +1404,18 @@ int write_record(THD *thd, TABLE *table,
           goto before_trg_err;
 
         table->file->restore_auto_increment();
-        if
((error=table->file->update_row(table->record[1],table->record[0])))
+        if ((table->file->table_flags() & HA_PARTIAL_COLUMN_READ) ||
+            compare_record(table, thd->query_id))
         {
-          if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore)
+          if
((error=table->file->update_row(table->record[1],table->record[0])))
           {
-            goto ok_or_after_trg_err;
+            if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore)
+            {
+              goto ok_or_after_trg_err;
+            }
+            goto err;
           }
-          goto err;
-        }
-
-        if (table->next_number_field)
-          table->file->adjust_next_insert_id_after_explicit_value(
-            table->next_number_field->val_int());
-        info->touched++;
 
-        if ((table->file->table_flags() & HA_PARTIAL_COLUMN_READ) ||
-            compare_record(table, thd->query_id))
-        {
           info->updated++;
           trg_error= (table->triggers &&
                       table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
@@ -1428,6 +1423,11 @@ int write_record(THD *thd, TABLE *table,
                                                         TRUE));
           info->copied++;
         }
+
+        if (table->next_number_field)
+          table->file->adjust_next_insert_id_after_explicit_value(
+            table->next_number_field->val_int());
+        info->touched++;
 
         goto ok_or_after_trg_err;
       }

--- 1.27/mysql-test/r/insert_update.result	2007-05-30 16:04:02 +04:00
+++ 1.28/mysql-test/r/insert_update.result	2007-06-12 01:28:31 +04:00
@@ -393,3 +393,17 @@ id	c1	cnt
 1	0	3
 2	2	1
 DROP TABLE t1;
+create table t1(f1 int primary key,
+f2 timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP);
+insert into t1(f1) values(1);
+select @stamp1:=f2 from t1;
+@stamp1:=f2
+#
+insert into t1(f1) values(1) on duplicate key update f1=1;
+select @stamp2:=f2 from t1;
+@stamp2:=f2
+#
+select if( @stamp1 = @stamp2, "correct", "wrong");
+if( @stamp1 = @stamp2, "correct", "wrong")
+correct
+drop table t1;

--- 1.26/mysql-test/t/insert_update.test	2007-05-11 02:13:29 +04:00
+++ 1.27/mysql-test/t/insert_update.test	2007-06-12 01:28:42 +04:00
@@ -290,3 +290,19 @@ INSERT IGNORE INTO t1 (id,c1) SELECT * F
 SELECT * FROM t1;
 
 DROP TABLE t1;
+
+#
+# Bug#28904: INSERT .. ON DUPLICATE was silently updating rows when it
+#            shouldn't.
+#
+create table t1(f1 int primary key,
+ f2 timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP);
+insert into t1(f1) values(1);
+--replace_column 1 #
+select @stamp1:=f2 from t1;
+--sleep 2
+insert into t1(f1) values(1) on duplicate key update f1=1;
+--replace_column 1 #
+select @stamp2:=f2 from t1;
+select if( @stamp1 = @stamp2, "correct", "wrong");
+drop table t1;
Thread
bk commit into 5.0 tree (evgen:1.2529) BUG#28904eugene11 Jun