Most of our tables have one BEFORE INSERT OR UPDATE trigger, in order to set ID’s BEFORE INSERT and to set creation / modification users / dates BEFORE INSERT OR UPDATE.
There are a couple of tables with additional triggers, which were separated from the previous one in order to make their intent more clear. Also, those additional triggers could be disabled independently from the previous one, which should never be disabled.
In most cases, the additional triggers also fire BEFORE INSERT OR UPDATE and the order is unimportant, as they cover different columns / use-cases. So generally, they could be combined to single triggers.
Are there any studies about the speed of calling 1 or n triggers on a table? Or is that pretty much irrelevant for single-row inserts / updates? In other words, is there only 1 global SQL -> PL/SQL context switch, or will there be 1 context switch per trigger.
I have now benchmarked this situation and I came to the conclusion that there is a significant performance loss most likely due to PL/SQL context switches, when adding 1 trigger. The loss is by factor 8 in my benchmark. Adding a second “compatible” trigger, however, doesn’t have any significant impact anymore. By “compatible”, I mean both triggers always fire at the same event in any order.
So I’m concluding that there is most likely only 1
SQL -> PL/SQLcontext switch for all triggersHere’s the benchmark:
Create a table
… and a sequence
A typical trigger setting ID, creation/modification user/date
Insert 1000, 10000, 100000 Records
Results
Another “compatible” trigger (execution order irrelevant)
Results of another run of the test script
Deactivate triggers
Run a slightly different test script
Results