千巷猫影
1 考察的是组合索引和索引排序,至少得建两个吧,idx_a_b(a,b)和idx_b_time(b,time);2 5.5以前不知,5.5以后会自动调整顺序(但还是强烈建议按照索引的顺序写sql,养成好习惯),5.6有icp特性,范围查询都可以不写在where条件的最后,举个简单例子,已知存在下例索引KEY `companyIsdelete` (`companyId`,`isDelete`)我交换顺序后的解析计划如下,还是用到了该索引mysql> explain select * from DB_Message9 where isDelete=1 and companyId=1234\G*************************** 1. row ***************************id: 1select_type: SIMPLEtable: DB_Message9type: refpossible_keys: companyIsdelete,companyAnswerUp,customertype,sender,sender2,noAssignkey: companyIsdeletekey_len: 6ref: const,constrows: 1Extra: NULL1 row in set (0.00 sec)