Concurrent INSERT and DELETE in the Same Table
Transaction T1:
1 2 3 | START TRANSACTION;
INSERT INTO test VALUES(1,'test1','test123');
COMMIT;
|
Transaction T2:
1 2 3 | START TRANSACTION;
DELETE test WHERE NAME='test1';
COMMIT;
|
Scenario 1:
T1 is started but not committed. At the same time, T2 is started. After the INSERT of T1 is complete, the DELETE of T2 is performed. In this case, DELETE 0 is displayed, because T1 is not committed and T2 cannot see the data inserted by T1.
Scenario 2:
- READ COMMITTED level
T1 is started but not committed. At the same time, T2 is started. After the INSERT of T1 is complete, T1 is committed and the DELETE of T2 is performed. In this case, DELETE 1 is displayed, because T2 can see the data inserted by T1.
- REPEATABLE READ level
T1 is started but not committed. At the same time, T2 is started. After the INSERT of T1 is complete, T1 is committed and the DELETE of T2 is performed. In this case, DELETE 0 is displayed, because the data obtained in queries is consistent in a transaction.
Last Article: Potential Deadlocks During Concurrent Write
Next Article: Concurrent INSERT in the Same table
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.