索引优化-失效

 

1) like "%",避免使用模糊查询;尽量使用右模糊,例:like "张%";

2) 避免使用 in,not in ,连续条件可使用between ... and ... ;

3) 避免使用or,可用 union 代替;

4) 避免使用 null 判断,可给字段添加默认值 0 ;

5) 避免 where = 左侧进行表达式、函数操作;可更改为 = 右侧;

6) 数据量大时,避免使用 where 1=1;

7) 不可用 != 或 <>;

8) 隐式类型转换造成不使用索引;例:varchar可以向下转为int,而int不可向上转;

9) 联合索引最左匹配原则;where条件包含复合索引非前之列;

posted @ 2024-02-18 19:54  学Java的`Bei  阅读(12)  评论(0)    收藏  举报