简体   繁体   中英

Does trigger(after insert) on table slow down inserting into this table

I have a big table( bo_sip_cti_event ) which is too largest to even run queries on this so I made the same table ( bo_sip_cti_event_day ), added trigger after insert on bo_sip_cti_event to add all the same values to bo_sip_cti_event_day and now I am thinking if I significantly slowed down inserts into bo_sip_cti_event .

So generally, does trigger after insert slow down operations on this table?

Yes, the trigger must slow down inserts.

The reason is that relational databases are ACID compliant: All actions, including side-effects like triggers, must be completed before the update transaction completes. So triggers must be executed synchronously, and that consumes CPU, and in your case I/O too, which ultimately takes more time. There's no getting around it.

The answer is yes: it is additional overhead, so obviously it takes time to finish the transaction with the additional trigger execution.

Your design makes me wonder if:

  • You explored all options to speed up your large table. Even billions of rows can be handled quite fine, if you have proper index ect. But it all depends on the table, the design, the data and the queries.
  • What exactly your trigger is doing. The table name "_day" raises questions when and where and how exactly this table is cleaned out at midnight. Hopefully not inside the trigger function, and hopefully not with a "DELETE FROM".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM