分区范围oracle partition table related operations

在本篇文章中,我们主要介绍分区范围的内容,自我感觉有个不错的建议和大家分享下

    Oracle 分区表的操作包括:add, split, drop, move, truncate, rename,merge(针对range分区表), coalesce(针对hash分区表)),Oracle 10g供给了以下几种分区类型:

           (1)范围分区(range);

           (2)哈希分区(hash);

           (3)列表分区(list);

           (4)范围-哈希复合分区(range-hash);

           (5)范围-列表复合分区(range-list)。

     

    Range分区:

     Range分区是应用范围比较广的表分区方法,它是以列的值的范围来做为分区的划分条件,将记载存放到列值地点的range分区中。如按照时间划分,2010年1月的数据放到a分区,2月的数据放到b分区,在创立的时候,需要指定基于的列,以及分区的范围值。在按时间分区时,如果某些记载暂没法预测范围,可以创立maxvalue分区,全部不在指定范围内的记载都会被存储到maxvalue地点分区中。

    1,range 分区

    create table examplepart (
idx number, txt varchar2(20)
)
partition by range(idx)
(
 partition p1 values less than (0),
 partition p2 values less than (10000) tablespace users,
 partition p3 values less than (maxvalue)
);

    
create index examplepart_ind on examplepart (idx) nologging parallel;

    
alter table examplepart parallel 5;

     

    alter table examplepart split partition p2 at (5000) into
(partition p2_1,partition p2_2) parallel 2;

     

    alter table examplepart merge partitions p2_1,p2_2 into partition p2 tablespace users
compress update indexes;

    
alter table examplepart drop partition p3;

    新增长的PARTITION必须是值比之前的全部的值都大,所以需要先drop partition p3
alter table examplepart add partition p4 values less than (100000);

    alter table examplepart rename partition p4 to p3;

    alter table examplepart add partition p4 values less than (maxvalue);

    alter table examplepart move partition p3 tablespace EXAMPLE compress;

    alter table examplepart truncate partition p4;

    SQL> alter table examplepart coalesce partition;
alter table examplepart coalesce partition
            *
ERROR at line 1:
ORA-14259: table is not partitioned by Hash method

     

    Hash分区:

     对于那些没法有效划分范围的表,可以使用hash分区,这样对于提高性能还是会有必定的帮助。hash分区会将表中的数据平均分配到你指定的几个分区中,列地点分区是根据分区列的hash值自动分配,因此你并不能控制也不知道哪条记载会被放到哪个分区中,hash分区也可以支撑多个依赖列。

    2,HASH分区
create table hashtest(id int,name varchar2(20))
partition by hash(id)
partitions 8 store in (batch)
nologging
parallel;

     

    SQL> select table_NAME,PARTITION_NAME from user_tab_partitions where table_name='HASHTEST';

    每日一道理
整个世界,因为有了阳光,城市有了生机;细小心灵,因为有了阳光,内心有了舒畅。明媚的金黄色,树丛间小影成像在叶片上泛有的点点破碎似的金灿,海面上直射反映留有的随波浪层层翻滚的碎片,为这大自然创造了美景,惹人醉的温馨之感,浓浓暖意中夹杂着的明朗与柔情,让雨过天晴后久违阳光的心灵重新得到了滋润!

    TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
HASHTEST                       SYS_P49
HASHTEST                       SYS_P50
HASHTEST                       SYS_P51
HASHTEST                       SYS_P52
HASHTEST                       SYS_P53
HASHTEST                       SYS_P54
HASHTEST                       SYS_P55
HASHTEST                       SYS_P56

    8 rows selected.

     

    合并分区:

    SQL> alter table hashtest coalesce partition;

    Table altered.

    SQL> select table_NAME,PARTITION_NAME from user_tab_partitions where table_name='HASHTEST';

    TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
HASHTEST                       SYS_P49
HASHTEST                       SYS_P50
HASHTEST                       SYS_P51
HASHTEST                       SYS_P52
HASHTEST                       SYS_P53
HASHTEST                       SYS_P54
HASHTEST                       SYS_P55

    7 rows selected.

    从上面可以看出,做了一下合并(coalesce)分区,分区数目就少了一个是,7个分区了。 

     

    SQL> alter table hashtest drop  partition SYS_P49;
alter table hashtest drop  partition SYS_P49
                                     *
ERROR at line 1:
ORA-14255: table is not partitioned by Range, Composite Range or List method

    从上面可以看出,HASH分区表的分区时不可以被DROP的。但是是可以进行MOVE的。

    move hash patition:
SQL> alter table hashtest move partition SYS_P49 tablespace users;

    Table altered.

    SQL> select table_NAME,PARTITION_NAME from user_tab_partitions where table_name='HASHTEST';

    TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
HASHTEST                       SYS_P49
HASHTEST                       SYS_P50
HASHTEST                       SYS_P51
HASHTEST                       SYS_P52
HASHTEST                       SYS_P53
HASHTEST                       SYS_P54
HASHTEST                       SYS_P55

    7 rows selected.

     

    ADD hash partition

    SQL> alter table hashtest add partition SYS_P56;

    Table altered.

     

    不能split partition

     SQL> alter table hashtest split partition SYS_P49 at (1000);
alter table hashtest split partition SYS_P49 at (1000)
            *
ERROR at line 1:
ORA-14255: table is not partitioned by Range, Composite Range or List method

    Truncate hash分区

    SQL> alter table hashtest truncate partition SYS_P49;

    Table truncated.

    Rename hash partition: 

    SQL> alter table hashtest rename partition SYS_P56 to SYS_P48;

    Table altered.

 

    To be continued.......

    

     

     

     

     

     

    
 

文章结束给大家分享下程序员的一些笑话语录: 很多所谓的牛人也不过如此,离开了你,微软还是微软,Google还是Google,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。

--------------------------------- 原创文章 By
范围和列
---------------------------------

你可能感兴趣的:(partition)