如果表的查询中的所有列都被包含在索引中,而索引的前导列并不在WHERE条件中时,就可以使用快速全局扫描。
实验验证:
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 | | 1 | 37 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMPT | 1 | 37 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------
1 - filter("DEPTNO"=20)
已选择13行。
SQL> explain plan for select empno,ename,deptno from empt where deptno=20;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 161062661
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 33 | 1 (0)| 00:00:01 |
|* 1 | INDEX FULL SCAN| EMPT_ID1 | 1 | 33 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - access("DEPTNO"=20)
filter("DEPTNO"=20)
已选择14行。
由于SQL语句中的所有列都包含在索引中并且表经过了分析,这样就可以执行快速全局扫描。
注意:如果索引相对于表的总体大小来说很小,快速全局扫描可使程序的性能陡增。如果表中有一个包含了大部分列的组合索引,索引可能要比真实的表要大,这样快速全局扫描反而会降低性能。
1554

被折叠的 条评论
为什么被折叠?



