sunfruit[请访问http://www.fruitres.cn]

--我相信JAVA能走得更远 QQ:316228067

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

    --sunfruit

    说明了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; 这时函数索引起作用了

posted on 2006-02-19 17:26 sunfruit 阅读(1182) 评论(0)  编辑  收藏 所属分类: 数据库


只有注册用户登录后才能发表评论。


网站导航: