Sometimes we need to create indexes for some partitions. Oracle 11g provides this function. You can create local and global indexes on partial partitions.
Global partial index: only those partitions that need to be indexed will be indexed, and other partitions will not be created.
Local index: if index is turned on for table partition, index partition is available; otherwise, it is not available. You can override this behavior by specifying USABLE / UNUSABLE at the index or index partition level.
This function does not support unique index. full is the default mode.
The indexing clause can be specified at the level of a partition or sub partition.
The following example is taken from the official website
CREATE TABLE orders (
order_id NUMBER(12),
order_date DATE CONSTRAINT order_date_nn NOT NULL,
order_mode VARCHAR2(8),
customer_id NUMBER(6) CONSTRAINT order_customer_id_nn NOT NULL,
order_status NUMBER(2),
order_total NUMBER(8,2),
sales_rep_id NUMBER(6),
promotion_id NUMBER(6),
CONSTRAINT order_mode_lov CHECK (order_mode in ('direct','online')),
CONSTRAINT order_total_min CHECK (order_total >= 0))
INDEXING OFF
PARTITION BY RANGE (ORDER_DATE)
(PARTITION ord_p1 VALUES LESS THAN (TO_DATE('01-MAR-1999','DD-MON-YYYY'))
INDEXING ON,
PARTITION ord_p2 VALUES LESS THAN (TO_DATE('01-JUL-1999','DD-MON-YYYY'))
INDEXING OFF,
PARTITION ord_p3 VALUES LESS THAN (TO_DATE('01-OCT-1999','DD-MON-YYYY'))
INDEXING ON,
PARTITION ord_p4 VALUES LESS THAN (TO_DATE('01-MAR-2000','DD-MON-YYYY')),
PARTITION ord_p5 VALUES LESS THAN (TO_DATE('01-MAR-2010','DD-MON-YYYY')));
//Create global index
CREATE INDEX ORDERS_ORDER_TOTAL_GIDX ON ORDERS (ORDER_TOTAL)
GLOBAL INDEXING PARTIAL;
SQL> select index_name,index_type,partitioned,orphaned_entries,indexing from user_indexes;
INDEX_NAME INDEX_TYPE PAR ORP INDEXIN
------------------------------ --------------------------- --- --- -------
PK_DEPT NORMAL NO NO FULL
PK_EMP NORMAL NO NO FULL
ORDERS_ORDER_TOTAL_GIDX NORMAL NO NO PARTIAL
SQL> select * from user_ind_partitions ;
no rows selected
//Next, create the local partition index
create index idx_orders_local on orders(order_date) local;
select index_name,partition_name,status from user_ind_partitions ;
SQL> select index_name,partition_name,status from user_ind_partitions ;
INDEX_NAME PARTITION_NAME STATUS
-------------------- -------------------- --------
IDX_ORDERS_LOCAL ORD_P1 USABLE
IDX_ORDERS_LOCAL ORD_P2 USABLE
IDX_ORDERS_LOCAL ORD_P3 USABLE
IDX_ORDERS_LOCAL ORD_P4 USABLE
IDX_ORDERS_LOCAL ORD_P5 USABLE
SQL> create index idx_orders_local on orders(order_date) local indexing partial;
Index created.
SQL> select index_name,partition_name,status from user_ind_partitions ;
INDEX_NAME PARTITION_NAME STATUS
-------------------- -------------------- --------
IDX_ORDERS_LOCAL ORD_P1 USABLE
IDX_ORDERS_LOCAL ORD_P2 UNUSABLE
IDX_ORDERS_LOCAL ORD_P3 USABLE
IDX_ORDERS_LOCAL ORD_P4 UNUSABLE
IDX_ORDERS_LOCAL ORD_P5 UNUSABLE
//You can see that the local partition index only sets the state of the partition containing the indexing property to usable