Does transaction stop all problems with race conditions in MySQL?

Consider this situation:

  • Start transaction
  • Insert 20 records into the table with the key auto_increment.
  • Get the first insert identifier (say 153)
  • Refresh all records in this table, where id >= 153
  • Fix

Is step 4 safe?

That is, if another request arrives almost exactly at the same time and inserts another 20 records after step 2 above, but before step 4, will there be a race condition?

+5
source share
2 answers

That is, if another request arrives almost exactly 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- 40will be blocked by the transaction 2.

1 , 2 .

2 , 1 40 ( , 2)

+5

, , DMBS. , , , .

, , , , , . , , mysql ​​. MSSQL.

0

All Articles