组合索引

组合索引,顾名思义是多个列组成的索引。它通常会比单列的索引更有效率。

要让oracle能够使用到一个组合索引,要求where条件中要包含该索引的先导列。比如:

create index ind1 on test(col1,col2,col3,col4);

对于这个组合索引,只要where条件里有col1,那么就可以使用。

 

有时候,where条件不包含先导列,也仍然可以使用组合索引。这种情况叫做索引跳跃扫描 index skip scan。 不过这种情况只有是先导列唯一值比较少才有意义。因为这种模式是对先导列的所有唯一值都执行查询。

SQL> create table test as select * from dba_objects;

Table created.

SQL> create index test_ont on test(owner,object_name,object_type);

Index created.

SQL> exec dbms_stats.gather_table_stats('SYS','TEST',cascade=>true);

PL/SQL procedure successfully completed.

SQL> select owner,object_name,object_type from test where object_name='TEST';


Execution Plan
----------------------------------------------------------
Plan hash value: 3426820653

-----------------------------------------------------------------------------
| Id  | Operation        | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT |          |     2 |    80 |    22   (0)| 00:00:01 |
|*  1 |  INDEX SKIP SCAN | TEST_ONT |     2 |    80 |    22   (0)| 00:00:01 |
-----------------------------------------------------------------------------

 

posted on 2014-08-08 16:46  kramer  阅读(828)  评论(0编辑  收藏  举报

导航