From 31b9145ab3de8813a10937f0894d3e127e78533c Mon Sep 17 00:00:00 2001 From: "evgen@moonbone.local" <> Date: Tue, 20 Mar 2007 00:46:19 +0300 Subject: [PATCH 1/2] sql_insert.cc: Removed wrong fix for the bug#27006. The bug was added by the fix for the bug#19978 and fixed by Monty on 2007/02/21. trigger.test, trigger.result: Corrected test case for the bug#27006. --- mysql-test/r/trigger.result | 11 ++++++----- mysql-test/t/trigger.test | 6 +++--- sql/sql_insert.cc | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index da72973dc52..0a0be41927a 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -1398,18 +1398,19 @@ id val 1 test1 2 test2 INSERT INTO t1 VALUES (2,'test2') ON DUPLICATE KEY UPDATE val=VALUES(val); -INSERT INTO t1 VALUES (3,'test3') ON DUPLICATE KEY UPDATE val=VALUES(val); +INSERT INTO t1 VALUES (2,'test3') ON DUPLICATE KEY UPDATE val=VALUES(val); +INSERT INTO t1 VALUES (3,'test4') ON DUPLICATE KEY UPDATE val=VALUES(val); SELECT * FROM t1; id val 1 test1 -2 test2 -3 test3 +2 test3 +3 test4 SELECT * FROM t2; id val 1 test1 2 test2 -3 test2 -4 test3 +3 test3 +4 test4 DROP TRIGGER trg27006_a_insert; DROP TRIGGER trg27006_a_update; drop table t1,t2; diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index 49b7b527bd9..a01efba11db 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -1700,8 +1700,7 @@ DROP PROCEDURE bug22580_proc_1; DROP PROCEDURE bug22580_proc_2; # -# Bug#27006: AFTER UPDATE triggers not fired with INSERT ... ON DUPLICATE KEY -# UPDATE if the row wasn't actually changed. +# Bug#27006: AFTER UPDATE triggers not fired with INSERT ... ON DUPLICATE # --disable_warnings DROP TRIGGER IF EXISTS trg27006_a_update; @@ -1730,7 +1729,8 @@ INSERT INTO t1(val) VALUES ('test1'),('test2'); SELECT * FROM t1; SELECT * FROM t2; INSERT INTO t1 VALUES (2,'test2') ON DUPLICATE KEY UPDATE val=VALUES(val); -INSERT INTO t1 VALUES (3,'test3') ON DUPLICATE KEY UPDATE val=VALUES(val); +INSERT INTO t1 VALUES (2,'test3') ON DUPLICATE KEY UPDATE val=VALUES(val); +INSERT INTO t1 VALUES (3,'test4') ON DUPLICATE KEY UPDATE val=VALUES(val); SELECT * FROM t1; SELECT * FROM t2; DROP TRIGGER trg27006_a_insert; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index dd08ccef462..d9d32d14321 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1238,19 +1238,19 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) 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, + TRG_ACTION_AFTER, + TRUE)); info->copied++; } - trg_error= (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_UPDATE, - TRG_ACTION_AFTER, - TRUE)); goto ok_or_after_trg_err; } else /* DUP_REPLACE */ From 41c732493e290213f7c078ff47553f092218cc51 Mon Sep 17 00:00:00 2001 From: "evgen@moonbone.local" <> Date: Tue, 20 Mar 2007 01:37:33 +0300 Subject: [PATCH 2/2] sql_insert.cc: After merge fix. --- sql/sql_insert.cc | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 242ae16a5d3..adb5c34fd37 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1262,26 +1262,22 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) compare_record(table)) { info->updated++; + /* + If ON DUP KEY UPDATE updates a row instead of inserting one, it's + like a regular UPDATE statement: it should not affect the value of a + next SELECT LAST_INSERT_ID() or mysql_insert_id(). + Except if LAST_INSERT_ID(#) was in the INSERT query, which is + 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)); + TRG_ACTION_AFTER, TRUE)); info->copied++; } - /* - If ON DUP KEY UPDATE updates a row instead of inserting one, it's - like a regular UPDATE statement: it should not affect the value of a - next SELECT LAST_INSERT_ID() or mysql_insert_id(). - Except if LAST_INSERT_ID(#) was in the INSERT query, which is - 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)); goto ok_or_after_trg_err; }