0

I'm using mysql with InnoDB engine, and I have created one trigger for BEFORE INSERT. I want to be sure that if two insert queries are fired at the same time then will both trigger work in parallel or sequentially?

I have added sleep in trigger and fired two insert queries, and from the execution time it looks like second trigger is waiting for first one to finish.

Stu
  • 30,392
  • 6
  • 14
  • 33
  • Does [this SO post](https://stackoverflow.com/questions/32087233/how-does-mysql-handle-concurrent-inserts) answer your question? – Sean Anglim Dec 04 '22 at 14:48
  • I had seen that post already, In this it says that for innodb parallel insertions happens, but when I added 10 seconds sleep in BEFORE INSERT TRIGGER and executed two insertions then it took 20sec to complete. – Nitesh kumar Rai Dec 04 '22 at 16:12
  • Oh I see. While I'm not very familiar with sleep, could it be that the sleeps are running sequentially rather than in parallel? – Sean Anglim Dec 04 '22 at 16:24

1 Answers1

0

For InnoDB in MySql, insertions happen in parallel, in my trigger I was using the update for a different table and when the same row was getting updated then in that case insertion was happening in sequential, and when different rows were getting updated then insertion was happening parallelly.

Read this post for more details: https://stackoverflow.com/a/32382959/9599500

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 07 '22 at 18:43