MySQL INSERT and SELECT Order of precedence -


If an INSERT and a selection are performed simultaneously which is the one on a mysql table which will go first?

Example: Assume that the "User" table is row number 0.

Then these two questions are run at the same time (assuming it is in the same milliseconds / second):

  INSERT (1)  

and

  from users SELECT COUNT (*)  

last query 0 or return of 1 Will be

It depends on whether your user is table mismus or indebibiah.

If it is a mezzo, then a statement or a lock on the second table takes a lock, and very few you can do to control it, less than yourself.

If it is INODB, then it is transaction-based. Multi-varianting architecture allows concurrent access to the table, and will see the count of SELECT rows immediately as the beginning of their transactions. If a INSERT is running at the same time, then SELECT will see 0 rows. In fact you can see 0 rows after executing some code after SELECT , if the transaction for INSERT is not yet committed.

There is no guarantee of some order for transactions in order to actually start simultaneously for two transactions.


Comments