Suppose I ran this statement:
UPDATE Employees set country='AU'
On an InnoDB table, Employees, with about 10 million rows.
This table is also actively being updated by other users through SQL queries like the one below:
E.g. a User, ID = 20, changes their country to NZ:
UPDATE Employees set country='NZ' where id = 20
- In that case, will any further updates to this table block until the general update completes?
- If so, is there a way to allow specific updates and the general update to run concurrently, if they are not updating the same row? (To clarify what I mean here: suppose the general update finishes updating Employees with Id 1 - 50, and is now updating Emplyoees 51 - ~10 million, a singular update on Employee with id of 20 should go through without waiting for the general update to finish)
Yes, the first update will place exclusive locks on all records in the table, blocking other queries from updating it. The locks are held until the transaction is commited.
No. The locks are held while the transaction is running and a released when the transaction is commited. You may want to update the table in chuncks, rather than in one big bang, avoiding the first update locking the entire table. Or execute the update outside of business hours, if possible.