欢迎光临
我们一直在努力

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

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。