關於 Oracle 分割槽索引的正確 DROP 和 TRUNCATE 方法
--檢視分割槽索引的大小
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 2) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
2 3 4 5 6 'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.75
IDX_ACCTFLOW_TYPECODEDATE 24.53
IDX_ACCTFLOW_MAPPING 33.19
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.44
PK_CUSTOMACCOUNTFLOW 33.19
SQL> select index_name, index_type, status
from user_indexes s
where index_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW'); 2 3 4 5 6 7
INDEX_NAME INDEX_TYPE STATUS
------------------------------ --------------------------- --------
IDX_ACCTFLOW_CUSTCODE FUNCTION-BASED NORMAL N/A
IDX_ACCTFLOW_CUSTOMTRANSTYPE NORMAL VALID
IDX_ACCTFLOW_MAPPING NORMAL VALID
IDX_ACCTFLOW_TYPECODEDATE NORMAL VALID
PK_CUSTOMACCOUNTFLOW NORMAL VALID
--備份出要進行操作的分割槽
create table CUSTOMACCOUNTFLOW_bk as select * from ELMP_TRANS_CUSTOMACCOUNTFLOW partition(SYS_P623);
insert into CUSTOMACCOUNTFLOW_bk select * from ELMP_TRANS_CUSTOMACCOUNTFLOW partition(SYS_P603);
SQL> select count(*) from CUSTOMACCOUNTFLOW_bk;
COUNT(*)
----------
291862
Elapsed: 00:00:00.07
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 4) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
2 3 4 5 6 'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.7566
IDX_ACCTFLOW_TYPECODEDATE 24.5361
IDX_ACCTFLOW_MAPPING 33.1943
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.4472
PK_CUSTOMACCOUNTFLOW 33.1923
--TRUNCATE 掉一個分割槽
SQL> set timing on
SQL> alter table ELMP_TRANS_CUSTOMACCOUNTFLOW truncate partition SYS_P623 update indexes;
Table truncated.
Elapsed: 00:00:04.60
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 4) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
2 3 4 5 6 'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.7547
IDX_ACCTFLOW_TYPECODEDATE 24.5361
IDX_ACCTFLOW_MAPPING 33.1943
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.4472
PK_CUSTOMACCOUNTFLOW 33.1923
--DROP 掉一個分割槽
Elapsed: 00:00:00.02
SQL> alter table ELMP_TRANS_CUSTOMACCOUNTFLOW drop partition SYS_P603 update indexes;
Table altered.
Elapsed: 00:00:20.92
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 4) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 2 3 4 5 6 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.7381
IDX_ACCTFLOW_TYPECODEDATE 24.5361
IDX_ACCTFLOW_MAPPING 33.1943
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.4472
PK_CUSTOMACCOUNTFLOW 33.1923
Elapsed: 00:00:00.03
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 2) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
2 3 4 5 6 'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.75
IDX_ACCTFLOW_TYPECODEDATE 24.53
IDX_ACCTFLOW_MAPPING 33.19
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.44
PK_CUSTOMACCOUNTFLOW 33.19
SQL> select index_name, index_type, status
from user_indexes s
where index_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW'); 2 3 4 5 6 7
INDEX_NAME INDEX_TYPE STATUS
------------------------------ --------------------------- --------
IDX_ACCTFLOW_CUSTCODE FUNCTION-BASED NORMAL N/A
IDX_ACCTFLOW_CUSTOMTRANSTYPE NORMAL VALID
IDX_ACCTFLOW_MAPPING NORMAL VALID
IDX_ACCTFLOW_TYPECODEDATE NORMAL VALID
PK_CUSTOMACCOUNTFLOW NORMAL VALID
--備份出要進行操作的分割槽
create table CUSTOMACCOUNTFLOW_bk as select * from ELMP_TRANS_CUSTOMACCOUNTFLOW partition(SYS_P623);
insert into CUSTOMACCOUNTFLOW_bk select * from ELMP_TRANS_CUSTOMACCOUNTFLOW partition(SYS_P603);
SQL> select count(*) from CUSTOMACCOUNTFLOW_bk;
COUNT(*)
----------
291862
Elapsed: 00:00:00.07
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
2 3 4 5 6 'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.7566
IDX_ACCTFLOW_TYPECODEDATE 24.5361
IDX_ACCTFLOW_MAPPING 33.1943
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.4472
PK_CUSTOMACCOUNTFLOW 33.1923
--TRUNCATE 掉一個分割槽
SQL> set timing on
SQL> alter table ELMP_TRANS_CUSTOMACCOUNTFLOW truncate partition SYS_P623 update indexes;
Table truncated.
Elapsed: 00:00:04.60
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 4) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
2 3 4 5 6 'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.7547
IDX_ACCTFLOW_TYPECODEDATE 24.5361
IDX_ACCTFLOW_MAPPING 33.1943
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.4472
PK_CUSTOMACCOUNTFLOW 33.1923
--DROP 掉一個分割槽
Elapsed: 00:00:00.02
SQL> alter table ELMP_TRANS_CUSTOMACCOUNTFLOW drop partition SYS_P603 update indexes;
Table altered.
Elapsed: 00:00:20.92
SQL> select segment_name, trunc(sum(bytes) / 1024 / 1024 / 1024, 4) GB
from user_segments
where segment_name in ('IDX_ACCTFLOW_CUSTOMTRANSTYPE',
'IDX_ACCTFLOW_CUSTCODE',
'IDX_ACCTFLOW_MAPPING',
'IDX_ACCTFLOW_TYPECODEDATE',
'PK_CUSTOMACCOUNTFLOW')
group by segment_name; 2 3 4 5 6 7 8
SEGMENT_NAME GB
--------------------------------------------------------------------------------- ----------
IDX_ACCTFLOW_CUSTCODE 31.7381
IDX_ACCTFLOW_TYPECODEDATE 24.5361
IDX_ACCTFLOW_MAPPING 33.1943
IDX_ACCTFLOW_CUSTOMTRANSTYPE 33.4472
PK_CUSTOMACCOUNTFLOW 33.1923
Elapsed: 00:00:00.03
加上 UPDATE INDEXES 的優點是:
在對分割槽表進行操作的時候,索引仍是線上和可用的,這個操作不會影響到應用程式。
在對分割槽表進行操作後,全域性分割槽索引不必進行重建。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-1993020/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 關於 Oracle 分割槽索引的失效和重建Oracle索引
- 關於 Oracle 分割槽索引的建立和維護Oracle索引
- 關於分割槽表和分割槽索引(About Partitioned Tables and Indexes)索引Index
- 關於ORACLE MYSQL在非字首分割槽索引上分割槽剪裁的比較OracleMySql索引
- Oracle drop,truncate partition 索引失效 實驗Oracle索引
- rebuild分割槽表分割槽索引的方法Rebuild索引
- 關於delete,drop,truncate的問題delete
- Oracle索引分割槽Oracle索引
- Oracle分割槽表及分割槽索引Oracle索引
- HWM和delete,drop,truncate的關係delete
- Oracle12c中效能最佳化&功能增強新特性之全域性索引DROP和TRUNCATE 分割槽的非同步維護Oracle索引非同步
- 簡單ORACLE分割槽表、分割槽索引Oracle索引
- 關於oracle的表空間,分割槽表,以及索引的總結Oracle索引
- oracle分割槽索引(二)Oracle索引
- oracle分割槽索引(一)Oracle索引
- oracle關於分割槽相關操作Oracle
- PLSQL根據分割槽表的分割槽名批次truncate分割槽SQL
- oracle索引詳解 分割槽索引Oracle索引
- 【學習筆記】分割槽表和分割槽索引——管理索引分割槽(四)筆記索引
- 全域性分割槽索引和區域性分割槽索引索引
- 12C新特性之表分割槽非同步全域性索引非同步維護(add、truncate、drop、spilt、merge多分割槽)非同步索引
- Oracle的分割槽索引技術Oracle索引
- 關於oracle的表空間,分割槽表,以及索引的總結(轉)Oracle索引
- 關於oracle的表空間,分割槽表,以及索引的總結 -- 轉Oracle索引
- [轉]Oracle分割槽索引--本地索引和全域性索引比較Oracle索引
- Oracle分割槽索引--本地索引和全域性索引比較(轉)Oracle索引
- 2 Day DBA-管理方案物件-關於方案物件管理許可權-管理索引-非分割槽和分割槽索引物件索引
- 分割槽表、分割槽索引和全域性索引部分總結索引
- oracle 建立所有分割槽索引Oracle索引
- Oracle分割槽之五:建立分割槽索引總結Oracle索引
- 深入學習Oracle分割槽表及分割槽索引Oracle索引
- 全面認識oracle分割槽表及分割槽索引Oracle索引
- oracle分割槽partition及分割槽索引partition index(一)Oracle索引Index
- 全面學習分割槽表及分割槽索引(16)--增加和刪除索引分割槽索引
- oracle本地分割槽索引跨分割槽對成本的影響Oracle索引
- Oracle帶區域性分割槽索引的分割槽表刪除舊分割槽新增新分割槽Oracle索引
- oracle分割槽及分割槽索引partition_partition index_維護(五)_快捷方法Oracle索引Index
- oracle恢復表delete/truncate/drop的方法總結Oracledelete