Description:
All triggers are evaluated on each statement against a table, even if they are out of
scope of the current statement.
For instance BEFORE UPDATE, and BEFORE DELETE triggers are checked even on an INSERT
statement.
We could get better performance were we to only check the appropriate triggers.
How to repeat:
DELIMITER //
DROP TABLE IF EXISTS t1//
CREATE TABLE t1 (id int)//
/* make sure these tables do not exist */
DROP TABLE IF EXISTS foo//
DROP TABLE IF EXISTS bar//
CREATE TRIGGER tr1 BEFORE UPDATE ON t1
FOR EACH ROW
BEGIN
INSERT INTO foo VALUES ('foo');
END//
INSERT INTO t1 VALUES (1)//
DROP TRIGGER tr1//
CREATE TRIGGER tr2 BEFORE DELETE ON t1
FOR EACH ROW
BEGIN
INSERT INTO bar VALUES ('bar');
END//
INSERT INTO t1 VALUES (1)//
Suggested fix:
Only check triggers that are within scope of the current statement.
Description: All triggers are evaluated on each statement against a table, even if they are out of scope of the current statement. For instance BEFORE UPDATE, and BEFORE DELETE triggers are checked even on an INSERT statement. We could get better performance were we to only check the appropriate triggers. How to repeat: DELIMITER // DROP TABLE IF EXISTS t1// CREATE TABLE t1 (id int)// /* make sure these tables do not exist */ DROP TABLE IF EXISTS foo// DROP TABLE IF EXISTS bar// CREATE TRIGGER tr1 BEFORE UPDATE ON t1 FOR EACH ROW BEGIN INSERT INTO foo VALUES ('foo'); END// INSERT INTO t1 VALUES (1)// DROP TRIGGER tr1// CREATE TRIGGER tr2 BEFORE DELETE ON t1 FOR EACH ROW BEGIN INSERT INTO bar VALUES ('bar'); END// INSERT INTO t1 VALUES (1)// Suggested fix: Only check triggers that are within scope of the current statement.