partition table(2)

tolilong發表於2012-07-04

5).interval分割槽11g新增)

Interval分割槽是range分割槽的一種加強版本。可以實現equi-sized範圍分割槽的自動化。隨著資料的增加會分配更多的分割槽,並自動建立新的分割槽和本地索引。

create table part6

(id int,

name varchar2(20),

dt date

)

partition by range(dt)

interval (numtoyminterval(1,'month'))

(

partition p1 values less than(to_date('2012/01/01','yyyy/mm/dd'))

)

6).外來鍵分割槽(11g新增)

SQL> create table part1

2 (id int,name varchar2(10))

3 partition by range(id)

4 (partition p1 values less than (100),

5 partition p2 values less than (200),

6 partition p3 values less than (maxvalue)

7 );

SQL> alter table part1 add primary key(id);

Table altered.

SQL> create table part7

2 (id int not null, à這個必須要,否則出現ora-14652

3 name varchar2(20),

4 constraint part7_fk foreign key(id) references part1(id)

5 )

6 partition by reference (part7_fk)

7 /

Table created.

7).虛擬列分割槽

11g以前的版本,只有分割槽鍵存在於表中才可以對該表實施分割槽操作。而11g則不需要。

create table part3

(id int,

name varchar2(20),

id1 int generated always as (to_number(substr(to_char(id),1,1)))

)

partition by list(id1)

( partition p1 values (3),

partition p2 values (5),

partition p3 values (default)

)

8).表分割槽的管理

Range partition:

增加partition:

Range

Partition

Hash

Partition

Add

Partition

組合

Partition

增加分割槽

Add partition

Add partition

Add partition

Add partition

合併分割槽

Coalesce

Partition

Modify partition

Coalesce

Subpartition…

刪除分割槽

Drop partition

Drop

Partition

Drop partition

交換分割槽

Exchange

Partition

Exchange

Partition

Exchange

Partition

Exchange

Partition

Exchange

Subpartition

融合分割槽

Merge partitions

Merge

Partitions

Merge

partitions

修改分割槽增加值

Modify partition

Add values

修改分割槽刪除值

Modify

Partition

Drop values

移動分割槽

Move partition

Move partition

Move partition

Move partition

更名分割槽

Rename partition

Rename partition

Rename partition

Rename partition

分割分割槽

Split partition

Splite partition

Split partition

捨棄分割槽

Truncate partition

Truncate partition

Truncate partition

Truncate partition

Truncate

subpartition

增加分割槽

SQL> alter table part1 add partition p3 values less than (to_date('2014/01/01','yyyy/mm/dd')) [tablespace xxx];

已更改表格.

SQL> alter table part1 add partition p4 values less than (maxvalue) [tablespace xxx];

合併分割槽(hash partition)

SQL> alter table part_hash coalesce partition;

SQL> alter table part5 modify partition p1 coalesce subpartition;

刪除分割槽

SQL> alter table part1 drop partition p3;

如果有全域性index,刪除partition之後,index會標識為unusable,需要重建indexAlter index xxx rebuild

如果有約束:alter table xxx disable constraints cons_xxx

Alter table xxxx drop partition px;

Alter table xxx enable constraints cons_xxx

融合分割槽

create index part1_index on part1(id,name)

local

(partition p1,

partition p2,

partition p3,

partition p4

)

SQL> alter table part1 merge partitions p3,p4 into partition p5;

索引變成無效

SQL> select status from user_indexes where index_name='PART1_INDEX'

2 ;

STATUS

----------------

N/A

SQL> alter table part1 modify partition p5 rebuild unusable local indexes;

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-1058716/,如需轉載,請註明出處,否則將追究法律責任。

相關文章