Does a transaction stop all race condition problems in MySQL?
Posted
by nickf
on Stack Overflow
See other posts from Stack Overflow
or by nickf
Published on 2010-05-11T07:29:35Z
Indexed on
2010/05/11
7:34 UTC
Read the original article
Hit count: 339
Consider this situation:
- Begin transaction
- Insert 20 records into a table with an auto_increment key
- Get the first insert id (let's say it's
153
) - Update all records in that table where
id >= 153
- Commit
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?
© Stack Overflow or respective owner