標籤:
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 $amp;<amp;$gt;是就相當於not p="" 當oracle”遇到”not,他就會停止使用索引轉而執行全表掃描.<="" not會產生在和在索引列上使用函數相同的影響.="" ①和②的查詢結果是一樣的,但②允許oracle對salary列使用索引,效率高="" <3000="" salary="" or="" >3000="" from="" *="" select="" ②="" salary$amp;<amp;$gt;3000;="" ①="">
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:
8.where條件的順序
9:UNION ALL 和 UNION
oracle之sql語句最佳化