Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

The Manual says: http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html

Currently, cascaded foreign key actions do not activate triggers.

Any Idea when will this be implemented.

Is there a work around for this?

share|improve this question

closed as not constructive by Derek Downey, Max Vernon, Mark Storey-Smith, Jon Seigel, dezso Apr 11 at 10:53

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

2 Answers

up vote 3 down vote accepted

Not to start a flamewar, but this does work in PostgreSQL for years. When using innoDB, it should be relative simple to move to PostgreSQL.

share|improve this answer
1  
I was thinking the same thing, but was afraid to give such an answer ;) – a_horse_with_no_name Apr 22 '12 at 16:35
I have a PostgreSQL db for some data.. for which there is better support on PostgreSQL. Will give the moving a thought. Thanks. – ThinkingMonkey Apr 22 '12 at 17:09
@a_horse_with_no_name The move to PostgreSQL has been done. :) – ThinkingMonkey Aug 7 '12 at 10:05

IMHO I do not think this feature will be implemented in the foreseeable future. Why?

Triggers are, by nature, stored procedures. Their actions are virtually hard to roll back. Even if all underlying tables are InnoDB, you will experience a proportional volume of shared row locks and annoying intermittency from exclusive row locks. Such would be the case if triggers were manipulating tables with INSERTs and UPDATEs being stagnated to perform heavy duty MVCC inside each call to a trigger.

Always keep in mind that a Trigger can require major overhead. In fact, According to this book

enter image description here

MySQL Stored Procedure Programming, page 256 under the heading "Trigger Overhead" says the following:

It is important to remember that, by necessity, triggers add overhead to the DML statement to which they apply. the actual amount of overhead will depend upon the nature of the trigger, but --- as all MySQL triggers execute FOR EACH ROW --- the overhead can rapidly accumulate for statements that process large numbers of rows. You should therefore avoid placing any expensive SQL statements or procedural code in triggers.

An expanded explanation of trigger overhead is given on pages 529-531. The concluding point from that section states the following:

The lesson here is this: since the trigger code will execute once for every row affected by a DML statement, the trigger can easily become the most significant factor in DML performance. Code inside the trigger body needs to be as lightweight as possible and -- in particular -- any SQL statements in the trigger should be supported by indexes whenever possible.

I also explained other nasty aspects of Triggers in an earlier post.

In light of these things, until Triggers can be redesigned to handle Transaction Isolation, I do not see Triggers being tied into CASCADE operations anytime soon.

share|improve this answer
1  
The performance issue is not very relevant, I think. The OP, or whoever uses a AFTER DELETE TRIGGER, knows that it will be activated after every deletion of a row. It doesn't really matter if the deletions are done by a DELETE that_table or are cascaded from DELETE FROM another_table. – ypercube Apr 24 '12 at 20:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.