Hi, Having a problem in SQL where multiple sessions are trying to do the same thing at once, causing a duplication method of what should happen...
for example:
(assuming this_value is 1)
old_value = 0
SELECT this_value FROM t1 WHERE id = 1
old_value += this_value
DELETE this_value FROM t1 WHERE id = 1
old_value should be 1... but then other sessions are SELECTING the row before it has been deleted, and is getting performed more than once... so the old_value could end up 2,3,4,5,6 depending on the amount of sessions that get ahold of it!
I've tried SELECT.... FOR UPDATE but that doesn't seem to lock the SELECT statement at all
This is transaction stuff in InnoDB with the SELECT + DELETE within the single transaction :/
for example:
(assuming this_value is 1)
old_value = 0
SELECT this_value FROM t1 WHERE id = 1
old_value += this_value
DELETE this_value FROM t1 WHERE id = 1
old_value should be 1... but then other sessions are SELECTING the row before it has been deleted, and is getting performed more than once... so the old_value could end up 2,3,4,5,6 depending on the amount of sessions that get ahold of it!
I've tried SELECT.... FOR UPDATE but that doesn't seem to lock the SELECT statement at all

This is transaction stuff in InnoDB with the SELECT + DELETE within the single transaction :/