Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can priority be given to write/update over read in MySQL?
    primarykey
    data
    text
    <p>In my application, I want any insert to the database to be executed as soon as a request comes for writing some data.</p> <p>I am using InnoDB engine.</p> <p>Since insertion requires an exclusive lock, it is possible that while current read query has a shared lock, some other reads might come which again have a shared lock and the write operation might have to wait for a long time.</p> <p>I want that when there is a write operation in queue, no read operation gets a shared lock. As soon as the reads which were initiated before the current write request are completed, the write operation should be executed. After that all other read operations should take place.</p> <p>How can this be implemented?</p> <h2>Edit</h2> <p>Since I am using InnoDB tables and I am not implementing table lock, there should not be a conflict between select and insert. It would be select and update. (Please correct me if there can be a conflict between select and insert as well)</p> <p>In MySQL, update has higher priority than select. But if there are some read queries being executed, then update query comes in followed by some read queries. In that case, will the read queries coming after update wait for the update to finish as mentioned here <a href="http://dev.mysql.com/doc/refman/5.0/en//table-locking.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en//table-locking.html</a> OR they will get shared lock along with the read queries which were there before the update query was fired?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload