create table orders (
order_id number
,name varchar2(30)
,order_date date
)
indexing off ---(1)
partition by range (order_date)
(
partition p_1 values less than (to_date('2015/01/01','yyyy/mm/dd')) indexing off, ---(2)
partition p_2 values less than (to_date('2016/01/01','yyyy/mm/dd')) indexing on, ---(3)
partition p_3 values less than (to_date('2017/01/01','yyyy/mm/dd')) ---(4)
)
;
alter table orders modify partition p_1 indexing on; ---(5)
alter table orders modify partition p_1 indexing off;
SQL> select
table_name, partition_name, indexing
from user_tab_partitions where table_name='ORDERS'
;
TABLE_NAME PARTITION_NAME INDE
------------------------------ ------------------------------ ----
ORDERS P_1 OFF
ORDERS P_2 ON
ORDERS P_3 OFF
SQL> create index ind1_orders_full on orders(order_date, order_id, name) global indexing full;
Index created.
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_FULL';
INDEX_NAME TABLE_NAME INDEXING
------------------------------ ------------------------------ --------
IND1_ORDERS_FULL ORDERS FULL
SQL>
SQL> select bytes from dba_Segments where segment_name='IND1_ORDERS_FULL';
BYTES
----------
284164096
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, NUM_ROWS FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_FULL';
INDEX_NAME TABLE_NAME INDEXIN NUM_ROWS
------------------------------ ------------------------------ ------- ----------
IND1_ORDERS_FULL ORDERS FULL 4540569
SQL> create index ind1_orders_partial on orders(order_id, name, order_date) global indexing partial;
Index created.
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_PARTIAL';
INDEX_NAME TABLE_NAME INDEXING
------------------------------ ------------------------------ --------
IND1_ORDERS_PARTIAL ORDERS PARTIAL
SQL> select bytes from dba_Segments where segment_name='IND1_ORDERS_PARTIAL';
BYTES
----------
65536
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, NUM_ROWS FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_PARTIAL';
INDEX_NAME TABLE_NAME INDEXIN NUM_ROWS
------------------------------ ------------------------------ ------- ----------
IND1_ORDERS_PARTIAL ORDERS PARTIAL 450
SQL>
SQL> create index ind2_orders_full on orders(order_date, name) local indexing full;
Index created.
SQL> select segment_name, partition_name, bytes from dba_Segments where segment_name='IND2_ORDERS_FULL';
SEGMENT_NAME PARTITION_NAME BYTES
------------------------------ ------------------------------ ----------
IND2_ORDERS_FULL P_3 196608
IND2_ORDERS_FULL P_2 65536
IND2_ORDERS_FULL P_1 234881024
SQL>
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, GLOBAL_STATS, NUM_ROWS FROM USER_INDEXES WHERE INDEX_NAME='IND2_ORDERS_FULL';
INDEX_NAME TABLE_NAME INDEXIN GLO NUM_ROWS
------------------------------ ------------------------------ ------- --- ----------
IND2_ORDERS_FULL ORDERS FULL NO 4540569
SQL> select INDEX_NAME, PARTITION_NAME, NUM_ROWS from user_ind_partitions where index_name='IND2_ORDERS_FULL';
INDEX_NAME PARTITION_NAME NUM_ROWS
------------------------------ ------------------------------ ----------
IND2_ORDERS_FULL P_1 4537650
IND2_ORDERS_FULL P_2 450
IND2_ORDERS_FULL P_3 2469
SQL> create index ind2_orders_partial on orders(order_date, name) local indexing partial;
Index created.
SQL> select segment_name, partition_name, bytes from dba_Segments where segment_name='IND2_ORDERS_PARTIAL';
SEGMENT_NAME PARTITION_NAME BYTES
------------------------------ ------------------------------ ----------
IND2_ORDERS_PARTIAL P_2 65536
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, GLOBAL_STATS, NUM_ROWS FROM USER_INDEXES WHERE INDEX_NAME='IND2_ORDERS_PARTIAL';
INDEX_NAME TABLE_NAME INDEXIN GLO NUM_ROWS
------------------------------ ------------------------------ ------- --- ----------
IND2_ORDERS_PARTIAL ORDERS PARTIAL NO 450
SQL> select INDEX_NAME, PARTITION_NAME, NUM_ROWS, STATUS, SEGMENT_CREATED from user_ind_partitions where index_name='IND2_ORDERS_PARTIAL';
INDEX_NAME PARTITION_NAME NUM_ROWS STATUS SEG
------------------------------ ------------------------------ ---------- -------- ---
IND2_ORDERS_PARTIAL P_1 0 UNUSABLE NO
IND2_ORDERS_PARTIAL P_2 450 USABLE YES
IND2_ORDERS_PARTIAL P_3 0 UNUSABLE NO
SQL> alter index ind1_orders_partial rebuild ;
Index altered.
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, NUM_ROWS FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_PARTIAL';
INDEX_NAME TABLE_NAME INDEXIN NUM_ROWS
------------------------------ ------------------------------ ------- ----------
IND1_ORDERS_PARTIAL ORDERS PARTIAL 450
SQL> alter table orders modify partition p_3 indexing on ;
Table altered.
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, NUM_ROWS, STATUS FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_PARTIAL';
INDEX_NAME TABLE_NAME INDEXIN NUM_ROWS STATUS
------------------------------ ------------------------------ ------- ---------- --------
IND1_ORDERS_PARTIAL ORDERS PARTIAL 450 VALID
SQL> alter index IND1_ORDERS_PARTIAL rebuild ;
Index altered.
SQL> SELECT INDEX_NAME, TABLE_NAME, INDEXING, NUM_ROWS, STATUS FROM USER_INDEXES WHERE INDEX_NAME='IND1_ORDERS_PARTIAL';
INDEX_NAME TABLE_NAME INDEXIN NUM_ROWS STATUS
------------------------------ ------------------------------ ------- ---------- --------
IND1_ORDERS_PARTIAL ORDERS PARTIAL 2919 VALID
SQL>
-- 생성되지 않은 partitial index 에 rebuild 시에는?
SQL> alter index IND2_ORDERS_PARTIAL rebuild partition p_1 ;
Index altered.
SQL> select INDEX_NAME, PARTITION_NAME, NUM_ROWS, STATUS, SEGMENT_CREATED from user_ind_partitions where index_name='IND2_ORDERS_PARTIAL';
INDEX_NAME PARTITION_NAME NUM_ROWS STATUS SEG
------------------------------ ------------------------------ ---------- -------- ---
IND2_ORDERS_PARTIAL P_1 4537650 USABLE YES
IND2_ORDERS_PARTIAL P_2 450 USABLE YES
IND2_ORDERS_PARTIAL P_3 0 UNUSABLE NO
SQL>
-- indexing 되지 않은 partition 에 altering 시에는?
SQL> alter table orders modify partition p_3 indexing on ;
Table altered.
SQL>
SQL> select INDEX_NAME, PARTITION_NAME, NUM_ROWS, STATUS, SEGMENT_CREATED from user_ind_partitions where index_name='IND2_ORDERS_PARTIAL';
INDEX_NAME PARTITION_NAME NUM_ROWS STATUS SEG
------------------------------ ------------------------------ ---------- -------- ---
IND2_ORDERS_PARTIAL P_1 4537650 USABLE YES
IND2_ORDERS_PARTIAL P_2 450 USABLE YES
IND2_ORDERS_PARTIAL P_3 2469 USABLE YES
SQL>
-- 이 때 table partition 속성은?
SQL> select
table_name, partition_name, indexing
from user_tab_partitions where table_name='ORDERS'
;
TABLE_NAME PARTITION_NAME INDE
------------------------------ ------------------------------ ----
ORDERS P_1 OFF -- local index rebuild
ORDERS P_2 ON
ORDERS P_3 ON -- partition indexing on
SQL>
- 강좌 URL : http://www.gurubee.net/lecture/4264
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.