So my understanding of slow query log is that it logs info about all those queries that took >= time (in secs) that we have set in my.conf file.
Now lets take 3 cases of 3 different SELECT queries (against tables with INNODB engine):
QUERY I: Query_time: 32.937667 Lock_time: 0.000081 Rows_sent: 343 Rows_examined: 12714043
QUERY II: Query_time: 12.937667 Lock_time: 0.000081 Rows_sent: 43 Rows_examined: 714043
QUERY III: Query_time: 42.937667 Lock_time: 0.000081 Rows_sent: 18 Rows_examined: 483
To me both QUERY I and QUERY II looks like possible cases of a bad query or poor indexing (or missing indexing) or fragmented table data etc. (anything else that I might have missed?) that user may look at to improve query execution time.
But for the QUERY III, I am not able to get my head around, I mean what could really be wrong with the DB that it takes 42 secs to just examine 483 rows and sent back 18 of them (with a negligble lock time). This becomes even more confusing when I see it happening intermittently.
So what I really want to ask here is:
- how should I interpret lock time info? Does it mean query had to wait for that many secs before it actually started executing? If yes, then in my example query III actually took 42 secs to examine 483 rows and sent back 18 of them?
- if lock time is neglible but still query time is super huge with just few hundreds of rows being examined and sent back, where should I start looking for issues?
- Could it be that query is spending to much time in some background IO activity? say logging or bin-logging.
- How badly could size of table affect the performance of query? e.g. can we say MySQL is good enough to handle table with 200+million rows
- Is there any better tool or way to monitor DB activity specially to figure background activity of DB? In short, to check where is that query spending most of it's time.
There might be lot many factors affecting such slow queries, so in case you feel that you need some more information from side to be able to help me then please do let me know.
Query_time
use? Seconds? Milliseconds? – Streeter