码迷,mamicode.com
首页 > 数据库 > 详细

SQL 优化通用方法

时间:2018-04-13 18:03:46      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:函数   for   HERE   应该   效率   form   res   优化   rom   

1. 尽量避免用sub-queres, 可以采用join代替

2. exists代替in

    not exists 和not in 这两个的性能值得深究,应该不是差太多

3. 索引优化

4. 一些操作会导致索引失效

   1)like 操作  

         column_a like ‘%format%‘ 和 column_a Like ‘%format‘ 都会失效

         column_a like ‘format%‘还可以用

    2)索引列上加计算

        select * from salary where sal*10 > 10000;(bad)

        select * from salary where sal> 10000/10;(good)

    3)索引列上面加函数运算

        select * from emp where to_char(empno) =‘10001‘ (bad)

5. distinct 操作会使效率明显下降,必要时可以看有没有备选方案,例如join 和exist 组合操作

    

     

 

 

 

未完待续......

SQL 优化通用方法

标签:函数   for   HERE   应该   效率   form   res   优化   rom   

原文地址:https://www.cnblogs.com/Jesse-Li/p/8821066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!