码迷,mamicode.com
首页 > 数据库 > 详细

oracle 查询不走索引的范例分析

时间:2018-01-19 23:29:13      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:auto   数据字典   隐式转换   sel   创建   code   执行   oracle   建议   

like 后%位置不走索引问题

create table t2 as select * from dba_objects;——创建表
create index idx_t2_name on t2(object_name);——创建索引
set autotrace on ——开启执行计划跟踪
select * from t2 where object_name like ‘DE%‘;——走索引
select * from t2 where object_name like ‘%DE‘;——不走索引

查询字段类型与表字段类型不一致导致隐式转换,不走索引问题

create table t3(id varchar2(10),name varchar2(10));——创建表t3
insert into t3 select * from dba_objects;——插入数据
commit; ——提交
create index idx_t3_id on t3(id);创建id索引
set autotrace on——开启执行计划自动跟踪
select * from t3 where id=7000;——不走索引,会出现隐式转换,filter(TO_NUMBER("ID")=7000)
select * from t3 where id=‘7000‘;——走索引,cost大大提升

另:不要用select ‘*‘ from........写select 星号时,oracle会查询数据字典再转换成具体的列名,增加oracle的开销,建议写具体字段名称。
附:查询表的索引信息
select INDEX_NAME,INDEX_TYPE,TABLE_OWNER,TABLE_NAME,TABLESPACE_NAME from user_indexes where table_name=‘T1‘;

oracle 查询不走索引的范例分析

标签:auto   数据字典   隐式转换   sel   创建   code   执行   oracle   建议   

原文地址:http://blog.51cto.com/12185273/2063034

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!