2016-07-05 2 views
0

Afin de compresser les données dans une seule partition, j'utilise l'approche suivante:ORACLE ÉCHANGE DE SÉPARATION et partitionner INDICES

-- I create a table with the same structure of the ORIGINAL TABLE, but 
-- on a new tablespace (NEW_TBS_DATA) 

CREATE TABLE AUXILIARY_TABLE TABLESPACE NEW_TBS_DATA AS 
SELECT * FROM ORIGINAL_TABLE WHERE 1=0 

-- I create the index on the AUXILIARY_TABLE, on a new tablespace 
-- for indexes (NEW_TBS_IDX) 

CREATE INDEX I_1 ON AUXILIARY_TABLE(START_DATE) TABLESPACE NEW_TBS_IDX 
CREATE INDEX I_2 ON AUXILIARY_TABLE(ID_FILE) TABLESPACE NEW_TBS_IDX 
CREATE INDEX I_3 ON AUXILIARY_TABLE(DESCRIPTION) TABLESPACE NEW_TBS_IDX 
CREATE INDEX I_4 ON AUXILIARY_TABLE(ZIP_CODE) TABLESPACE NEW_TBS_IDX 
CREATE INDEX I_5 ON AUXILIARY_TABLE(BH_TRAFFIC) TABLESPACE NEW_TBS_IDX 

-- I move data from partition 20160529 to auxiliary_table 

ALTER TABLE ORIGINAL_TABLE EXCHANGE PARTITION PARTITION_20160529 WITH TABLE AUXILIARY_TABLE INCLUDING INDEXES WITHOUT VALIDATION 

-- I compress data using the new tablespace NEW_TBS_DATA on auxiliary_table 

ALTER TABLE AUXILIARY_TABLE MOVE TABLESPACE NEW_TBS_DATA PARALLEL 4 COMPRESS 

-- I move the data back to the original table, with the same exchange statement: 

ALTER TABLE ORIGINAL_TABLE EXCHANGE PARTITION PARTITION_20160529 WITH TABLE AUXILIARY_TABLE including indexes without validation 

-- I drop the auxiliary_table 

DROP TABLE AUXILIARY_TABLE CASCADE CONSTRAINTS PURGE 

Pourquoi, à la fin du processus, la partition INDEXES sont sur l'ancien tablespace au lieu du nouveau tablespace (NEW_TBS_IDX)?

Répondre

1

La section "y compris les index" n'a d'effet que pour les index locaux. Voir https://docs.oracle.com/cd/E11882_01/server.112/e25523/part_admin002.htm section (Partitions) Troc de

+0

Que puis-je faire pour se rendre compte que, après la deuxième déclaration EXCHANGE PARTITION, les indices sont en NEW_TBS_IDX plutôt que sur OLD_TBS_IDX? – UltraCommit

+1

Je pense seulement le déplacer explicitement avec une commande supplémentaire. –