• 2020-11-08:在Mysql中,三个字段A、B、C的联合索引,查询条件是B、A、C,会用到索引吗?


    福哥答案2020-11-08:

    会走索引,原因是mysql优化器会把BAC优化成ABC。

    CREATE TABLE `t_testabc2` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `A` varchar(255) NOT NULL,
      `B` varchar(255) NOT NULL,
      `C` varchar(255) NOT NULL,
      `D` varchar(255) NOT NULL DEFAULT '''''',
      PRIMARY KEY (`id`),
      KEY `abc2` (`A`,`B`,`C`) USING BTREE
    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
    
    EXPLAIN SELECT * FROM t_testabc2 WHERE B='a2' AND A='a2' AND C='a2'    --走索引
    
    EXPLAIN SELECT * FROM t_testabc2 WHERE  B >='a1' AND B<='a2' AND A >='a1' AND A<='a2' AND C >='a1' AND C<='a2'    --走索引
    
    EXPLAIN SELECT * FROM t_testabc2 WHERE  B BETWEEN 'a1' AND 'a2' AND A BETWEEN 'a1' AND 'a2' AND C BETWEEN 'a1' AND 'a2'    --走索引
    
    EXPLAIN SELECT * FROM t_testabc2 WHERE B='a1' AND A LIKE 'a%' AND C='a1'    --不走索引
    

      

  • 相关阅读:
    20191024-1 每周例行报告
    萌猿纵横字谜引擎实现过程
    Blender插件加载研究
    Blender插件初始化范例
    Blender插件编写指南
    Blender之Property
    Blender之UILayout
    Blender插件之Panel
    Blender插件之操作器(Operator)实战
    向量之基底
  • 原文地址:https://www.cnblogs.com/waitmoon/p/13946084.html
Copyright © 2020-2023  润新知