索引失效的条件(Oracle)

   1.没有 where 子句

   2.使用 like '%T' 进行模糊查询
    例: select * from t_owners where name like '%李'
    索引不失效:  select * from t_owners where name like '张%'

   3.使用 is null和 is not null 针对null值查询,索引无效
    例:select * from t_pricetable where max is null;
   4.where子句中使用不等于操作       例:<>      !=       not  in
    例:select * from t_account where money <>100;
    可以使用:select * from t_account where money>100 or money<100;

   5.where子句中使用函数
    例:select * from t_owners where round(id) > 5
    可以使用: create index idx_owners_id on t_owners(round(id));  --建立函数索引
          select * from t_owners where round(id) > 5  

   6.隐式转换时索引失效   (比较时类型不匹配)
    例:select * from t_account  where year = 2012
          oracle在执行时,会把以上语句变为:select * from t_account  where  to_number(year) = 2012
    正确写法:select * from t_account  where year = '2012';

   7.对索引列进行运算时导致索引失
    例:select * from t_owners where id-1=5;
    正确的写法:select * from t_owners where id=6;
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值