I need to query a frequently updated record, does it wait until all updates finish?
Many requests are sent
UPDATE users SET count = count + 1 WHERE id = 1 LIMIT 1
While the user is being updated i perform this request
SELECT * from users WHERE id = 1 LIMIT 1
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
By default, writers do not block readers. So no, the SELECT would not have to wait for the UPDATE to finish.
If you use explicit syntax to make the SELECT a locking read query.
If you set the transaction isolation level to SERIALIZABLE, which has the effect that all SELECTs are implicitly locking reads.