ITPub博客

首页 > 数据库 > Oracle > partition table(1)

partition table(1)

原创 Oracle 作者:tolilong 时间:2012-07-04 14:21:21 0 删除 编辑

使用分区有很多优点:

l 增加可用性,一个分区有问题,不影响其他的分区

l 减少维护工作量

l 均衡I/O,减少争用。

l 提高查询速度

l 分区对user是透明

1).range partition

create table part1(

id number primary key,

name varchar2(10),

dt date

)

partition by range(dt)

(

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

partition p2 values less than (to_date('2013/01/01','yyyy/mm/dd')) tablespace test,

partition p3 values less than (maxvalue) tablespace users

)

SQL> insert into part1 values(4,'a',sysdate);

已建立 1 個資料列.

SQL> insert into part1 values(5,'b',sysdate-200);

已建立 1 個資料列.

SQL> insert into part1 values(6,'c',sysdate+200);

已建立 1 個資料列.

SQL> commit;

確認完成.

SQL> select * from part1 partition(p2);

ID NAME DT

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

4 a 01-7月 -12

1 a 01-7月 -12

Range partition可以是两个字段或多个字段

create table part2(

id number primary key,

dt date,

des varchar2(20)

)

partition by range(id,dt)

(

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

partition p2 values less than (10,to_date('2013/01/01','yyyy/mm/dd')) tablespace test,

partition p3 values less than (maxvalue,maxvalue) tablespace users

)

2).hash 分区 à散列分区

主要用去取值不确定的情况下采用的方法

create table part_hash(

id number primary key,

name varchar2(20),

dt date)

partition by hash(id)

(

partition p1 tablespace users,

partition p2 tablespace test

)

SQL> select * from part_hash partition (p1);

ID NAME DT

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

2 b 30-6月 -12

SQL> select * from part_hash partition (p2);

ID NAME DT

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

1 a 01-7月 -12

3 c 28-6月 -12

或者采用如下方法:

create table part_hash1(

id number primary key,

name varchar2(20),

dt date)

storage(initial 1024k) --表空间的初始分配1024k

partition by hash(id)

partitions 3

store in (users,test,system);

3).list partition à列表分区

主要是用于某个列的值是可以枚举的

create table part4

(id number(1),

name varchar2(10)

)

partition by list(id)

(partition p1 values (1) tablespace users,

partition p2 values (2) tablespace test,

partition p3 values (default) tablespace users

)

insert into part4 values(1,'A')

insert into part4 values(2,'B')

insert into part4 values(3,'B')

select * from part4 partition (p3)

Normal 0 0 2 false false false MicrosoftInternetExplorer4

4).组合分区

a.Range-hash partition

b.range-list partition

c.range-range partition

d.list-range partition

e.list-list partition

f.list-hash partition

eg:

create table part5

(id int,

name varchar2(10)

)

partition by range(id)

subpartition by hash(name)

subpartitions 2 store in (users,test)

(partition p1 values less than (10) tablespace users,

partition p2 values less than (20) tablespace test,

partition p3 values less than (maxvalue) tablespace users

)

先进行range partition,然后子分区按照hash进行。

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24237320/viewspace-1058715/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: partition table(2)
请登录后发表评论 登录
全部评论

注册时间:2010-07-13

  • 博文量
    406
  • 访问量
    1208666