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’;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值