So, from my reading of the MySQL 5.5 documentation and some experiments I did with colleagues, I understand that the following is the case:
- With InnoDB tables, a simple
SELECTstatement (one that does not useFOR UPDATEorLOCK IN SHARE MODE) will not grab any row locks on the tables that theSELECTstatement reads. This is true at all transaction isolation levels. - However, if your transaction isolation level is
REPEATABLE READor higher, anINSERT ... SELECTorCREATE TABLE AS SELECTstatement will place row locks on tables that it reads from.
Sources:
- http://dev.mysql.com/doc/refman/5.5/en/innodb-consistent-read.html
- http://dev.mysql.com/doc/refman/5.5/en/innodb-locks-set.html
If I understand this correctly (and correct me if I don't), then I'm puzzled by this difference. Why does reading a table require lock rows in the one case but not the other, when the transaction isolation level is the same? I'd like to understand the reason for this.