sql语句的优化
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]
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]