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

大兔子大兔子 提交于 2019-11-30 06:40:51

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;

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).

Without seeing the dumps you're talking about, it's probably a user defined function? See this thread ( http://lists.mysql.com/internals/33707 ) for a couple of gotchas and how to do it.

Not elegant, but working solution is to patch /usr/bin/mysql:

# copy the original mysql binary to your home dir
cp /usr/bin/mysql ~/mysql
# patch it
sed -i -e 's/%.2f sec/%.8f sec/1' ~/mysql 
# run it from the home directory
~/mysql 

It works because CURRENTLY there is only one format string '%.2f sec' in the mysql binary, BUT it may change over time. You may revert to the original binary by applying reverse patch:

sed -i -e 's/%.8f sec/%.2f sec/1' ~/mysql
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!