PT - Oracle Compression Basic and advanced
- Query to check table compression
SQL> SELECT TABLE_NAME, COMPRESSION, COMPRESS_FOR FROM USER_TABLES;
TABLE_NAME COMPRESS COMPRESS_FOR
----------------- -------- ------------------------------
ADDRESSES DISABLED
PRODUCT_INFORMATI DISABLED
ON
LOGON DISABLED
ORDERS DISABLED
CARD_DETAILS DISABLED
INVENTORIES DISABLED
WAREHOUSES DISABLED
JOBS DISABLED
CUSTOMERS DISABLED
TABLE_NAME COMPRESS COMPRESS_FOR
----------------- -------- ------------------------------
PRODUCT_DESCRIPTI DISABLED
ONS
ORDER_ITEMS DISABLED
V DISABLED
JOB_HISTORY DISABLED
EMP DISABLED
DEPT DISABLED
ORDERENTRY_METADA DISABLED
TA
TABLE_NAME COMPRESS COMPRESS_FOR
----------------- -------- ------------------------------
CUST_SOURCE DISABLED
CUST_BCOMPRESSED ENABLED BASIC
CUST_ACOMPRESSED ENABLED ADVANCED
19 rows selected.
SQL>
- Create table with no compression basic and advanced.
SQL> conn soe/soe
Connected.
SQL> CREATE TABLE CUST_SOURCE
2 ( CUSTOMER_NO NUMBER(6),
3 FIRST_NAME VARCHAR2(20),
4 LAST_NAME VARCHAR2(20),
5 NOTE1 VARCHAR2(100),
6 NOTE2 VARCHAR2(100)
7 ) NOLOGGING PCTFREE 0 TABLESPACE SOETBS;
Table created.
SQL> CREATE TABLE CUST_BCOMPRESSED
2 ( CUSTOMER_NO NUMBER(6),
3 FIRST_NAME VARCHAR2(20),
4 LAST_NAME VARCHAR2(20),
5 NOTE1 VARCHAR2(100),
6 NOTE2 VARCHAR2(100)
7 ) ROW STORE COMPRESS BASIC NOLOGGING TABLESPACE SOETBS;
Table created.
SQL> CREATE TABLE CUST_ACOMPRESSED
2 ( CUSTOMER_NO NUMBER(6),
3 FIRST_NAME VARCHAR2(20),
4 LAST_NAME VARCHAR2(20),
5 NOTE1 VARCHAR2(100),
6 NOTE2 VARCHAR2(100)
7 ) ROW STORE COMPRESS ADVANCED NOLOGGING PCTFREE 0 TABLESPACE SOETBS;
Table created.
- Insert value on all tables.
SQL> INSERT INTO CUST_SOURCE
2 SELECT LEVEL AS CUSTOMER_NO,
3 DBMS_RANDOM.STRING('A', TRUNC(DBMS_RANDOM.value(10,20))) FIRST_NAME,
4 DBMS_RANDOM.STRING('A', TRUNC(DBMS_RANDOM.value(10,20))) LAST_NAME,
5 DBMS_RANDOM.STRING('A', TRUNC(DBMS_RANDOM.value(0,100))) NOTE1,
6 DBMS_RANDOM.STRING('A', TRUNC(DBMS_RANDOM.value(0,100))) NOTE2
7 FROM DUAL
8 CONNECT BY LEVEL <= 100000;
100000 rows created.
SQL> COMMIT;
Commit complete.
SQL> INSERT INTO CUST_BCOMPRESSED SELECT * FROM CUST_SOURCE;
100000 rows created.
SQL> COMMIT;
Commit complete.
- Gather stats on the all tables.
SQL> exec DBMS_STATS.GATHER_TABLE_STATS(USER,'CUST_SOURCE');
PL/SQL procedure successfully completed.
SQL> exec DBMS_STATS.GATHER_TABLE_STATS(USER,'CUST_BCOMPRESSED');
PL/SQL procedure successfully completed.
SQL>
- Check block size compression on the all tables
SQL> col TABLE_NAME format a17
SQL> SELECT TABLE_NAME, BLOCKS*8 SIZE_KB, COMPRESSION, PCT_FREE
2 FROM USER_TABLES
3 WHERE TABLE_NAME IN ('CUST_SOURCE','CUST_BCOMPRESSED','CUST_ACOMPRESSED');
TABLE_NAME SIZE_KB COMPRESS PCT_FREE
----------------- ---------- -------- ----------
CUST_ACOMPRESSED ENABLED 0
CUST_BCOMPRESSED 15056 ENABLED 0
CUST_SOURCE 15056 DISABLED 0
- Truncate and insert value on compressed table using direct path loading hints . As compare to basic compression there is small difference in advanced. check the status below.
SQL> TRUNCATE TABLE CUST_ACOMPRESSED;
Table truncated.
SQL> INSERT /*+ APPEND */ INTO CUST_ACOMPRESSED SELECT * FROM CUST_SOURCE;
100000 rows created.
SQL> COMMIT;
Commit complete.
SQL> exec DBMS_STATS.GATHER_TABLE_STATS(USER,'CUST_ACOMPRESSED');
PL/SQL procedure successfully completed.
SQL> col TABLE_NAME format a17
SQL> SELECT TABLE_NAME, BLOCKS*8 SIZE_KB, COMPRESSION, PCT_FREE
2 FROM USER_TABLES
3 WHERE TABLE_NAME IN ('CUST_SOURCE','CUST_BCOMPRESSED','CUST_ACOMPRESSED');
TABLE_NAME SIZE_KB COMPRESS PCT_FREE
----------------- ---------- -------- ----------
CUST_ACOMPRESSED 4360 ENABLED 0
CUST_BCOMPRESSED 4360 ENABLED 0
CUST_SOURCE 5984 DISABLED 0
- Create Basic level of compression from no compressed table
SQL> CREATE TABLE CUST_BCOMPRESSED1 ROW STORE COMPRESS BASIC as select * from CUST_SOURCE ;
Table created.
- Change existing table to compression
- Change existing table from basic to compression
- Create tablespace with advanced level of compression
- Determining Which Rows Are Compressed
- Compression Related Statistics
No comments:
Post a Comment