建立分区索引的优点是 可以分散IO的压力。

分区索引分为全局分区索引和本地分区索引。

一、现在创建全局索引

1、创建表空间tablespace

SQL>create tablespace ts01 logging datafile '/oracle/app/oradata/TEST/ts01.dbf' size 100m;
SQL>create tablespace ts02 logging datafile '/oracle/app/oradata/TEST/ts02.dbf' size 100m;
SQL>create tablespace ts03 logging datafile '/oracle/app/oradata/TEST/ts03.dbf' size 100m;
SQL>create tablespace ts04 logging datafile '/oracle/app/oradata/TEST/ts04.dbf' size 100m;

2、创建范围分区表

table_name为test123,

partition p1存放<10000的数据。

partition p2存放大于10000小于20000的数据。

partition p3存放大于20000小于50000的数据。

partition p4存放大于50000的数据。
 

SQL> create table test123 partition by range(object_id)
    (
    partition p1 values less than (10000) tablespace ts01,
    partition p2 values less than (20000) tablespace ts02,
    partition p3 values less than (50000) tablespace ts03,
    partition p4 values less than (maxvalue) tablespace ts04)
    as select * from dba_objects;

3、创建全局分区表索引

  全局分区表索引的区域划分不用以范围分区表划分的一致。


SQL> create index idx123 on test123(object_id)
    global partition by range(object_id)
    (
    partition idx_1 values less than(10000) tablespace ts01,
    partition idx_2 values less than(25000) tablespace ts02,
    partition idx_3 values less than(50000) tablespace ts03,
    partition idx_4 values less than(maxvalue) tablespace ts04);

4、测试

SQL> set autotrace traceonly;(开启自动跟踪)

SQL> select * from test123 where object_id=3001;(检索object_id=3001)

 

 

 

 

 

二、创建本地分区表索引

1、SQL> create index idx123 on test123(object_id) local; (本地分区表的创建和创建普通的索引类似)

2、 SQL>select index_name,PARTITIONED from dba_indexes where table_name='TEST123';

 

显示类型为分区。