索引失效的條件 Oracle

2021-09-25 10:56:32 字數 1102 閱讀 7097

1.沒有 where 子句

2.使用 like '%t' 進行模糊查詢

例: select * from t_owners where name like '%李'

索引不失效:  select * from t_owners where name like '張%'

3.使用 is null和 is not null 針對null值查詢,索引無效

例:select * from t_pricetable where max is null;

4.where子句中使用不等於操作       例:<>      !=       not  in

例:select * from t_account where money <>100;

可以使用:select * from t_account where money>100 or money<100;

5.where子句中使用函式

例:select * from t_owners where round(id) > 5

可以使用: create index idx_owners_id on t_owners(round(id));  --建立函式索引

select * from t_owners where round(id) > 5  

6.隱式轉換時索引失效   (比較時型別不匹配)

例:select * from t_account  where year = 2012

oracle在執行時,會把以上語句變為:select * from t_account  where  to_number(year) = 2012

正確寫法:select * from t_account  where year = '2012';

7.對索引列進行運算時導致索引失

例:select * from t_owners where id-1=5;

正確的寫法:select * from t_owners where id=6;

索引失效的條件

索引失效的條件 1.條件中用or,即使其中有條件帶索引,也不會使用索引查詢 這就是查詢盡量不要用or的原因,用in吧 注意 使用or,又想索引生效,只能將or條件中的每個列都加上索引 2.對於多列索引,不是使用的第一部分,則不會使用索引。3.like的模糊查詢以 開頭,索引失效 4.如果列型別是字串...

oracle 索引失效的原因

索引失效 1 沒有查詢條件,或者查詢條件沒有建立索引 2 在查詢條件上沒有使用引導列 3 查詢的數量是大表的大部分,應該是30 以上。4 索引本身失效 5 查詢條件使用函式在索引列上 見12 6 對小表查詢 7 提示不使用索引 8 統計資料不真實 9 cbo計算走索引花費過大的情況。其實也包含了上面...

oracle 索引失效的原因

文章 url 失效原因 索引失效 1 沒有查詢條件,或者查詢條件沒有建立索引 2 在查詢條件上沒有使用引導列 3 查詢的數量是大表的大部分,應該是30 以上。4 索引本身失效 5 查詢條件使用函式在索引列上 見12 6 對小表查詢 7 提示不使用索引 8 統計資料不真實 9 cbo計算走索引花費過大...