码迷,mamicode.com
首页 > 数据库 > 详细

Mysql in statement performance related with its position?

时间:2014-12-07 21:36:02      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   os   sp   for   strong   

select
    *
from
    (
    select
        event_date,
        2014-12-06 as active_date,
        channel_id,
        new_user_count as new_user_count,
        1d_retain/new_user_count as 1d_retain_rate
    from
        web_channel_retain
    where
        app_id=-1
    and
        event_date=2014-12-05
    and
        new_user_count>= 500
    and
        channel_id in (select distinct channel_id from formated_channel_category where type_id=507 )
    )as f
order by 1d_retain_rate desc
limit 0,50;

The above sql runs less than 2 seconds, while below sql runs a long time(I killed it before it completed). The only difference is the position of in statement.

select
    *
from
    (
    select
        event_date,
        2014-12-06 as active_date,
        channel_id,
        new_user_count as new_user_count,
        1d_retain/new_user_count as 1d_retain_rate
    from
        web_channel_retain
    where
        channel_id in (select distinct channel_id from formated_channel_category where type_id=507 )
    and
        app_id=-1
    and
        event_date=2014-12-05
    and
        new_user_count>= 500
        
    )as f
order by 1d_retain_rate desc
limit 0,50;

 

Mysql in statement performance related with its position?

标签:des   style   blog   io   color   os   sp   for   strong   

原文地址:http://www.cnblogs.com/linghuaichong/p/4149835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!