Concurrent INSERT in the Same table
Transaction T1:
1 2 3 | START TRANSACTION;
INSERT INTO test VALUES(2,'test2','test123');
COMMIT;
|
Transaction T2:
1 2 3 | START TRANSACTION;
INSERT INTO test VALUES(3,'test3','test123');
COMMIT;
|
Scenario 1:
T1 is started but not committed. At the same time, T2 is started. After the INSERT of T1 is complete, the INSERT of T2 is performed and succeeds. At the READ COMMITTED and REPEATABLE READ levels, the SELECT of T1 cannot see data inserted by T2, and a query in 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. In T2, a query performed after INSERT 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. In T2, a query performed after INSERT cannot see the data inserted by T1.
Last Article: Concurrent INSERT and DELETE in the Same Table
Next Article: Concurrent UPDATE in the Same Table
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.