分区索引的建立方式,作用是什么
分区索引分为两种:全局索引、本地索引。
全局索引是一个或多个共同承担索引任务,提高I/O性能
本地索引只承担本地分区表内的索引任务
1.创建4个表空间
SQL> create tablespace tst01 logging datafile '/oracle/app/tst01.dbf' size 100m;
Tablespace created.
SQL> create tablespace tst02 logging datafile '/oracle/app/tst02.dbf' size 100m;
Tablespace created.
SQL> create tablespace tst03 logging datafile '/oracle/app/tst03.dbf' size 100m;
Tablespace created.
SQL> create tablespace tst04 logging datafile '/oracle/app/tst04.dbf' size 100m;
Tablespace created.
2.创建范围分区表
 
SQL> create table test567 partition by range(object_id)
  2      (
  3      partition p1 values less than (10000) tablespace tst01,
  4      partition p2 values less than (20000) tablespace tst02,
  5      partition p3 values less than (50000) tablespace tst03,
  6      partition p4 values less than (maxvalue) tablespace tst04)
  7      as select * from dba_objects;
Table created.
3.创建全局分区表索引
SQL> create index idx567 on test567(object_id)
  2      global partition by range(object_id)
  3      (
  4      partition idx_1 values less than(10000) tablespace tst01,
  5      partition idx_2 values less than(25000) tablespace tst02,
  6      partition idx_3 values less than(50000) tablespace tst03,
  7      partition idx_4 values less than(maxvalue) tablespace tst04);
Index created.
4.效果
SQL> set autotrace traceonly;
SQL> select * from test567 where object_id=30001;
| Id  | Operation                           | Name    | Rows  | Bytes | Cost (%C
PU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------
-------------------------------
|   0 | SELECT STATEMENT                    |         |     1 |   177 |     2
(0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE             |         |     1 |   177 |     2
(0)| 00:00:01 |     3 |     3 |
|   2 |   TABLE ACCESS BY GLOBAL INDEX ROWID| TEST567 |     1 |   177 |     2
(0)| 00:00:01 |     3 |     3 |
|*  3 |    INDEX RANGE SCAN                 | IDX567  |     1 |       |     1
(0)| 00:00:01 |     3 |     3 |
--------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          4  consistent gets
          0  physical reads
          0  redo size
       1227  bytes sent via SQL*Net to client
        385  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
6.创建本地分区表索引
SQL> create index idx567 on test567(object_id) local;
| Id  | Operation                          | Name    | Rows  | Bytes | Cost (%CP
U)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------
------------------------------
|   0 | SELECT STATEMENT                   |         |     1 |   177 |     2   (
0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE            |         |     1 |   177 |     2   (
0)| 00:00:01 |     1 |     1 |
|   2 |   TABLE ACCESS BY LOCAL INDEX ROWID| TEST567 |     1 |   177 |     2   (
0)| 00:00:01 |     1 |     1 |
|*  3 |     INDEX RANGE SCAN                | IDX567  |     1 |       |     1   (
0)| 00:00:01 |     1 |     1 |
--------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          4  consistent gets
          0  physical reads
          0  redo size
       1198  bytes sent via SQL*Net to client
        385  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed