2

I need to query a frequently updated record, does it wait until all updates finish?

  • /updateUser/1

    Many requests are sent

    UPDATE users SET count = count + 1 WHERE id = 1 LIMIT 1
    
  • /getUser/1

    While the user is being updated i perform this request

    SELECT * from users WHERE id = 1 LIMIT 1
    
2

1 Answer 1

0

By default, writers do not block readers. So no, the SELECT would not have to wait for the UPDATE to finish.

Exception cases:

4
  • Interesting. I suggest you explain that, because "writers do not block readers" seems to imply READ UNCOMMITTED Mar 9, 2022 at 20:45
  • @Charlieface, Notwithstanding our deleted comment exchange, I think it's now fair to ask you to test what you assert. Mar 10, 2022 at 3:36
  • No I agreed with you, which is why I deleted it, I don't know MySQL well enough. I was just saying that a cursory reading of your answer, at least coming from a SQL Server perspective, sounds more like READ UNCOMMITTED than it does SNAPSHOT (and you've said it is effectively snapshot isolation), so I just thought you could write that a bit clearer. Mar 10, 2022 at 10:36
  • Well in fact, writers do not block readers in READ-COMMITTED isolation level either. In both RR and RC levels, readers use a snapshot. But in RC, the snapshot is updated to include most recently committed data. Whereas in RR, the snapshot is based on the first read done during the user's transaction and it does not change for the duration of the transaction. Mar 10, 2022 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.