Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see high-precision query times in mysql command line?

I'm working through some optimization work, and I've noticed that in some mysql dumps people post in articles and questions (which I cannot find again now that I'm actually looking), there are high-precision execution times (0.05985215 sec instead of 0.06 sec).

How can I see these more precise times for my queries on the command line?

EDIT

Example of this is:

+----------+
| COUNT(*) |
+----------+
| 11596    |
+----------+
1 row in set (0.05894344 sec)

Using profiling gets me part of the way there, but produces an output too long, and I have to remember to enable it. I am just looking for a simple high-precision duration.

SET profiling = 1;
<query>
SHOW PROFILES;

Gives me something like this:

+----------------------+-----------+
| Status               | Duration  |
+----------------------+-----------+
| (initialization)     | 0.000005  |
| checking permissions | 0.00001   |
| Opening tables       | 0.000499  |
| Table lock           | 0.000071  |
| preparing            | 0.000018  |
| Creating tmp table   | 0.00002   |
| executing            | 0.000006  |
| Copying to tmp table | 6.565327  |
| Sorting result       | 0.000431  |
| Sending data         | 0.006204  |
| query end            | 0.000007  |
| freeing items        | 0.000028  |
| closing tables       | 0.000015  |
| logging slow query   | 0.000005  |
+----------------------+-----------+
14 rows in set (0.00 sec)
like image 820
Ben Dauphinee Avatar asked May 23 '11 20:05

Ben Dauphinee


People also ask

How do I know which query is taking more time in MySQL?

Run the 'show processlist;' query from within MySQL interactive mode prompt. (Adding the 'full' modifier to the command disables truncation of the Info column. This is necessary when viewing long queries.) Pro: Using the full modifier allows for seeing the full query on longer queries.

How do I see what SQL queries are running in MySQL?

MySQL SHOW PROCESSLIST For that measure, we need to look at the table that will show running MySQL queries which is done by the processlist command: show full processlist; The FULL modifier allows us to see the query text in its entirety instead of the first 100 symbols we would get without this modifier.

What is Max execution time in MySQL?

SET GLOBAL MAX_EXECUTION_TIME=1000; Then any SELECT statement run against this MySQL instance will be aborted if it takes more than 1 second to complete. The default for the GLOBAL variable is 0, which means that there is no global time limit.


2 Answers

It seems that the best answer to this is to enable profiling. There have been no other leads that pan out.

Best answer, use query profiling.

SET profiling = 1;
<query>
SHOW PROFILES;
like image 109
Ben Dauphinee Avatar answered Sep 22 '22 09:09

Ben Dauphinee


this question is best answered by looking at the source of the mysql command line client. the relevant piece of code,

static void nice_time(double sec,char *buff,bool part_second)
{
  // ...
  if (part_second)
    sprintf(buff,"%.2f sec",sec);
  else
    sprintf(buff,"%d sec",(int) sec);
}

has the number of digits after the decimal point for the sec value hard-coded into (2). this would make me conclude that higher precision times are not possible with a stock mysql install.

of course, you could patch this code, make it configurable, etc, and install from source. i guess this is what the people in the articles and questions you mentioned are doing. your best chance to find out is to just ask them (see my comment to your question).

like image 34
ax. Avatar answered Sep 20 '22 09:09

ax.