Home > database >  Why is the trigger inefficient
Why is the trigger inefficient

Time:04-18

Why is the trigger inefficient, take up the server resources, should be used sparingly trigger?

The efficiency of the trigger is proportional to implement the business logic? If this table does not involve the batch operation, and trigger the execution of business logic is simple, if there is no I said "trigger is inefficient, take up server resources" this statement?

CodePudding user response:

The trigger don't abuse, this is the consensus,

Say first trigger shortcomings,
1. Influence table increases the deletion operation, prolonged operation, even result in failure,
2. Logic becomes complex, in the case of programmers don't know, out of the question is very difficult to trace, in fact, most programmers could not understand the trigger, the problem basically won't be in this direction,

But the trigger is not nothing, some special cases use or can be, note:
1. Try not to in the main business on the table;
2. The trigger logic don't complicated, as simple as possible, more not allowed to have the possibility of error, especially do not operate the remote tables or other objects;
3. Create a trigger, all developers should know its existence, and understand its function,

To answer your question:
A. inefficient?
- more than the original low efficiency is certain, how many to look at logic and low if the logic is simple, low may only 20% ~ 30%, the complex is hard to say.

B. server resources?
- this not much, mainly is prolonged, if it is a busy table, lock will be complex,

C. the efficiency of the trigger is proportional to implement the business logic?
Simple - trigger business, efficiency is high, low, conversely

D. if the table does not involve the batch operation, and trigger the execution of business logic is simple, if there is no I said "trigger is inefficient, take up server resources" this statement?
- reducing efficiency is yes, how many there will be,

In short, if is not very important table, then you can try, according to the actual situation, it is good to watch for a period of time,
In general, not important table, the trigger logic is simple, it's not a problem,
  • Related