一.一些常见的SQL实践 (1)负向条件查询不能使用索引 select * from order where status!=0 and stauts!=1 not in/not exists都不是好习惯 可以优化为in查询: select * from order where status in(2,3) (2)前导模糊查询不能使用索引 select * from order where desc like '%XX' 而非前导模糊查询则可以: select * from order wher
select count(1) from table1 where column1 = 1 and column2 = 'foo' and column3 = 'bar' 其中column1,column2 ,column3分别单独建立了3个单索引. 与其说是“数据库查询只能用到一个索引”,倒不是说是 和全表扫描/只使用一个索引的速度比起来,去分析两个索引二叉树更加耗费时间,所以绝大多数情况下数据库都是是用一个索引.如这条语句: select count(1) from table1 where