Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the unit of time in MySQL's slow-query log?

Tags:

logging

mysql

I'm looking at the slow query log from a drupal-based webapp, and have lines that look like this:

# Query_time: 3257  Lock_time: 0  Rows_sent: 272  Rows_examined: 272
# Query_time: 1654  Lock_time: 0  Rows_sent: 222  Rows_examined: 222
# Query_time: 3292  Lock_time: 0  Rows_sent: 269  Rows_examined: 269
# Query_time: 1029  Lock_time: 0  Rows_sent: 172  Rows_examined: 172
# Query_time: 2126  Lock_time: 0  Rows_sent: 251  Rows_examined: 251
# Query_time: 1731  Lock_time: 0  Rows_sent: 229  Rows_examined: 229

Are these times indicating that the associated queries took between 1 and 3+ seconds (slow but not terrible) to execute, or between 1,000 and 3,000+ seconds (completely unacceptable)? I understand that the long_query_time option is specified in seconds, but do the log messages follow this same convention, or do they use milliseconds instead?

Edit: this is with MySQL version 5.0.45.

like image 366
aroth Avatar asked Aug 04 '11 05:08

aroth


People also ask

What is slow query time?

The slow query log consists of SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined. The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization.

How do I read a slow query log?

To make reading the log contents easier, you can use the mysqldumpslow command-line utility to process a slow query log file and summarize its contents: ~ $ mysqldumpslow -a /var/lib/mysql/slowquery. log Reading mysql slow query log from /var/lib/mysql/slowquery.

What is long query time?

By default, when the slow query log is enabled, it logs any query that takes longer than 10 seconds to run. To change this interval, type the following command, replacing X with the time in seconds: Copy SET GLOBAL long_query_time = X; By default, the slow query log file is located at /var/lib/mysql/hostname-slow. log.


2 Answers

It's in seconds. The 'resolution of microseconds' means, that you can have up to microsecond precision after a decimal (although AFAIK it need a patch to actually write with such precision)

https://github.com/wvanbergen/request-log-analyzer/wiki/MySQL-slow-query-log

like image 185
Mchl Avatar answered Oct 19 '22 10:10

Mchl


Only since MySQL 5.1.21 that you can specify a decimal value and has a resolution of microsecond. http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html

like image 31
jcisio Avatar answered Oct 19 '22 08:10

jcisio