I am doing a very simple select from a table like
SELECT column FROM table WHERE id=5;
id is a primary key and all the tables are using innodb.
When I enable profiling in phpmyadmin and run this query I see this :
Status Time
starting 0.000025
checking query cache for query 0.000034
checking permissions 0.000004
Opening tables 0.000022
System lock 0.000004
Table lock 0.000022
init 0.000016
optimizing 0.000008
statistics 0.000030
preparing 0.000022
executing 0.000003
Sending data 0.000009
end 0.000002
query end 0.000003
freeing items 0.000061
storing result in query cache 0.000005
logging slow query 0.000002
cleaning up 0.000002
The second time I run the same query I get this since the query is cached:
Status Time
starting 0.000022
checking query cache for query 0.000005
checking privileges on cached 0.000003
checking permissions 0.000020
sending cached result to clien 0.000055
logging slow query 0.000002
cleaning up 0.000002
Why is a simple select query like this locking the table?
Please keep in mind that the primary key is a clustered index (called gen_clust_index). There is a possiblility of a Shared Index Lock hitting the index page where id=5 resides.
Exclusive Index Locks and Shared Index Locks try to coexist in InnoDB as best as possible to accommodate
Try running
SHOW ENGINE INNODB STATUS\Gand look for such locks.