oracle之sql语句优化

sql语句的优化
  1.在where子句中使用 is null 或 is not null 时,oracle优化器就不能使用索引了.


 2.对于有连接的列,即使最有一个是静态的值,优化器也不会使用索引
比如: select * from employss where first_name||''||last_name='Beill cliton'
要写成 :select * from employss where first_name='Beill' and last_name='Beill cliton'
这时oracle 就会采用 基于 last_name 的索引


  3.带通配符 (%) 的 like 语句
比如: select * from employee where last_name like '%cliton%';
%在词首出现oracle系统就不能使用 last_name 的索引;
select * from employee where last_name like 'cliton%'


4:order by
任何在order by语句的非索引项或者表达式都会降低查询效率;

5:NOT  
<>是就相当于NOT
① select * from salary<>3000;
② select * from salary >3000 or salary <3000
①和②的查询结果是一样的,但②允许oracle对salary列使用索引,效率高

NOT会产生在和在索引列上使用函数相同的影响. 当ORACLE”遇到”NOT,他就会停止使用索引转而执行全表扫描.


6:  exist 代替 in
not exist 代替 not in
select * from A where id in(select id from B)
以上查询使用了in语句,in()只执行一次,它查出B表中的所有id字段并缓存起来.之后,检查A表的id是否与B表中的 id相等,如果相等则将 A表的记录加入结果集中,直到遍历完A表的所有记录.
exist 比 in 的执行效率更高



7:
[img]http://dl.iteye.com/upload/attachment/0081/3997/4881556a-ef38-3e57-b4bf-1de5e0674089.png[/img]


8.where条件的顺序

[img]http://dl.iteye.com/upload/attachment/0081/3999/c463ad40-8f01-3be6-ace4-4a703fc5c467.png[/img]


9:UNION ALL 和 UNION
[img]http://dl.iteye.com/upload/attachment/0081/4001/0c66fbaf-541a-3004-9732-121952a2c438.png[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值