CREATE TABLE emp_compress
(EMPNO NUMBER UNIQUE, ENAME VARCHAR2(10), JOB VARCHAR2(9),
MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER);
CREATE UNIQUE INDEX COMPRESS_UNIQUE_EMP ON EMP_compress(ENAME, EMPNO)
COMPRESS 1;
-# NON-UNIQUE KEY 에 대한 INDEX 압축
-## 오라클이 자동으로 row id 컬럼을 생성
-## 생성된 row id 컬럼 = SUFFIX 부분
-## NON-UNIQUE 컬럼 = PREFIX 부분 = DEPTNO
-## NON-UNIQUE COMPRESS INDEX 생성
CREATE INDEX COMPRESS_NON_UNIQUE_EMP on EMP_compress(DEPTNO) COMPRESS;
-# 인덱스 정보 확인
SQL> select index_name, uniqueness, compression from user_indexes;
INDEX_NAME | UNIQUENESS | COMPRESSION |
---|---|---|
SYS_C005707 | UNIQUE | DISABLED |
BIG_TABLE_PK | UNIQUE | DISABLED |
BIG_TABLE_OWNER_IDX | NONUNIQUE | DISABLED |
PK_EMP | UNIQUE | DISABLED |
{*}COMPRESS_UNIQUE_EMP{*} | {*}UNIQUE{*} | {*}ENABLED{*} |
{*}COMPRESS_NON_UNIQUE_EMP{*} | {*}NONUNIQUE{*} | {*}ENABLED{*} |
PK_DEPT | UNIQUE | DISABLED |
SQL> analyze index COMPRESS_NON_UNIQUE_EMP validate structure;
SQL> select * from index_stats where name like '%NON_UNIQUE_EMP';
SQL> analyze index COMPRESS_NON_UNIQUE_EMP validate structure;
SQL> select * from index_stats where name like '%UNIQUE_EMP';
-# COMPRESS 상태 전환
SQL> ALTER INDEX COMPRESS_NON_UNIQUE_EMP REBUILD NOCOMPRESS;
SQL> ALTER INDEX COMPRESS_UNIQUE_EMP REBUILD NOCOMPRESS;
SQL> select index_name, uniqueness, compression from user_indexes;
INDEX_NAME | UNIQUENESS | COMPRESSION |
---|---|---|
SYS_C005707 | UNIQUE | DISABLED |
BIG_TABLE_PK | UNIQUE | DISABLED |
BIG_TABLE_OWNER_IDX | NONUNIQUE | DISABLED |
PK_EMP | UNIQUE | DISABLED |
{*}COMPRESS_UNIQUE_EMP{*} | {*}UNIQUE{*} | {*}DISABLED{*} |
{*}COMPRESS_NON_UNIQUE_EMP{*} | {*}NONUNIQUE{*} | {*}DISABLED{*} |
PK_DEPT | UNIQUE | DISABLED |
SQL> select * from index_stats where name like '%NON_UNIQUE_EMP';
SQL> select * from index_stats where name like '%UNIQUE_EMP';
-## user_indexes 조회 결과
OPTION | Compress = Enable | Compress = Enable | Compress = Disable | Compress = Disable |
---|---|---|---|---|
{*}NAME{*} | COMPRESS_NON_UNIQUE_EMP | COMPRESS_UNIQUE_EMP | COMPRESS_NON_UNIQUE_EMP | COMPRESS_UNIQUE_EMP |
{*}USED_SPACE{*} | {*}181{*} | {*}363{*} | {*}196{*} | {*}279{*} |
{*}PRE_ROWS{*} | 3 | 14 | 0 | 0 |
{*}PRE_ROWS_LEN{*} | 27 | 168 | 0 | 0 |
{*}ROWS_PER_KEY{*} | 4.667 | 1 | 4.667 | 1 |
{*}PCT_USED{*} | 3 | 5 | 3 | 4 |
{*}BTREE_SPACE{*} | 7992 | 7992 | 7996 | 7996 |
{*}USED_SPACE_Ratio{*} | 2.26 | 4.54 | 2.45 | 3.49 |
{*}LF_ROWS{*} | 14 | 14 | 14 | 14 |
{*}LF_ROWS_LEN{*} | 154 | 195 | 196 | 279 |
{*}BR_ROWS{*} | 0 | 0 | 0 | 0 |
{*}BR_ROWS_LEN{*} | 0 | 0 | 0 | 0 |
{*}DEL_LF_ROWS{*} | 0 | 0 | 0 | 0 |
{*}DEL_LF_ROWS_LEN{*} | 0 | 0 | 0 | 0 |
{*}DISTINCT_KEYS{*} | 3 | 14 | 3 | 14 |
{*}OPT_CMPR_PCTSAVE{*} | 0 | 23 | 7 | 0 |
-# Index Only Table 을 COMPRESS OPTION 을 사용해서 생성하는 예제
--# IOT 테이블 생성
CREATE TABLE EMP_COM_IOT
(EMPNO NUMBER UNIQUE, ENAME VARCHAR2(10), JOB VARCHAR2(9),
MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2),
DEPTNO NUMBER, PRIMARY KEY (ENAME, EMPNO)) ORGANIZATION INDEX COMPRESS;
---# PREFIX 부분 : ENAME(첫 번째 컬럼)
---# DEFAULT : 첫번째 컬럼이 PREFIX 부분으로 잡힘
\\ \\
--# EMP_COM_IOT INDEX 구조
!EMP_COM_IOT_INDEX.jpg!
\\ \\
--# 인덱스 생성 및 분석
SQL> CREATE INDEX IOT_COM_NON_UNIQUE_EMP on EMP_COM_IOT(DEPTNO) COMPRESS;
SQL> ALTER TABLE EMP_COM_IOT MOVE COMPRESS;
SQL> select index_name, uniqueness, compression, num_rows from user_indexes;
SQL> ALTER INDEX IOT_COM_NON_UNIQUE_EMP REBUILD COMPRESS;
SQL> analyze index IOT_COM_NON_UNIQUE_EMP validate structure;
SQL> analyze index SYS_C005709 validate structure;
SQL> analyze index SYS_IOT_TOP_53121 validate structure;
SQL> select * from index_stats;
--# COMPRESS 상태 전환
SQL> ALTER TABLE EMP_COM_IOT MOVE NOCOMPRESS;
SQL> select index_name, uniqueness, compression, num_rows from user_indexes;
SQL> ALTER INDEX IOT_COM_NON_UNIQUE_EMP REBUILD COMPRESS;
SQL> analyze index IOT_COM_NON_UNIQUE_EMP validate structure;
SQL> analyze index SYS_C005709 validate structure;
SQL> analyze index SYS_IOT_TOP_53121 validate structure;
SQL> select * from index_stats;
(on) SYS_IOT_TOP_53121, SYS_C005709 rebuild 하면 에러 발생
--# user_indexes 조회 결과
출처 : OTN포럼