If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How can I optimize this query to run faster?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-10, 11:38
ggduff ggduff is offline
Registered User
 
Join Date: Mar 2010
Posts: 1
How can I optimize this query to run faster?

How can I change this query to execute faster? Right now it's doing a filesort. Thanks!

mysql> explain select m.mon_id, m.frequency, (select l.ts_end from SYS_monitor_log l where l.mon_id = m.mon_id order by l.log_id desc limit 1) as ts_end from SYS_monitor m where m.active = 1 and m.late_since = 0 having ts_end is not null;
+----+--------------------+-------+------+------------------------+--------+---------+-------------------+------+------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+------+------------------------+--------+---------+-------------------+------+------------------------------------------+
| 1 | PRIMARY | m | ref | active | active | 5 | const,const | 339 | |
| 2 | DEPENDENT SUBQUERY | l | ref | mon_id,mon_id_2,log_id | mon_id | 4 | netsaint.m.mon_id | 43 | Using where; Using index; Using filesort |
+----+--------------------+-------+------+------------------------+--------+---------+-------------------+------+------------------------------------------+
2 rows in set (0.00 sec)

OPIDElapsedRowsArgsSQLLineFile
slowQuery34.206s292 select m.mon_id, m.frequency,
(select l.ts_end
from SYS_monitor_log l
where l.mon_id = m.mon_id
order by l.log_id desc
limit 1) as ts_end
from SYS_monitor m
where m.active = 1
and m.late_since = 0
having ts_end is not null31/web/www/***/***/*******.php
StatusDurationCPU_userCPU_systemBlock_ops_inBlock_ ops_outSwapsstarting0.0000100.0000000.000000---checking permissions0.0000060.0000000.000000---checking permissions0.0000070.0000000.000000---Opening tables0.0000110.0000000.000000---System lock0.0000060.0000000.000000---Table lock0.0000080.0000000.000000---init0.0000150.0000000.000000---optimizing0.0000200.0000000.000000---statistics0.0001030.0000000.000000---preparing0.0000230.0000000.000000---executing0.0000080.0000000.000000---Sending data0.1120410.0329950.027996---optimizing0.0000250.0000000.000000---statistics0.0000390.0000000.000000---preparing0.0000270.0000000.000000---executing0.0000080.0000000.000000---Sorting result0.0541950.0449930.033995---Sending data0.0000390.0000000.000000---executing0.0000150.0000000.000000---Sorting result0.0568140.0309950.015997---Sending data0.0000260.0010000.000000---executing0.0000060.0000000.000000---Sorting result0.0978700.0399940.017997---Sending data0.0000340.0000000.000000---executing0.0000130.0000000.000000---Sorting result0.1273040.0309950.019997---Sending data0.0000270.0000000.000000---executing0.0000070.0000000.000000---Sorting result0.0366200.0439930.029996---Sending data0.0000430.0000000.000000---executing0.0000080.0000000.000000---Sorting result0.0415700.0349950.025996---Sending data0.0000330.0000000.000000---executing0.0000130.0000000.000000---Sorting result0.0123900.0419940.025996---Sending data0.0000340.0000000.001000---executing0.0000070.0000000.001000---Sorting result0.1260470.0609900.023996---Sending data0.0000370.0000000.000000---executing0.0000100.0000000.001000---Sorting result0.0888280.0459930.022996---Sending data0.0000510.0000000.000000---executing0.0000080.0000000.000000---Sorting result0.0457080.0549920.033995---Sending data0.0000340.0000000.000000---executing0.0000080.0000000.000000---Sorting result0.1291580.0429930.014998---Sending data0.0000360.0000000.000000---executing0.0000070.0000000.000000---Sorting result0.0127810.0239970.005999---Sending data0.0000900.0000000.000000---executing0.0000070.0000000.000000---Sorting result0.0114370.0629900.014998---Sending data0.0000360.0000000.000000---executing0.0000170.0000000.000000---Sorting result0.0014200.0040000.001999---Sending data0.0000680.0000000.000000---executing0.0000140.0000000.000000---Sorting result0.0150350.0499920.014998---Sending data0.0000270.0000000.000000---executing0.0000070.0000000.000000---Sorting result0.0509340.0329950.016998---Sending data0.0000340.0000000.000000---executing0.0000070.0000000.000000---Sorting result0.1266030.0449930.014997---Sending data0.0000720.0000000.000000---executing0.0000080.0000000.000000---Sorting result0.0115910.0439930.004000---Sending data0.0000470.0020000.000000---executing0.0000060.0000000.000000---Sorting result0.0035020.0129980.001999---Sending
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On