Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are database triggers implemented inside a SQL database engine?

How are triggers implemented inside a SQL database engine? I am not referring to the SQL language-level trigger definitions but rather their underlying implementations inside Oracle, SQL Server, MySQL, etc. How can the database engine scalably manage hundreds or thousands of triggers? Do they use a publish-subscribe model like with an observer/listener pattern? Any pointers to relevant literature on the subject would also be appreciated.

I did google for "database trigger implementation" but all I found was information on SQL trigger definitions, which again is not want I'm looking for.

like image 833
stackoverflowuser2010 Avatar asked Feb 23 '12 23:02

stackoverflowuser2010


1 Answers

Triggers are callbacks, so the implementation can be as simple as function pointers in C. Normally, a user is not expected writing user-defined procedural code in the RDBMS in C, though. You would need to support some other "higher-level" language. So the relevant programming pattern is DSL. The number of triggers (scalability) itself is not a problem because there is usually only one, max two per table and DML event triggers only these. The implementation challenge is elsewhere: in the areas of consistency, concurrency semantics.

like image 85
Tegiri Nenashi Avatar answered Nov 15 '22 06:11

Tegiri Nenashi