[Oracle] Partition table exchange Heap table
Heap Table --(exchange)--> Partiton table
SQL> create table part_tab1(id int,owner varchar2(30),name varchar2(30),type varchar2(30),created date)
2 partition by range(id)
3 (partition p1 values less than(10000) tablespace users,
4 partition p2 values less than(50000) tablespace users,
5 partition p3 values less than(100000) tablespace users
6 );
Table created. #建立測試的表,range partition
SQL> insert into part_tab1 select object_id,owner,object_name,object_type,created from all_objects;
56331 rows created.
Elapsed: 00:00:00.91 #寫入一部分資料
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
SQL> select count(*) from part_tab1;
COUNT(*)
----------
56331
SQL> create index part_tab1_index on part_tab1(id) local; #建立local indexes
Index created.
SQL> create table temp_part_tab1 as select * from part_tab1; #建立臨時table
Table created.
Elapsed: 00:00:00.06
SQL> create index temp_part_tab1_index on temp_part_tab1(id); #建立臨時table的indexes
Index created.
Elapsed: 00:00:00.11
SQL> update temp_part_tab1 set id=id+100000;
56331 rows updated.
Elapsed: 00:00:01.55
SQL> commit;
Commit complete.
Elapsed: 00:00:00.01
SQL> alter table part_tab1 add partition p4 values less than(200000) tablespace users; #建立需要使用的partition
Table altered.
ERROR at line 1:
ORA-02149: Specified partition does not exist #如果再exchange前沒有建立相應的parition會報這個錯誤.
SQL> alter table part_tab1 exchange partition p4 with table temp_part_tab1 including indexes without validation;
Table altered.
Elapsed: 00:00:00.10
ERROR at line 1:
ORA-14099: all rows in table do not qualify for specified partition #沒有新增 without validation選項,則exchange時會檢查id是否符合parition的規則.
SQL> select count(*) from part_tab1;
COUNT(*)
----------
112662
Elapsed: 00:00:00.01
SQL> select count(*) from part_tab1 partition (p4); #資料已經全部exchange到partition p4中
COUNT(*)
----------
56331
SQL> select count(*) from temp_part_tab1; #exchange後原有的臨時表中沒有資料了.
COUNT(*)
----------
0
==========================================================================
PartitonTable --(exchange)--> Heap table
SQL> alter table part_tab1 exchange partition p1 with table temp_part_tab1 including indexes;
Table altered.
Elapsed: 00:00:00.02
SQL>
SQL> select count(*) from temp_part_tab1;
COUNT(*)
----------
4490
Elapsed: 00:00:00.01
SQL> select * from part_tab1 partition(p1);
no rows selected
Elapsed: 00:00:00.01
SQL> select segment_name,partition_name from user_segments where segment_name like '%PART%';
SEGMENT_NAME PARTITION_NAME
---------------------------------------- ------------------------------------------------------------------------------------------
TEMP_PART_TAB1
PART_TAB1 P2
PART_TAB1 P3
PART_TAB1 P4
PART_TAB1 P5
TEMP_PART_TAB1_INDEX
PART_TAB1_INDEX P2
PART_TAB1_INDEX P3
PART_TAB1_INDEX P4
PART_TAB1_INDEX P5
10 rows selected.
Elapsed: 00:00:00.07
SQL> list
1* select index_name,partition_name,status from user_ind_partitions
SQL> /
INDEX_NAME PARTITION_NAME STATUS
------------------------------ ------------------------------------------------------------------------------------------ ------------------------
PART_TAB1_INDEX P5 USABLE
PART_TAB1_INDEX P2 USABLE
PART_TAB1_INDEX P3 USABLE
PART_TAB1_INDEX P4 USABLE
PART_TAB1_INDEX P1 USABLE
Elapsed: 00:00:00.01
SQL> select index_name,table_name,status from user_indexes where table_name like '%PART%';
INDEX_NAME TABLE_NAME STATUS
------------------------------ ------------------------------------------------------------------------------------------ ------------------------
TEMP_PART_TAB1_INDEX TEMP_PART_TAB1 VALID
PART_TAB1_INDEX PART_TAB1 N/A
Elapsed: 00:00:00.27
SQL> create table part_tab1(id int,owner varchar2(30),name varchar2(30),type varchar2(30),created date)
2 partition by range(id)
3 (partition p1 values less than(10000) tablespace users,
4 partition p2 values less than(50000) tablespace users,
5 partition p3 values less than(100000) tablespace users
6 );
Table created. #建立測試的表,range partition
SQL> insert into part_tab1 select object_id,owner,object_name,object_type,created from all_objects;
56331 rows created.
Elapsed: 00:00:00.91 #寫入一部分資料
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
SQL> select count(*) from part_tab1;
COUNT(*)
----------
56331
SQL> create index part_tab1_index on part_tab1(id) local; #建立local indexes
Index created.
SQL> create table temp_part_tab1 as select * from part_tab1; #建立臨時table
Table created.
Elapsed: 00:00:00.06
SQL> create index temp_part_tab1_index on temp_part_tab1(id); #建立臨時table的indexes
Index created.
Elapsed: 00:00:00.11
SQL> update temp_part_tab1 set id=id+100000;
56331 rows updated.
Elapsed: 00:00:01.55
SQL> commit;
Commit complete.
Elapsed: 00:00:00.01
SQL> alter table part_tab1 add partition p4 values less than(200000) tablespace users; #建立需要使用的partition
Table altered.
ERROR at line 1:
ORA-02149: Specified partition does not exist #如果再exchange前沒有建立相應的parition會報這個錯誤.
SQL> alter table part_tab1 exchange partition p4 with table temp_part_tab1 including indexes without validation;
Table altered.
Elapsed: 00:00:00.10
ERROR at line 1:
ORA-14099: all rows in table do not qualify for specified partition #沒有新增 without validation選項,則exchange時會檢查id是否符合parition的規則.
SQL> select count(*) from part_tab1;
COUNT(*)
----------
112662
Elapsed: 00:00:00.01
SQL> select count(*) from part_tab1 partition (p4); #資料已經全部exchange到partition p4中
COUNT(*)
----------
56331
SQL> select count(*) from temp_part_tab1; #exchange後原有的臨時表中沒有資料了.
COUNT(*)
----------
0
==========================================================================
PartitonTable --(exchange)--> Heap table
SQL> alter table part_tab1 exchange partition p1 with table temp_part_tab1 including indexes;
Table altered.
Elapsed: 00:00:00.02
SQL>
SQL> select count(*) from temp_part_tab1;
COUNT(*)
----------
4490
Elapsed: 00:00:00.01
SQL> select * from part_tab1 partition(p1);
no rows selected
Elapsed: 00:00:00.01
SQL> select segment_name,partition_name from user_segments where segment_name like '%PART%';
SEGMENT_NAME PARTITION_NAME
---------------------------------------- ------------------------------------------------------------------------------------------
TEMP_PART_TAB1
PART_TAB1 P2
PART_TAB1 P3
PART_TAB1 P4
PART_TAB1 P5
TEMP_PART_TAB1_INDEX
PART_TAB1_INDEX P2
PART_TAB1_INDEX P3
PART_TAB1_INDEX P4
PART_TAB1_INDEX P5
10 rows selected.
Elapsed: 00:00:00.07
SQL> list
1* select index_name,partition_name,status from user_ind_partitions
SQL> /
INDEX_NAME PARTITION_NAME STATUS
------------------------------ ------------------------------------------------------------------------------------------ ------------------------
PART_TAB1_INDEX P5 USABLE
PART_TAB1_INDEX P2 USABLE
PART_TAB1_INDEX P3 USABLE
PART_TAB1_INDEX P4 USABLE
PART_TAB1_INDEX P1 USABLE
Elapsed: 00:00:00.01
SQL> select index_name,table_name,status from user_indexes where table_name like '%PART%';
INDEX_NAME TABLE_NAME STATUS
------------------------------ ------------------------------------------------------------------------------------------ ------------------------
TEMP_PART_TAB1_INDEX TEMP_PART_TAB1 VALID
PART_TAB1_INDEX PART_TAB1 N/A
Elapsed: 00:00:00.27
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2134644/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle:TABLE MONITORINGOracle
- Oracle table selectOracle
- oracle cache table(轉)Oracle
- Oracle Pipelined Table(轉)Oracle
- TiDB 原始碼閱讀系列文章(二十)Table PartitionTiDB原始碼
- [20191203]enq: ZA - add std audit table partition.txtENQ
- Oracle Pipelined Table Functions(轉)OracleFunction
- ext4 lvreduce報錯superblock or the partition table is likely to be corruptVRBloC
- create table,show tables,describe table,DROP TABLE,ALTER TABLE ,怎麼使用?
- 今天測試了一下update partition table的part key
- Oracle Table建立引數說明Oracle
- Analyze table對Oracle效能的提升Oracle
- Oracle cluster table(1)_概念介紹Oracle
- ORACLE _small_table_threshold與eventOracle
- ESP32 編譯報錯 57) boot: no bootable app partitions in the partition table編譯bootAPP
- use azure data studio to create external table for oracleOracle
- 【TABLE】Oracle表資訊收集指令碼Oracle指令碼
- 深入解析 oracle drop table內部原理Oracle
- table
- Oracle 19c Concepts(02):Tables and Table ClustersOracle
- 14_深入解析Oracle table cluster結構Oracle
- 教你解決ghost win10開機出現invalid partition table的方法Win10
- MySQL:Analyze table導致'waiting for table flush'MySqlAI
- oracle truncate table recover(oracle 如何拯救誤操作truncate的表)Oracle
- Sparse Table
- 有關oracle external table的一點測試。Oracle
- 【TABLE】Oracle監控異常的表設計Oracle
- oracle 19c 無法create table解決Oracle
- MySQL:Table_open_cache_hits/Table_open_cache_misses/Table_open_cache_overflowsMySql
- SQLAlchemy Table(表)類方式 – Table類和Column類SQL
- oracle表空間不足:ORA-01653: unable to extend tableOracle
- Oracle中獲取TABLE的DDL語句的方法Oracle
- table寬度
- Lua table(表)
- audit by user by table
- jquery-tablejQuery
- flink table apiAPI
- bootsrap table 表格載入完整 post-body.bs.tableboot
- oracle partition by 語法Oracle