zoukankan      html  css  js  c++  java
  • Mysql in statement performance related with its position?

    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;
    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;

     The 1st sql runs less than 2 seconds, while 2nd sql runs a long time(I killed it before it completed). The only difference is the position of the in statement. This means mysql executes "where conditions" in the exact order that we write them.

  • 相关阅读:
    1-5-03:均值
    1-5-01:求平均年龄
    1-04-t6993:二进制位处理
    1-4-20:求一元二次方程的根
    1-4-19:简单计算器
    1-4-18:点和正方形的关系
    1-4-17:判断闰年
    1-4-16:三角形判断
    1-4-15:最大数输出
    停止IIS服务
  • 原文地址:https://www.cnblogs.com/linghuaichong/p/4149835.html
Copyright © 2011-2022 走看看