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;

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;
时间: 2024-08-04 16:18:15

Mysql in statement performance related with its position?的相关文章

Profiling MySQL queries from Performance Schema

转自:http://www.percona.com/blog/2015/04/16/profiling-mysql-queries-from-performance-schema/?utm_source=tuicool When optimizing queries and investigating performance issues, MySQL comes with built in support for profiling queries aka SET profiling = 1;

MySql用statement实现DDL,DML,DQL的操作Demo

Demo1 Connection connection=null; Statement stmt=null; int result=-1; try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { //创建连接 String url="jdbc:mysql://localhost:3306/jdbcdb"

函数:MySQL中字符串匹配函数LOCATE和POSITION使用方法

1. 用法一 LOCATE(substr,str) POSITION(substr IN str) 函数返回子串substr在字符串str中第一次出现的位置.如果子串substr在str中不存在,返回值为0. mysql> SELECT LOCATE('bar', 'foobarbar'); -> 4 mysql> SELECT LOCATE('xbar', 'foobar'); -> 0 这个函数是大小写不敏感的.在MySQL3.23中,这个函数是字母大小写敏感的,当在MySQL

MySQL: LEAVE Statement

https://www.techonthenet.com/mysql/loops/leave.php This MySQL tutorial explains how to use the LEAVE statement in MySQL with syntax and examples. Description In MySQL, the LEAVE statement is used when you want to exit a block of code identified by a 

MySQL时间点数据恢复测试步骤--基于Position

MySQL时间点数据恢复测试步骤(基于Position): 1.查看当前的二进制日志的名称及位置 mysql> show master status ; | master-bin.000001 |      107 2.修改数据库的信息并记录相应的修改内容以便于恢复后比对. 例如本例对test.tb1插入了数据: +------+-------+ | id   | name  | +------+-------+ |    1 | tina  | |    2 | jason | +------

MySQL 5.6 Reference Manual-14.4 InnoDB Configuration

14.4 InnoDB Configuration 14.4.1 InnoDB Initialization and Startup Configuration 14.4.2 Configuring InnoDB for Read-Only Operation 14.4.3 InnoDB Buffer Pool Configuration 14.4.4 Configuring the Memory Allocator for InnoDB 14.4.5 Configuring InnoDB Ch

mysql主从同步配置方法和原理

mysql主从复制试验环境:    1.CentOS5.8 x86_64位 采用最小化安装,系统经过了基本优化篇    2.mysql版本: 5.1.73-log ,同台服务器多实例,安装方法参考:mysql多实例安装方法 3.源码包存放位置:/home/oldboy/tools    4.源码包编译安装位置:/application/一.修改master配置    1.修改my.cnf配置         vi /data/3306/my.cnf         egrep "log-bin|

MySQL 5.7 Replication 相关新功能说明

背景: MySQL5.7在主从复制上面相对之前版本多了一些新特性,包括多源复制.基于组提交的并行复制.在线修改Replication Filter.GTID增强.半同步复制增强等.因为都是和复制相关,所以本文将针对这些新特性放一起进行说明,篇幅可能稍长,本文使用的MySQL版本是5.7.13. 1,多源复制(多主一从) MySQL在5.7之后才支持多源复制,之前介绍过MariaDB 多主一从 搭建测试说明,现在介绍如何在MySQL上做多主一从,具体的方法说明可以查看官方文档. 原理:多源复制加入

103-MHA 高可用mysql集群

一.MHA简介 1.1.简介 MHA(Master HA ) 是一款开源的 MySQL高可用程序,它为MYSQL 主从复制架构提供了automating master failover 主节点自动迁移功能.MHA在监控到master节点故障时候,会自动提升拥有的数据最近进于主节点的其他从节点为主节点, 并且在此期间,会通过其他节点获取额外的信息来避免数据不一致性的问题.MHA也提供master节点的在线切换功能, 即按需切换master/slave节点. 1.2.MHA服务角色 MHA Mana