partition table中truncate應用
本文描述了truncate在partition table中應用情況.
環境
oracle版本:11g Enterprise Edition Release 11.2.0.1.0
表:
create table “rootdba”.”t_p”
( “id” number,
“name” char(10)
)
partition by range (”id”)
(partition “p10″ values less than (10)
partition “p20″ values less than (20)
partition “p30″ values less than (30)
partition “p40″ values less than (40)
)
索引: create index idx_t_p on t_p(id);
1.在分割槽表上truncate整個表資料.
ROOTDBA@ora11g>select segment_name,sum(bytes)/1024/1024 from user_segments where segment_name in (’IDX_T_P’,'T_P’) group by segment_name;
SEGMENT_NAME SUM(BYTES)/1024/1024
—————————— ——————–
T_P 8
IDX_T_P 7
ROOTDBA@ora11g>select index_name,status from user_indexes where index_name=’IDX_T_P’;
INDEX_NAME STATUS
—————————— ——–
IDX_T_P VALID
ROOTDBA@ora11g>truncate table t_p ;
Table truncated.
ROOTDBA@ora11g>select segment_name,sum(bytes)/1024/1024 from user_segments where segment_name in (’IDX_T_P’,'T_P’) group by segment_name;
SEGMENT_NAME SUM(BYTES)/1024/1024
—————————— ——————–
T_P .25
IDX_T_P .0625
Elapsed: 00:00:00.01
ROOTDBA@ora11g>
ROOTDBA@ora11g>
ROOTDBA@ora11g>select index_name,status from user_indexes where index_name=’IDX_T_P’;
INDEX_NAME STATUS
—————————— ——–
IDX_T_P VALID
2.在分割槽表上truncate某個分割槽中資料.
ROOTDBA@ora11g>select segment_name,sum(bytes)/1024/1024 from user_segments where segment_name in (’IDX_T_P’,'T_P’) group by segment_name;
SEGMENT_NAME SUM(BYTES)/1024/1024
—————————— ——————–
T_P 8
IDX_T_P 9
Elapsed: 00:00:00.01
ROOTDBA@ora11g>select index_name,status from user_indexes where index_name=’IDX_T_P’;
INDEX_NAME STATUS
—————————— ——–
IDX_T_P VALID
ROOTDBA@ora11g>Alter table t_p truncate partition p10;
Table truncated.
ROOTDBA@ora11g>select segment_name,sum(bytes)/1024/1024 from user_segments where segment_name in (’IDX_T_P’,'T_P’) group by segment_name;
SEGMENT_NAME SUM(BYTES)/1024/1024
—————————— ——————–
T_P 6.0625
IDX_T_P 9
ROOTDBA@ora11g>select index_name,status ,PARTITIONED from user_indexes where index_name=’IDX_T_P’;
INDEX_NAME STATUS PAR
—————————— ——– —
IDX_T_P UNUSABLE NO
3.truncate時 reuse storage的作用
reuse storage作用是可以保留已分配的空間(普通表和分割槽表都一樣),但索引會失效.
ROOTDBA@ora11g>select segment_name,sum(bytes)/1024/1024 from user_segments where segment_name in (’IDX_T_P’,'T_P’) group by segment_name;
SEGMENT_NAME SUM(BYTES)/1024/1024
—————————— ——————–
T_P 6.0625
IDX_T_P 5
Elapsed: 00:00:00.02
ROOTDBA@ora11g>select index_name,status ,PARTITIONED from user_indexes where index_name=’IDX_T_P’;
INDEX_NAME STATUS PAR
—————————— ——– —
IDX_T_P VALID NO
ROOTDBA@ora11g> alter table t_p truncate partition p20 reuse storage ;
Table truncated.
Elapsed: 00:00:00.29
ROOTDBA@ora11g>select segment_name,sum(bytes)/1024/1024 from
user_segments where segment_name in (’IDX_T_P’,'T_P’) group by
segment_name;
SEGMENT_NAME SUM(BYTES)/1024/1024
—————————— ——————–
T_P 6.0625
IDX_T_P 5
Elapsed: 00:00:00.01
ROOTDBA@ora11g>select index_name,status ,PARTITIONED from user_indexes where index_name=’IDX_T_P’;
INDEX_NAME STATUS PAR
—————————— ——– —
IDX_T_P UNUSABLE NO
4. truncate分割槽後失效索引處理
ROOTDBA@ora11g>select id from t_p where id=1;
Elapsed: 00:00:00.00
Execution Plan
———————————————————-
Plan hash value: 4247270103
—————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————-
| 0 | SELECT STATEMENT | | 500K| 1467K| 3943 (1)| 00:00:48 |
|* 1 | INDEX RANGE SCAN| IDX_T_P | 500K| 1467K| 3943 (1)| 00:00:48 |
—————————————————————————-
Predicate Information (identified by operation id):
—————————————————
1 – access(”ID”=1)
ROOTDBA@ora11g>
ROOTDBA@ora11g>alter table t_p truncate partition p10;
Table truncated.
Elapsed: 00:00:00.31
ROOTDBA@ora11g>select id from t_p where id=1;
Elapsed: 00:00:00.01
Execution Plan
———————————————————-
Plan hash value: 551878766
———————————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
———————————————————————————————–
| 0 | SELECT STATEMENT | | 500K| 1467K| 6104 (3)| 00:01:14 | | |
| 1 | PARTITION RANGE SINGLE| | 500K| 1467K| 6104 (3)| 00:01:14 | 1 | 1 |
|* 2 | TABLE ACCESS FULL | T_P | 500K| 1467K| 6104 (3)| 00:01:14 | 1 | 1 |
———————————————————————————————–
Predicate Information (identified by operation id):
—————————————————
2 – filter(”ID”=1)
ROOTDBA@ora11g>alter index idx_t_p rebuild;
Index altered.
Elapsed: 00:01:25.59
ROOTDBA@ora11g>
ROOTDBA@ora11g>select id from t_p where id=1;
Elapsed: 00:00:00.00
Execution Plan
———————————————————-
Plan hash value: 4247270103
—————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————-
| 0 | SELECT STATEMENT | | 500K| 1467K| 1271 (1)| 00:00:16 |
|* 1 | INDEX RANGE SCAN| IDX_T_P | 500K| 1467K| 1271 (1)| 00:00:16 |
—————————————————————————-
Predicate Information (identified by operation id):
—————————————————
1 – access(”ID”=1)
ROOTDBA@ora11g>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7364032/viewspace-615292/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- partition table and partition indexIndex
- 拆分Table 為Partition Table
- partition table test
- partition table(1)
- partition table(2)
- When to Partition a Table
- [Oracle] Partition table exchange Heap tableOracle
- 在儲存過程中寫truncate table儲存過程
- drop table和truncate table的區別
- Oracle drop,truncate partition 索引失效 實驗Oracle索引
- Oracle 普通table 轉換為partition tableOracle
- create a partition table using a exsit table
- 分割槽表PARTITION table
- 【實驗】【PARTITION】RANGE分割槽表截斷表分割槽(Truncate Partition)
- partition table update partition-key result in changing tablespace
- oracle truncate table recover(oracle 如何拯救誤操作truncate的表)Oracle
- db2 partition table testDB2
- Interval Partition table 11G
- Oracle分割槽表(Partition Table)Oracle
- How to partition a non-partitioned table
- 分割槽表PARTITION table(轉)
- 禁止客戶端 誤 truncate table客戶端
- 定期truncate 歷史間隔分割槽INTERVAL PARTITION
- truncate table執行很慢的原因分析
- delete table 和 truncate table - 型別安全的心 - 部落格園delete型別
- mysql partition table use to_days bugMySql
- 關於partition table import的問題Import
- doesn't contain a valid partition tableAI
- add hash partition , default tablespace for patitioned table
- MySQL資料災難挽救之truncate tableMySql
- oracle logminer恢復truncate table的資料Oracle
- Oracle中truncate table後的資料恢復(Oracle資料恢復工具-ODU)Oracle資料恢復
- Mysql truncate table時解決外來鍵關聯MySql
- Truncate table 詳解及與delete,drop 的區別delete
- truncate table 誤刪除資料後的恢復
- Truncate table詳解及與delete,drop的區別delete
- 恢復被執行truncate table的表資料
- 【DB】Direct Path EXP Corrupts The Dump If An Empty Table Partition Exists