What is the main performance concern when a trigger contains complex logic that runs on every row affected by a data modification?
Think about how often the trigger code runs when many rows are changed.
Triggers that execute complex logic for each row can slow down data modifications because the logic runs repeatedly, increasing the total time for the transaction.
Given a table orders with 3 rows updated in a single statement, and a row-level trigger that inserts a log entry per updated row, how many rows will be inserted into the log table?
CREATE TRIGGER log_order_update AFTER UPDATE ON orders FOR EACH ROW INSERT INTO order_log(order_id, action) VALUES (NEW.id, 'updated'); UPDATE orders SET status = 'shipped' WHERE status = 'processing';
Consider how row-level triggers behave with multiple rows affected.
Row-level triggers execute once per affected row, so updating 3 rows causes 3 trigger executions and 3 inserts into the log table.
Which trigger design below is likely to cause the worst performance impact on bulk inserts?
Think about how often the trigger code runs and what it does each time.
Row-level triggers with complex queries run once per row, causing significant slowdowns on bulk operations compared to statement-level triggers.
A trigger on the employees table causes an UPDATE statement to run very slowly. The trigger updates a departments table for each employee updated. What is the likely cause?
Consider how triggers that modify other tables per row can affect performance.
Row-level triggers that update another table for each row can cause many repeated updates and locking, slowing down the original update statement.
Which approach is best to optimize trigger performance when handling bulk data modifications?
Think about minimizing repeated executions during bulk changes.
Statement-level triggers run once per statement, allowing batch processing of all affected rows, which improves performance during bulk operations.