问题
When i run 'Select * from table' on an INNODB table, does the table get locked implicity? Does it mean that during the time MySQL takes to return the result set, i cannot issue an update statement on the table?
From what i have understood, the whole table would be locked in shared mode until the result set is returned from the server. Only then could the update command be executed.
回答1:
InnoDB uses a feature called Multi-version concurrency control.
Locking in shared mode is not required, since MVCC
will retain earlier versions of the row for your SELECT
statement to be able to read if required.
So the answer is 'no', running a SELECT
statement will not need to lock any rows while updating. That is, unless it is a special SELECT
statement like SELECT .. FOR UPDATE
.
来源:https://stackoverflow.com/questions/23218588/confusion-regarding-innodb-locking