Oracle优化你的查询--关于避免索引隐式失效

来源:互联网 发布:java培训达内 编辑:程序博客网 时间:2024/05/20 16:01

 

说明了Oracle数据库中的索引隐式失效的问题

1、隐式转换导致索引失效.这一点应当引起重视.也是开发中经常会犯的错误.
    由于表的字段tu_mdn定义为varchar2(20),但在查询时把该字段作为number类型以where条件传给Oracle,这样会导致索引失效.
    错误的例子:select * from test where tu_mdn=13333333333;
    正确的例子:select * from test where tu_mdn='13333333333';
   
2、对索引列进行运算导致索引失效,我所指的对索引列进行运算包括(+,-,*,/,! 等)
    错误的例子:select * from test where id-1=9;
    正确的例子:select * from test where id=10;
   
3、使用Oracle内部函数导致索引失效.对于这样情况应当创建基于函数的索引.
    错误的例子:select * from test where round(id)=10; 说明,此时id的索引已经不起作用了
    正确的例子:首先建立函数索引,create index test_id_fbi_idx on test(round(id));
                     然后 select * from test where round(id)=10; 这时函数索引起作用了

原创粉丝点击