oracle执行计划中不走索引的情况

1、查询中不含where条件
select * from t;

2、含有where条件,但是没有索引列出现在where条件中
select * from t where x=1;

3、模糊查询和使用is null或者is not null的不会走索引
select * from t where y like ‘100%’;
select * from t where y like ‘%a’; 转换成"Y" LIKE ‘%a’ AND “Y” IS NOT NULL
select * from t where y is not null;
select * from t where y is null;

4、当查询的结果超过了表中的30%值时候,走索引不如走全表扫描

5、统计信息过期了
exec dbms_stats.gather_table_stats(ownname=>‘SYS’,tabname=>‘T’,estimate_percent=>100,cascade=>TRUE,no_invalidate=>false);
analyze table t compute statistics for all indexes;

6、where中使用了不等操作符
select * from t where y<>‘1a’;
select * from t where y!=‘1a’;
select * from t where y not in (‘1a’,‘2a’); 转换成"Y"<>‘1a’ AND “Y”<>‘2a’
select * from t where y in (‘1a’,‘2a’); 转换成"Y"=‘1a’ OR “Y”=‘2a’
select * from t where y=‘1a’ or x=1;
select * from t where y>‘900a’;
select * from t where y<‘900a’;
select * from t where not y<‘900a’; 转换成"Y">=‘900a’
select * from t where not y>‘900a’; 转换成"Y"<=‘900a’
select * from t where y between ‘10a’ and ‘30a’; 转换成"Y"<=‘30a’ AND “Y”>=‘10a’
select * from t where not exists (select * from t where x=1000);
select * from t where exists (select * from t where x=1000);

7、函数索引的使用情况
索引列出现了函数,但是没有创建函数索引,那么就会导致索引失效
create or replace function f(p_value varchar2) return varchar2
deterministic is
begin
return p_value;
end;

创建普通索引
create index idx_t on t(y);
—走索引
select * from t where y=‘1a’;
—不走索引,因为索引列有函数
select * from t where f(y)=‘1a’;
–走索引
select * from t where y=f(‘1a’);

创建函数索引
create index idx_f_t on t (f(y));
–走索引,走函数索引idx_f_t
select * from t where f(y)=‘1a’;

对于min max等函数可以使用普通索引
select max(x) from t; 这个走索引来查询INDEX FULL SCAN (MIN/MAX)| IDX_XY_T
select min(x) from t;

使用函数索引一定要注意在函数代码变更后重建函数索引

8、对于索引列使用运算式会导致失效
select * from t where x+1=3;

9、对于复合索引的情况
create index idx_xy_t on t(x,y);
–不会走索引,因为where中没有复合索引的前导列x
select * from t where y=‘1a’;
–会走索引,因为where中有复合索引的前导列x
select * from t where y=‘1a’ and x=1;
select * from t where x=1;

10、并行查询不会用到索引
select /*+ parallel (2,t) */ * from t where y=‘10a’;

11、SortMergeJoin(SMJ)、HashJoin(HJ)和NestedLoopJoin(NL)。
在两张表连接,且内表的目标列上建有索引时,只有NestedLoop才能有效地利用到该索引。
SMJ即使相关列上建有索引,最多只能因索引的存在,避免数据排序过程。
HJ由于须做HASH运算,索引的存在对数据查询速度几乎没有影响。

查看索引
select owner,index_name,table_owner,table_name from dba_indexes where table_name=‘T’;

你可能感兴趣的:(oracle,数据库)