HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Does a TRIGGER improve the performance?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
triggertheimproveperformancedoes

Problem

I understand that TRIGGERs are useful, as they take care of subsequent queries, but do they have an advantage from performance point of view too?

Replacing two or three queries as

INSERT INTO table1 ...
UPDATE table2 ...
UPDATE table3 ...


with a trigger-based query as

INSERT INTO table 1


with trigger

CREATE TRIGGER test
AFTER INSERT ON table1
FOR EACH ROW BEGIN
UPDATE table2 ... WHERE id=NEW.id;
UPDATE table3 ... WHERE id=NEW.id;
END


-
Do we still have the same three queries with identical performance? I mean does it matter if we perform the subsequent queries or the TRIGGER does?

-
What if we use an API (like conducting queries through PHP). The subsequent queries are internal with no need to connector/driver. Does the TRIGGER improve the performance?

Additional Information: The database is mysql 5.5 with innoDB.

Solution

Using a trigger will not affect the execution speed significantly -- in the end, the database system is executing the same operations.

But if you are sure that every insert mandates the updates then triggers are a great way to ensure database integrity, so by all means do it.

Context

StackExchange Database Administrators Q#48797, answer score: 4

Revisions (0)

No revisions yet.