› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
wudaye
V2EX  ›  MySQL

mysql 的 if 函数条件能走索引吗

  •  
  •   wudaye · Jul 15, 2020 via Android · 4217 views
    This topic created in 2265 days ago, the information mentioned may be changed or developed.

    有个统计需求,大概是 select count(if(条件 a)) as acount,count(if(条件 b)) as bcount,担心 if 里面的字段比较能不能走索引(MySQL 文档没说),如果不能,就考虑拆成两个 SQL 并用 where 取代原来的 if 条件。

    4 replies  •  2020-07-16 07:50:00 +08:00
    w516322644
        1
    w516322644  
       Jul 15, 2020
    主要看 where 。
    zhangysh1995
        2
    zhangysh1995  
       Jul 15, 2020
    IF 函数的话,不论是否满足都要执行表达式,所以这里索引没什么用,所有数据都要扫一遍的吧
    为啥不放到 where 里面用索引呢?看起来就是数一下行数。
    cubecube
        3
    cubecube  
       Jul 15, 2020
    不会,这个在列表达式,和索引没任何关系
    realpg
        4
    realpg  
       Jul 16, 2020 via Android
    为什么这么多人都喜欢或者说优先考虑奇形怪状的查询?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2703 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 08:23 · PVG 16:23 · LAX 01:23 · JFK 04:23
    ♥ Do have faith in what you're doing.