Search code examples
mysqlperformancemysql-slow-query-log

How do I test the real execution time of a query?


I get one slow query in Mysql slow query log. Mysql slow query log shows the query need more than 4 seconds to execute.

I run this query in phpmyadmin, it takes 3 seconds. When I run it again, it takes only 0.0002 seconds. I guess there is a DB Cache or something. When I run it in second time, it executing time might not be accurate.

For this kind of situation(executing time is quick), how do I test the real execution time of the query?


Solution

  • For testing purpose only you can use SQL_NO_CACHE

    SELECT SQL_NO_CACHE * FROM `table` .....
    

    other way you can set query_cache_type to 0 for current session

    SET SESSION query_cache_type=0;
    

    SQL_NO_CACHE

    Query Cache Configuration