Bug #14887 | Allow Insert Trigger to call simple UPDATE on same table trigger is based | ||
---|---|---|---|
Submitted: | 11 Nov 2005 21:33 | Modified: | 15 Dec 2010 10:33 |
Reporter: | Kirk Smith | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server | Severity: | S4 (Feature request) |
Version: | 5.0.15-standard-log | OS: | Linux (Linux) |
Assigned to: | CPU Architecture: | Any |
[11 Nov 2005 21:33]
Kirk Smith
[16 Oct 2008 15:45]
Marques Johansson
This is still a problem in 5.0.62. http://dev.mysql.com/doc/refman/5.0/en/stored-program-restrictions.html says: - Within a stored function or trigger, it is not permitted to modify a table that is already being used (for reading or writing) by the statement that invoked the function or trigger. I assume this is caused by the table lock and a naivety about who is asking to perform the modification while the table is locked. Couldn't this be resolved by making the currently locked table (the source of the trigger) available with a special table name (eg. self, target, source, this_trigger_table)? But if that could be done I would imagine it wouldn't be much more complicated to allow the trigger's table name to be used. My illustration of the problem is a bit simpler: CREATE TABLE `user_affiliate` ( `user_id` int(10) unsigned NOT NULL, `affiliate_id` int(10) unsigned NOT NULL, `created` timestamp NOT NULL default CURRENT_TIMESTAMP, `expired` timestamp NULL default NULL, PRIMARY KEY (`id`), ) ENGINE=InnoDB COMMENT='store single affiliate for user during time range' create trigger user_affiliate_expire before insert on user_affiliate for each row update user_affiliate ua set ua.expired=DATE_SUB(NEW.created, INTERVAL 1 SECOND) where ua.expired is null and ua.user_id=NEW.user_id; insert into user_affiliate (user_id,avc_user_id,created) values (1,2000,now()); ERROR 1442 (HY000): Can't update table 'user_affiliate' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. I can understand blocking an INSERT trigger from calling an UPDATE that has a trigger that executes an INSERT, but because the trigger and modification operations differ here, I expect this to work.
[15 Dec 2010 10:33]
Valeriy Kravchuk
Let's call this a duplicate (special case) of Bug #29542.