开发者

Is there a way to run the trigger in separate thread in MySQL?

开发者 https://www.devze.com 2023-01-29 02:45 出处:网络
I have开发者_Python百科 a PHP web application and when inserted in a table, I have written a trigger to calculate some scores and this takes time. My PHP application waits till the trigger completes.

I have开发者_Python百科 a PHP web application and when inserted in a table, I have written a trigger to calculate some scores and this takes time. My PHP application waits till the trigger completes. Can this trigger run in a separate thread such that my application will not wait for the completion of the trigger?


No.

But as Bill Clinton would have said, "and I'll tell you why."

One of the big advantages of a trigger is that the actions of the trigger are contained within the transaction of the original statement that fired the trigger. This is a Good Thing from the Relational mindset because we like ACID compliance.

Now if you do not need that ACID compliance, and it is ok for the triggered actions to take effect "eventually", then remove the trigger and make an 'actions' table. Then either the trigger can drop something into the actions table or your PHP code might do it. You can have a job querying this table once/second or so, and if it finds anything it executes it. Don't worry about performance on the daemon, a once/second query of a table that is usually empty is nothing.

0

精彩评论

暂无评论...
验证码 换一张
取 消