您的位置:首页 > 数据库 > Oracle

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

2018-01-19 22:22 555 查看
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 查询优化