I have a table called places that has such a schema
id taken
For each user, I take a random untaken id and assign it to this user, here for simplicity I will say that I did take = 1. The request that I use
update seats u inner join (
SELECT id from seats
where taken is null limit 1) s
on s.id = u.id set taken = 1;
This request takes a random place with the accepted null flag, and for this place it makes flag 1. While this request works fine, is this streaming security?
Consider this scenario, I have two users in parallel. For user1, I select the line X, and just before the update request is executed, user2 checks it, and for this user request, the request returns the same line as user1. Therefore, I will finish updating the same line twice.
Is this scenario possible with this query?
source
share