From: Date: February 6 2007 10:46pm Subject: bk commit into 5.0 tree (evgen:1.2403) BUG#19978 List-Archive: http://lists.mysql.com/commits/19450 X-Bug: 19978 Message-Id: <20070206214606.42A9D22D1D1@moonbone.moonbone.local> 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-02-07 00:46:03+03:00, evgen@stripped +5 -0 Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were updated. INSERT ... ON DUPLICATE KEY UPDATE reports that a record was updated when the duplicate key occurs even if the record wasn't actually changed because the update values are the same as those in the record. Now the compare_record() function is used to check whether the record was changed and the update of a record reported only if the record differs from the original one. mysql-test/r/insert_select.result@stripped, 2007-02-07 00:45:39+03:00, evgen@stripped +12 -0 Added a test case for bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were updated. mysql-test/t/insert_select.test@stripped, 2007-02-07 00:45:19+03:00, evgen@stripped +13 -0 Added a test case for bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were updated. sql/mysql_priv.h@stripped, 2007-02-07 00:45:00+03:00, evgen@stripped +1 -0 Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were updated. Added the prototype of the compare_record() function. sql/sql_insert.cc@stripped, 2007-02-07 00:44:35+03:00, evgen@stripped +16 -10 Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were updated. Now the compare_record() function is used to check whether the record was changed and the update of a record reported only if the record differs from the original one. sql/sql_update.cc@stripped, 2007-02-07 00:44:19+03:00, evgen@stripped +1 -1 Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were updated. The compare_record() function was changed to non-static one. # 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/19978-bug-5.0-opt-mysql --- 1.432/sql/mysql_priv.h 2007-01-31 17:12:41 +03:00 +++ 1.433/sql/mysql_priv.h 2007-02-07 00:45:00 +03:00 @@ -701,6 +701,7 @@ char* packet, uint packet_length); void log_slow_statement(THD *thd); bool check_dup(const char *db, const char *name, TABLE_LIST *tables); +bool compare_record(TABLE *table, query_id_t query_id); bool table_cache_init(void); void table_cache_free(void); --- 1.214/sql/sql_insert.cc 2007-01-23 13:04:15 +03:00 +++ 1.215/sql/sql_insert.cc 2007-02-07 00:44:35 +03:00 @@ -1186,23 +1186,29 @@ goto before_trg_err; if ((error=table->file->update_row(table->record[1],table->record[0]))) - { - if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore) + { + if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore) { table->file->restore_auto_increment(); goto ok_or_after_trg_err; } goto err; - } - info->updated++; + } + if ((table->file->table_flags() & HA_PARTIAL_COLUMN_READ) || + compare_record(table, query_id)) + { + info->updated++; - if (table->next_number_field) - table->file->adjust_next_insert_id_after_explicit_value(table->next_number_field->val_int()); + 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)); - info->copied++; + trg_error= (table->triggers && + table->triggers->process_triggers(thd, TRG_EVENT_UPDATE, + TRG_ACTION_AFTER, + TRUE)); + info->copied++; + } goto ok_or_after_trg_err; } else /* DUP_REPLACE */ --- 1.210/sql/sql_update.cc 2007-01-26 15:36:48 +03:00 +++ 1.211/sql/sql_update.cc 2007-02-07 00:44:19 +03:00 @@ -26,7 +26,7 @@ /* Return 0 if row hasn't changed */ -static bool compare_record(TABLE *table, query_id_t query_id) +bool compare_record(TABLE *table, query_id_t query_id) { if (table->s->blob_fields + table->s->varchar_fields == 0) return cmp_record(table,record[1]); --- 1.42/mysql-test/r/insert_select.result 2006-11-13 19:06:41 +03:00 +++ 1.43/mysql-test/r/insert_select.result 2007-02-07 00:45:39 +03:00 @@ -705,3 +705,15 @@ INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1; DROP DATABASE bug21774_1; DROP DATABASE bug21774_2; +USE test; +create table t1(f1 int primary key, f2 int); +insert into t1 values (1,1); +affected rows: 1 +insert into t1 values (1,1) on duplicate key update f2=1; +affected rows: 0 +insert into t1 values (1,1) on duplicate key update f2=2; +affected rows: 2 +select * from t1; +f1 f2 +1 2 +drop table t1; --- 1.34/mysql-test/t/insert_select.test 2006-11-13 19:06:41 +03:00 +++ 1.35/mysql-test/t/insert_select.test 2007-02-07 00:45:19 +03:00 @@ -265,4 +265,17 @@ DROP DATABASE bug21774_1; DROP DATABASE bug21774_2; +USE test; +# +# Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were +# updated. +# +create table t1(f1 int primary key, f2 int); +--enable_info +insert into t1 values (1,1); +insert into t1 values (1,1) on duplicate key update f2=1; +insert into t1 values (1,1) on duplicate key update f2=2; +--disable_info +select * from t1; +drop table t1;