I feel puzzled when I try to analyse slow_query_log in mysql. In my opinion, a plain(nonlocking) select has no need to lock any record because of mvcc, referece: https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html https://dev.mysql.com/doc/refman/8.0/en/innodb-consistent-read.html
But in slow_query_log, I find that a plain select has Lock_time. I use the sample database of mysql, namely sakila.
I execute the sql:
select * from customer limit 10;
then in the slow_query_log, I find the log:
# User@Host: root[root] @ localhost [::1] Id: 13
# Query_time: 0.009601 Lock_time: 0.009362 Rows_sent: 10 Rows_examined: 10
SET timestamp=1650356898;
select * from customer limit 10;
I read the book High Performance Mysql (Baron Schwartz) (p735) and find that mysql will implicitly add shared locks for plain select.
so, what does nonlocking read (mvcc) actually mean?
Well, there are (intention) shared locks that are still needed. Here's the manual entry about locking in InnoDB: InnoDB Locking