I have the following InnoDB table:
+-----------+-----------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default
Sometimes it is not the query itself which causes a slowdown - another query operating on the table can easily cause inserts to slow down due to transactional isolation and locking. Your slow queries might simply have been waiting for another transaction(s) to complete. This is fairly common on a busy table, or if your server is executing long/complex transactions.
Another significant factor will be the overall performance of your database: how your my.cnf
file is tuned, how the server itself is tuned, what else the server has running on it, and of course, what hardware the server is running.
The linux tool mytop
and the query SHOW ENGINE INNODB STATUS\G
can be helpful to see possible trouble spots. General linux performance tools can also show how busy your disks are, etc.
Given the nature of this table, have you considered an alternative way to keep track of who is online? In MySQL, I have used a MEMORY
table for such purposes in the past. A NoSQL data store might also be good for this type of information. Redis could store this as a sorted set with much success (score == timestamp).
Further reading: