在Oracle 9i引入跳跃式扫描的索引访问方法之前,查询只能在有限条件下使用该索引。除非在WHERE子句中对第一列指定一个值,否则就不能使用这个索引键进行一次范围扫描。
示例:对组合索引empt_id1(empno,ename,deptno)的测试
SQL> explain plan for select * from empt where empno=7369 and ename='SMITH' and
deptno=20;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1829075880
--------------------------------------------------------------------------------
--------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Ti
me |
--------------------------------------------------------------------------------
--------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 87 | 2 (0)| 00
:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPT | 1 | 87 | 2 (0)| 00
:00:01 |
|* 2 | INDEX RANGE SCAN | EMPT_ID1 | 1 | | 1 (0)| 00
:00:01 |
--------------------------------------------------------------------------------
--------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO"=7369 AND "ENAME"='SMITH' AND "DEPTNO"=20)
Note
-----
- dynamic sampling used for this statement
已选择18行。
SQL> explain plan for select * from empt where empno=7369;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1829075880
--------------------------------------------------------------------------------
--------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Ti
me |
--------------------------------------------------------------------------------
--------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 87 | 2 (0)| 00
:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPT | 1 | 87 | 2 (0)| 00
:00:01 |
|* 2 | INDEX RANGE SCAN | EMPT_ID1 | 1 | | 1 (0)| 00
:00:01 |
--------------------------------------------------------------------------------
--------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO"=7369)
Note
-----
- dynamic sampling used for this statement
已选择18行。
SQL> explain plan for select * from empt where deptno=20;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1497070856
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 435 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMPT | 5 | 435 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - filter("DEPTNO"=20)
Note
-----
- dynamic sampling used for this statement
已选择17行。
注意:在Oracle 9i之前,只有在使用到索引的前导引时才可使用组合索引。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15203236/viewspace-536279/ ,如需转载,请注明出处,否则将追究法律责任。