summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/insert_update.result14
-rw-r--r--mysql-test/t/insert_update.test16
-rw-r--r--sql/sql_insert.cc26
3 files changed, 43 insertions, 13 deletions
diff --git a/mysql-test/r/insert_update.result b/mysql-test/r/insert_update.result
index b3bca7517f3..20cde86101e 100644
--- a/mysql-test/r/insert_update.result
+++ b/mysql-test/r/insert_update.result
@@ -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;
diff --git a/mysql-test/t/insert_update.test b/mysql-test/t/insert_update.test
index 725fbdb25d7..67108744ec6 100644
--- a/mysql-test/t/insert_update.test
+++ b/mysql-test/t/insert_update.test
@@ -290,3 +290,19 @@ INSERT IGNORE INTO t1 (id,c1) SELECT * FROM t2
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;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index f3ed3ebab24..228fc8860ae 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1404,23 +1404,18 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
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,
@@ -1429,6 +1424,11 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
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;
}
else /* DUP_REPLACE */