Consider this situation:
153)id >= 153
Is step 4 safe?
That is, if another request comes in almost precisely at the same time, and inserts another 20 records after step 2 above, but before step 4, will there be a race condition?
That is, if another request comes in almost precisely at the same time, and inserts another 20 records after step 2 above, but before step 4, will there be a race condition?
Yes, it will.
Records 21 to 40 will be locked by the transaction 2.
Transaction 1 will be blocked and wait until transaction 2 commits or rolls back.
If transaction 2 commits, then transaction 1 will update 40 records (including those inserted by transaction 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With