当前位置:Gxlcms > 数据库问题 > oracle 不走索引的几种情况

oracle 不走索引的几种情况

时间:2021-07-01 10:21:17 帮助过:21人阅读

不走索引的其它原因:     

1、建立组合索引,但查询谓词并未使用组合索引的第一列,此处有一个INDEX SKIP SCAN概念。     

2、在包含有null值的table列上建立索引,当时使用select count(*) from table时不会使用索引。     

3、在索引列上使用函数时不会使用索引,如果一定要使用索引只能建立函数索引。     

4、当被索引的列进行隐式的类型转换时不会使用索引。如:select * from t where indexed_column = 5,而indexed_column列建立索引但类型是字符型,这时Oracle会产生隐式的类型转换,转换后的语句类似于select * from t where to_number(indexed_column) = 5,此时不走索引的情况类似于case3。日期转换也有类似问题,如: select * from t where trunc(date_col) = trunc(sysdate)其中date_col为索引列,这样写不会走索引,可改写成select * from t where date_col >= trunc(sysdate) and date_col < trunc(sysdate+1),此查询会走索引。     

5、并不是所有情况使用索引都会加快查询速度,full scan table 有时会更快,尤其是当查询的数据量占整个表的比重较大时(大约为大于总量的20%时),因为full scan table采用的是多块读,当Oracle优化器没有选择使用索引时不要立即强制使用,要充分证明使用索引确实查询更快时再使用强制索引。     

6、<>     

7、like’%dd’百分号在前。    

8、not in,not exist

oracle 不走索引的几种情况

标签:字符型   where   百分号   情况   null   概念   index   scan   数据   

人气教程排行