diff options
author | unknown <dlenev@mysql.com> | 2006-06-16 20:21:25 +0400 |
---|---|---|
committer | unknown <dlenev@mysql.com> | 2006-06-16 20:21:25 +0400 |
commit | e08a2b326b143cc5b3dead51f981559aef2c2e95 (patch) | |
tree | 49bb7960457e95a5453761b6d5d335e206cc9265 /mysql-test/t/trigger.test | |
parent | 9b871930a9189cce16b39dc5576f3592a34959ba (diff) | |
download | mariadb-git-e08a2b326b143cc5b3dead51f981559aef2c2e95.tar.gz |
Fix for bug#13479 "REPLACE activates UPDATE trigger, not the DELETE and
INSERT triggers".
In cases when REPLACE was internally executed via update and table had
on update (on delete) triggers defined we exposed the fact that such
optimization used by callng on update (not calling on delete) triggers.
Such behavior contradicts our documentation which describes REPLACE as
INSERT with optional DELETE.
This fix just disables this optimization for tables with on delete triggers.
The optimization is still applied for tables which have on update but have
no on delete triggers, we just don't invoke on update triggers in this case
and thus don't expose information about optimization to user.
Also added test coverage for values returned by ROW_COUNT() function (and
thus for values returned by mysql_affected_rows()) for various forms of
INSERT.
mysql-test/r/insert.result:
Added test for values returned by ROW_COUNT() function (and thus for values
returned by mysql_affected_rows()) for various forms of INSERT. We didn't
have coverage for this before and since this fix touches related code it is
better to add it now.
mysql-test/r/trigger.result:
Adjusted test after fixing bug#13479 "REPLACE activates UPDATE trigger, not
the DELETE and INSERT triggers".
mysql-test/t/insert.test:
Added test for values returned by ROW_COUNT() function (and thus for values
returned by mysql_affected_rows()) for various forms of INSERT. We didn't
have coverage for this before and since this fix touches related code it is
better to add it now.
mysql-test/t/trigger.test:
Adjusted test after fixing bug#13479 "REPLACE activates UPDATE trigger, not
the DELETE and INSERT triggers".
sql/sql_insert.cc:
write_record():
We should not expose that internally we sometimes execute REPLACE
via UPDATE instead of documented INSERT + DELETE pair. So we should not
use this optimization for tables with on delete triggers. OTOH it is ok
to use it for tables which have on update but have no on delete triggers,
we just should not invoke on update triggers in this case.
Diffstat (limited to 'mysql-test/t/trigger.test')
-rw-r--r-- | mysql-test/t/trigger.test | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index a5bd2ba0b38..3743d8f5c76 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -185,24 +185,26 @@ select @log; set @log:= ""; insert ignore t1 values (1, 2); select @log; -# REPLACE: before insert trigger should be called for both records, -# but then for first one update will be executed (and both update -# triggers should fire). For second after insert trigger will be -# called as for usual insert +# INSERT ... ON DUPLICATE KEY UPDATE ... set @log:= ""; -replace t1 values (1, 3), (2, 2); +insert into t1 (id, data) values (1, 3), (2, 2) on duplicate key update data= data + 1; select @log; -# Now let us change table in such way that REPLACE on won't be executed -# using update. -alter table t1 add ts timestamp default now(); +# REPLACE (also test for bug#13479 "REPLACE activates UPDATE trigger, +# not the DELETE and INSERT triggers") +# We define REPLACE as INSERT which DELETEs old rows which conflict with +# row being inserted. So for the first record in statement below we will +# call before insert trigger, then delete will be executed (and both delete +# triggers should fire). Finally after insert trigger will be called. +# For the second record we will just call both on insert triggers. set @log:= ""; -# This REPLACE should be executed via DELETE and INSERT so proper -# triggers should be invoked. -replace t1 (id, data) values (1, 4); +replace t1 values (1, 4), (3, 3); select @log; -# Finally let us test INSERT ... ON DUPLICATE KEY UPDATE ... +# Now we will drop ON DELETE triggers to test REPLACE which is internally +# executed via update +drop trigger t1_bd; +drop trigger t1_ad; set @log:= ""; -insert into t1 (id, data) values (1, 5), (3, 3) on duplicate key update data= data + 2; +replace t1 values (1, 5); select @log; # This also drops associated triggers @@ -531,14 +533,11 @@ alter table t1 add primary key (i); --error 1054 insert into t1 values (3, 4) on duplicate key update k= k + 10; select * from t1; +# The following statement will delete old row and won't +# insert new one since after delete trigger will fail. --error 1054 replace into t1 values (3, 3); select * from t1; -# Change table in such way that REPLACE will delete row -alter table t1 add ts timestamp default now(); ---error 1054 -replace into t1 (i, k) values (3, 13); -select * from t1; # Also drops all triggers drop table t1, t2; @@ -594,11 +593,6 @@ select * from t1; --error 1054 replace into t1 values (2, 4); select * from t1; -# Change table in such way that REPLACE will delete row -alter table t1 add ts timestamp default now(); ---error 1054 -replace into t1 (i, k) values (2, 11); -select * from t1; # Also drops all triggers drop table t1, t2; |