MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:damien Date:July 16 2007 6:53pm
Subject:bk commit into 5.1 tree (dkatz:1.2559) BUG#29692
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of dkatz. When dkatz 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-07-16 14:53:05-04:00, dkatz@stripped +3 -0
  Bug #29692  	Single row inserts can incorrectly report a huge number of row insertions
  
  This bug was caused by unitialized value that was the result of a bad 5.0 merge.

  sql/sql_class.h@stripped, 2007-07-16 14:53:01-04:00, dkatz@stripped +16 -4
    Readded comments lost in a bad merge.

  sql/sql_insert.cc@stripped, 2007-07-16 14:53:01-04:00, dkatz@stripped +5 -4
    Fixed code to completely initialize (zero) the "COPY_INFO info" var in the same manner as the delayed write code.
    
    Readded a change that was lost in a bad merge.

  tests/mysql_client_test.c@stripped, 2007-07-16 14:53:01-04:00, dkatz@stripped +33 -0
    Test case added for bug#29692.

diff -Nrup a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h	2007-07-09 04:54:21 -04:00
+++ b/sql/sql_class.h	2007-07-16 14:53:01 -04:00
@@ -65,11 +65,23 @@ typedef struct st_user_var_events
 #define RP_LOCK_LOG_IS_ALREADY_LOCKED 1
 #define RP_FORCE_ROTATE               2
 
+/*
+  The COPY_INFO structure is used by INSERT/REPLACE code.
+  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
+  UPDATE code:
+    If a row is inserted then the copied variable is incremented.
+    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
+      new data differs from the old one then the copied and the updated
+      variables are incremented.
+    The touched variable is incremented if a row was touched by the update part
+      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
+      was actually changed or not.
+*/
 typedef struct st_copy_info {
-  ha_rows records;
-  ha_rows deleted;
-  ha_rows updated;
-  ha_rows copied;
+  ha_rows records; /* Number of processed records */
+  ha_rows deleted; /* Number of deleted records */
+  ha_rows updated; /* Number of updated records */
+  ha_rows copied;  /* Number of copied records */
   ha_rows error_count;
   ha_rows touched; /* Number of touched records */
   enum enum_duplicates handle_duplicates;
diff -Nrup a/sql/sql_insert.cc b/sql/sql_insert.cc
--- a/sql/sql_insert.cc	2007-07-06 12:07:01 -04:00
+++ b/sql/sql_insert.cc	2007-07-16 14:53:01 -04:00
@@ -661,7 +661,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
   /*
     Fill in the given fields and dump it to the table file
   */
-  info.records= info.deleted= info.copied= info.updated= 0;
+  bzero((char*) &info,sizeof(info));
   info.ignore= ignore;
   info.handle_duplicates=duplic;
   info.update_fields= &update_fields;
@@ -1421,6 +1421,10 @@ int write_record(THD *thd, TABLE *table,
           goto before_trg_err;
 
         table->file->restore_auto_increment(prev_insert_id);
+        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->ha_table_flags() & HA_PARTIAL_COLUMN_READ) ||
             compare_record(table))
         {
@@ -1448,9 +1452,6 @@ int write_record(THD *thd, TABLE *table,
             handled separately by THD::arg_of_last_insert_id_function.
           */
           insert_id_for_cur_row= table->file->insert_id_for_cur_row= 0;
-          if (table->next_number_field)
-            table->file->adjust_next_insert_id_after_explicit_value(
-              table->next_number_field->val_int());
           trg_error= (table->triggers &&
                       table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
                                                         TRG_ACTION_AFTER, TRUE));
diff -Nrup a/tests/mysql_client_test.c b/tests/mysql_client_test.c
--- a/tests/mysql_client_test.c	2007-07-01 17:54:58 -04:00
+++ b/tests/mysql_client_test.c	2007-07-16 14:53:01 -04:00
@@ -16272,6 +16272,38 @@ static void test_bug27592()
 
 
 /*
+  Bug #29692  	Single row inserts can incorrectly report a huge number of 
+  row insertions
+*/
+
+static void test_bug29692()
+{
+  MYSQL* conn;
+
+  if (!(conn= mysql_init(NULL)))
+  {
+    myerror("test_bug29692 init failed");
+    exit(1);
+  }
+
+  if (!(mysql_real_connect(conn, opt_host, opt_user,
+                           opt_password, opt_db ? opt_db:"test", opt_port,
+                           opt_unix_socket,  CLIENT_FOUND_ROWS)))
+  {
+    myerror("test_bug29692 connection failed");
+    mysql_close(mysql);
+    exit(1);
+  }
+  myquery(mysql_query(conn, "drop table if exists t1"));
+  myquery(mysql_query(conn, "create table t1(f1 int)"));
+  myquery(mysql_query(conn, "insert into t1 values(1)"));
+  DIE_UNLESS(1 == mysql_affected_rows(conn));
+  myquery(mysql_query(conn, "drop table t1"));
+  mysql_close(conn);
+}
+
+
+/*
   Read and parse arguments and MySQL options from my.cnf
 */
 
@@ -16560,6 +16592,7 @@ static struct my_tests_st my_tests[]= {
   { "test_bug28505", test_bug28505 },
   { "test_bug28934", test_bug28934 },
   { "test_bug27592", test_bug27592 },
+  { "test_bug29692", test_bug29692 },
   { 0, 0 }
 };
 
Thread
bk commit into 5.1 tree (dkatz:1.2559) BUG#29692damien16 Jul