When I run a query, I don't want it to print to the console. I just want to see the time.
9166 rows in set (0.90 sec)
Thats all I want to see, instead of it printing everything.
Now, go to the Scalyr dashboard menu and select MySQL. You will be able to see the log details of your MySQL, which includes the query time. This is a very simple and easy way to measure query time for a large number of MySQL queries.
You can view this by Right Clicking on Instance Name in SQL Server Management Studio and selecting “Activity Monitor”. Activity monitor tells you what the current and recent activities are in your SQL Server Instance. The above screenshot displays an overview window for the Activity Monitor.
There are a number of things that may cause a query to take longer time to execute: Inefficient query – Use non-indexed columns while lookup or joining, thus MySQL takes longer time to match the condition. Table lock – The table is locked, by global lock or explicit table lock when the query is trying to access it.
By default, the slow query log file is located at /var/lib/mysql/hostname-slow. log. We can also set up another location as shown in listing 03 using the slow_query_log_file parameter. We can also indicate to log queries not using indexes, as shown in the listing 04.
Try this simple example
mysql> set profiling=1;
mysql> select count(*) from comment;
mysql> select count(*) from message;
mysql> show profiles;
+----------+------------+------------------------------+
| Query_ID | Duration | Query |
+----------+------------+------------------------------+
| 1 | 0.00012700 | select count(*) from comment |
| 2 | 0.00014200 | select count(*) from message |
+----------+------------+------------------------------+
2 rows in set (0.00 sec)
You can write your query inside sub-query with COUNT
to do the trick as:
SELECT COUNT(1)
FROM ( SELECT * FROM your_table WHERE ...) a
It may slow down your query slightly, as it's doing COUNT
also but I think its negligible.
For measuring performance of query you can turn on PROFILES
in MySQL as:
SET profiling = 1;
For more details about PROFILES
see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With