Thursday, February 4, 2010

a easy way to find mysql slow query

There are several ways to find mysql slow query in your scripts.
The easies way is 'show full processlist' in your mysql terminal.

Here is example:

mysql> show full processlist;
+----+--------+----------------------+------+---------+------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+--------+----------------------+------+---------+------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10 | amp | revolution:54088 | amp | Sleep | 9 | NULL | NULL |
| 9 | amp | revolution:54089 | amp | Sleep | 9 | NULL | NULL |
| 11 | amp | revolution:54090 | amp | Query | 1 | Sorting for group | select bottuples0_.sensor_id as col_0_0_, sensor2_.sensorName as col_1_0_, organizati3_.name as col_2_0_, count(distinct bottuples0_.id) as col_3_0_, count(distinct boteventse1_.id) as col_4_0_, max(bottuples0_.day_index) as col_5_0_ from bot_tuples bottuples0_ left outer join bot_events boteventse1_ on bottuples0_.id=boteventse1_.bot_tuple_id, sensors sensor2_, groups organizati3_ where sensor2_.sensorID=bottuples0_.sensor_id and sensor2_.organizationID=organizati3_.organizationID group by bottuples0_.sensor_id order by count(bottuples0_.id) desc |
| 22 | amp | localhost | amp | Sleep | 0 | NULL | NULL |
|
| 40 | amp | localhost | amp | Sleep | 2889 | NULL | NULL |
|
+----+--------+----------------------+------+---------+------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
7 rows in set (0.00 sec)

mysql>

No comments:

Post a Comment