I have a table with InnoDB engine (comments) in MySQL database and I have the following scenario:
There are two users trying to access the same comments table at the same time as following:
user1:
INSERT INTO comments (comment) VALUES ('HELLO WORLD');
user2:
SELECT * FROM comments;
I want the following points to be clarified , please:
- The user2 can not read (SELECT) from the table , it should wait for some time (I think until the insert of the user1 is finihshed). Is this waiting called row-level lock which used by InnoDB?
- If the answer of the previous question was YES so what is the job of MVCC? in InnoDB engine. I read that MVCC means to let the users read the table rows (repeatable-read) even if there is an update or insert situation at the same time (because the user here read an old version of the row even if it is being updated at the mean time).
Notes:
- I want to mention that I use the above code in the following form but it still making the same problem (waiting problem):
user1:
SET AUTOCOMMIT=0;
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
INSERT INTO comments (comment) VALUES ('HELLO WORLD');
COMMIT;
user2:
SELECT * FROM comments;
- I even try to change the isolation level from repeatable-read to read uncommited -the dirty read is not so important in my case- (I thought it will solve the waiting problem but it did not. the waiting is still stand).
user1:
SET AUTOCOMMIT=0;
START TRANSACTION;
INSERT INTO comments (comment) VALUES ('HELLO WORLD');
COMMIT;
user2:
SELECT * FROM comments;
The big question is How could my users read while other users inserting or updating rows?