当前位置: 代码迷 >> Oracle开发 >> 为什么select * 就没有用到索引
  详细解决方案

为什么select * 就没有用到索引

热度:93   发布时间:2016-04-24 06:36:11.0
为何select * 就没有用到索引?

select 某个字段可以

但是join后又没了


我的目的是这句sql很慢,要3s,ts_outphone_list 表有500w,ts_outphone_batch 很少
 select count(*) from ts_outphone_list l where l.TASK_STATUS = '3'
           and l.agentid = '4005'  这样是1s钟

select count(*)
  from (select l.*
          from ts_outphone_list l
         inner join ts_outphone_batch b
            on l.batchnum = b.batchnum
         where  l.TASK_STATUS = '3'
           and l.agentid = '4005') a

------解决思路----------------------
你的索引是怎么建的?
我猜是TASK_STATUS、agentid、batchnum这三个字段的组合索引
当结果集中存在除这3项之外的字段时就会不走索引而是全表扫描
oracle自身优化时除了考虑利用索引提升查询速度,还会考虑数据io消耗等多方面的因素,最终选取一种最合适的方案
  相关解决方案