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:

  1. Begin transaction
  2. Insert 20 records into a table with an auto_increment key
  3. Get the first insert id (let's say it's 153)
  4. Update all records in that table where id >= 153
  5. 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

Related posts about mysql

Related posts about race-condition