Mysql查询优化连接和顺序

时间:2013-03-05 06:14:39

标签: mysql

我的以下查询需要超过20秒才能执行以生成大约150k条记录。需要在此查询或服务器参数中进行一些优化?

select 
    ml.device_media_id,
    ml.device_id,
    ml.media_id,
    ml.playback_type_id,
    ml.playback_id,
    ml.play_date,
    ml.start_time,
    ml.end_time,
    m.title as medianame,
    mt.name as media_type,
    d.device_name as devicename,
    SUBTIME(ml.end_time,ml.start_time) as playback_duration,
    d.client_id 
from t1 ml 
    left join t2 m on m.media_id = ml.media_id 
    left join t3 d on d.device_id = ml.device_id 
    left join t4 mt on m.media_type_id = mt.media_type_id 
where 
    d.client_id ='' and 
    m.title = '' and 
    d.device_id = '' and 
    mt.media_type_id = '' and 
    DATE_FORMAT(ml.play_date,'%Y-%m-%d') = '' and 
    ml.start_time >= '' and 
    ml.end_time <= '' 
order by 
    ml.play_date desc,
    ml.start_time desc,
    ml.end_time desc; 

0 个答案:

没有答案