Basic Compression e Analyzing Tables - DIRECT-PATH Insert - append
Con l'opzione "basic compression" il server oracle comprime i dati durante un bulk load come direct load o CREATE TABLE AS SELECT.
E' raccomandato per bulk loading in data warehouses.
Per verificare l'integrità della struttura di una tabella, index, cluster, o materialized view usare
Puoi valideare un oggettto e le sue dipendenze (esempio indici) usando l'opzione CASCADE.
Il comando APPEND dice all'optimizer oracle di eseguire una direct-path insert che migliora le performance di una semplice operazione INSERT .. SELECT prechè i dati sono "appesi" alla fine della tabella dopo l'Hwm (High water mark) piuttosto che tentare di usare spazio libero all'interno della tabella.
I dati sono scritti direttamente sui data files, bypassando il buffer cache.
E' raccomandato per bulk loading in data warehouses.
Vediamo un esempio
Caso 1 Creiamo una tabella senza compressione dei dati.
SQL> create table test01
as
select * from dba_objects where rownum <= 10000;
SQL> ANALYZE TABLE test01 COMPUTE statistics;
Oracle aggiorna il Dictionary table con le informazioni sul numero di righe della tabella, lo spazio occupato e altre informazioni. Se la struttura è valida, non viene restituito alcun messaggio di errore.
Ad esempio, durante la convalida dell'indice, è possibile confermare che ogni voce nell'indice punta alla riga corretta della tabella associata.
Se l'indice è danneggiato, puoi eseguire drop e create.
Stessa cosa per una tabella, un indice o un cluster.
SQL > ANALYZE TABLE test01 VALIDATE STRUCTURE CASCADE;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST01';
Non restiruisce righe.
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
---------- ---------- --------------------- --------------------- ----------------------
186 10 DISABLED
La tabella occupa 186 blocchi e la percentuale di spazio libero in un blocco è il 10%. Non è abilitata la compressione.
Caso 2 Creiamo una tabella compressa con opzione basic.
SQL> create table test02 compress basic
as
select * from dba_objects where rownum <= 10000;
SQL > ANALYZE TABLE TEST02 compute statistics
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST02';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
---------- ---------- -------- -------------------------------------------------------
44 0 ENABLED BASIC
La tabella occupa 44 blocchi e la percentuale di spazio libero in un blocco è il 0%. E' abilitata la compressione di tipo base.
Caso 3 Eseguiamo insert normali nella tabella vuota creata con compress basic.
SQL> create table test03 compress basic
as
select * from dba_objects where 1=2
Crea solo la tabella perchè la where conditition è sempre falsa quindi la select non restiruisce record.
SQL> insert into test03 select * from dba_objects where rownum <= 10000;
SQL> commit;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST03';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
---------- ---------- -------- ---------------------------------------------
0 0 ENABLED BASIC
SQL> ANALYZE TABLE TEST03 compute statistics
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST03';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
---------- ---------- -------- -----------------------------------------------
244 0 ENABLED BASIC
La tabella occupa 244 blocchi e la percentuale di spazio libero in un blocco è il 0%.
E' abilitata la compressione di tipo base.
Non ho benifici anche se la tabella è compressa perchè ho eseguito delle insert normali.
Caso 4 Eseguiamo Direct-path insert nella tabella vuota creata con compress basic.
SQL> create table TEST04 compress basic
as
select * from dba_objects where rownum = 0;
SQL> insert /*+ append */ into TEST04 select * from dba_objects where rownum <= 10000
I dati sono scritti direttamente sui data files, bypassando il buffer cache.
SQL> ANALYZE TABLE TEST04 COMPUTE statistics;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST04';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
---------- ---------- -------- ---------------------------------------------------
44 0 ENABLED BASIC
Abbiamo solo 44 blocchi oracle occupati rispetto al caso 3
Caso 5 Creiamo una tabella senza compressione e poi effettuaimo la compressione
SQL> create table test05
as
select * from dba_objects where rownum <= 10000;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST505';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
-------------------------- ---------- -------- ------------------------------
186 10 DISABLED
SQL> alter table test05 compress basic;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST505';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
-------------------------- ---------- -------- ------------------------------
186 10 ENABLED BASIC
Non abbiamo alcun cambiamento con il comando precedente perchè occorre esegiure anche il comando seguente che comprimere i dati vecchi:
SQL > alter table test05 move;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST505';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
-------------------------- ---------- -------- ------------------------------
186 10 ENABLED BASIC
SQL> ANALYZE TABLE TEST05 COMPUTE statistics;
SQL> select blocks, pct_free , compression, compress_for
from user_tables
where table_name = 'TEST505';
BLOCKS PCT_FREE COMPRESS COMPRESS_FOR
---------- ---------------------------------------------------------------
44 0 ENABLED BASIC