日期:2014-05-16  浏览次数:20459 次

Oracle索引学习笔记

反向关键字索引会降低争用的特定块可能性,但,只对等式谓词有改进作用!!!


index full scan可用于消除排序操作,因为数据是按索引关键字排序的,她是使用单个块I/O读取索引(不同于fast index full scan)
fast index full scan不能用于消除排序操作,因为数据不按索引关键字排序,通常比普通的IFS快,因为她可以像FTS一样使用多个块I/O


处理B*树索引时一种常见错误是忘记处理空值。A good example:
create table nulltest(col1 number,col2 number not null);
create index nullind1 on nulltest (col1);
create index notnullind2 on nulltest (col2);
select /*+ index(t nullind1) */ col1 from nulltest t; --FTS

? ------------------------------------------
| Id? | Operation???????? | Name???? | Rows? | Bytes | Cost (%CPU)| Time???? |
------------------------------------------
|?? 0 | SELECT STATEMENT? |????????? |???? 1 |??? 13 |???? 2?? (0)| 00:00:01 |
|?? 1 |? TABLE ACCESS FULL| NULLTEST |???? 1 |??? 13 |???? 2?? (0)| 00:00:01 |
------------------------------------------


select col1 from nulltest t where col1=10; --index range scan

-----------------------------------------
| Id? | Operation??????? | Name???? | Rows? | Bytes | Cost (%CPU)| Time???? |
-----------------------------------------
|?? 0 | SELECT STATEMENT |????????? |???? 1 |??? 13 |???? 1?? (0)| 00:00:01 |
|*? 1 |? INDEX RANGE SCAN| NULLIND1 |???? 1 |??? 13 |???? 1?? (0)| 00:00:01 |
-----------------------------------------


select /*+ index(t notnullind2) */ col2 from nulltest t; --IFS

--------------------------------------------
| Id? | Operation??????? | Name??????? | Rows? | Bytes | Cost (%CPU)| Time???? |
--------------------------------------------
|?? 0 | SELECT STATEMENT |???????????? |???? 1 |??? 13 |???? 2?? (0)| 00:00:01 |
|?? 1 |? INDEX FULL SCAN | NOTNULLIND2 |???? 1 |??? 13 |???? 2?? (0)| 00:00:01 |
--------------------------------------------