分区表的使用

分区表的使用(8i),之后的版本也可参考[@more@]

Oracle8i的划分

当把大的表格和索引划分成小块,可以实现以下功能:
. 减少数据库因为维护而造成的不可用时间
. 减少数据库由于失败而造成的不可用时间
. 查询性能
. 磁盘访问
. 划分的透明性

判断一个逻辑表是否可以划分的规则:
. 存在于聚集中的表不能被划分
. 如果包含long或long raw列的表不能划分
. Oracle8i支持包含LOB列表的划分
. 对于索引组织的表,当划分的关键字是该表的主关键字的子集时,该索引可被划分
. 索引组织的表存储根据主码排序的数据
使用带有PARTITION BY RANGE子句的CREATE TABLE命令创建一个划分表。对于PARTITION BY分句有三个子句,分别描述如下:
. Partition by range: 根据表中列值的范围将表中的行分成不同的划分
. Partition by hash: 根据列值将表格中的行划分成指定数目的划分。每个划分中的数值由一个哈希函数计算
. Partition by composite: 表中的行首先根据范围划分,然后在每个范围内再由哈希函数值进行划分。
并行参数:parallel(degree 2)
-- 按范围划分
[partition by range (column list)
(partition [part_name] values less than (values list) ,...)]
[enable | disable row movement] -- 允不允许划分间的行进行移动
例:
create table students
(
student_id number not null ,
student_first_name varchar2(25) null ,
student_last_name varchar2(25) null ,
student_dept_id number null ,
student_address varchar2(50) null ,
student_city varchar2(25) null ,
student_state varchar2(15) null ,
student_zip varchar2(10) null ,
student_bl_status char null
)
constraint dept_id_pk primary key(student_dept_id)
partition by range(student_dept_id)
(
partition dept_id_1 values less than (100) tablespace om1 ,
partition dept_id_2 values less than (250) tablespace om2 ,
partition dept_id_3 values less than (500) tablespace om3 ,
partition dept_id_4 values less than (750) tablespace om4 ,
partition dept_id_5 values less than (maxvalue) tablespace om5
)
disable row movement ;
-- 哈希划分
[partition by hash (column list)
(partition partition_name [tablespace tablespace_name],...)
-- or --
(partitions number_partitions [store in tablespace_name,...])
[enable | disable row movement] -- 允不允许划分间的行进行移动
例:
create table bookstroe
(
bookstore_id number primary key ,
state varchar2(20) not null ,
zip_code varchar2(11) not null)
partition by hash(state,zip_code)
(
partition bkpart_a tablespace bookstore_a ,
partition bkpart_b tablespace bookstore_b ,
partition bkpart_c tablespace bookstore_a ,
partition bkpart_d tablespace bookstore_b ,
)
enable row movement ;
-- 复合划分
复合划分需要两个步骤:1)将表以范围方式进行划分 2)紧接着采用哈希划分
[partition by range (column list)
(subpartition by hash (column list)
subpartitions number_partitions [store in tablespace_name,...]
)
(partition [part_name] values less than (values list),...)]
[enable | disable row movement]
例:
create table booksales
(
booksales_id number ,
sales_date date ,
book_sale_amount number ,
sales_rep_name varchar2(30) ,
customer_id number
)
partition by range (book_sale_amount)
(subpartition by hash (sales_date)
subpartition 8 store in bk_storage_a,bk_storage_b)
(
partition small_sale values less than(150),
partition medium_sale values less than(450),
partition large_sale values less then(maxvalue)
) ;

创建索引划分(局部索引和全局索引)
索引划分原则:
. 划分的索引不能应用于聚集表
. 划分表的位图索引必须为局部索引
. 划分和未划分的索引可以应用于划分或未划分的表
. 在未划分表上的位图索引不能被范围划分
-- 本地索引(局部索引)
create index dept_idx on students(student_dept_id)
local
(
partition dept_id_1 tablespace om1,
partition dept_id_2 tablespace om2,
partition dept_id_3 tablespace om3,
partition dept_id_4 tablespace om4,
partition dept_id_5 tablespace om5
) ;
-- 全局索引
create index dept_idx on students(student_dept_id)
global partition by range(student_dept_id)
(
partitiion dept_id_1 values less than (1000,100) tablespace om1,
partitiion dept_id_2 values less than (2000,250) tablespace om2,
partitiion dept_id_3 values less than (3000,500) tablespace om3,
partitiion dept_id_4 values less than (4000,750) tablespace om4,
partitiion dept_id_5 values less than (maxvalue,maxvalue) tablespace om5
) ;

-- 改变划分属性
可以用alter table命令修改划分的某一特定属性。
. 把一个划分从一个表空间移动到另一个表空间
. 增加一个划分
. 重命名一个划分
. 为范围划分和复合划分修改存储子句
. 分离划分
. 合并划分
下面命令是用来维护和管理划分表的:
. modify partition -- 修改划分的真实物理属性
. rename partition -- 给划分重新命名
. move partitiion -- 把划分移到另一个段(需重建索引)
. coalesce partition -- 将特定段的数据移到保留划分中然后删除该划分,该项操作只对哈希划分适用
. add partition -- 在表格中增加一个新划分
. drop partition -- 从一个表格中移走一个划分和它的数据
. merge partition ... into partition ... -- 将划分合并为一个单一的划分
. truncate partition -- 在一个划分中有效地移动所有行
. split partition ... into partition ... -- 从一个旧的划分中创建一个新划分(需重建索引)
. exchange partition -- 在一个划分和一个非预先确定的划分之间交换数据(需重建索引)
使用alter index命令
可以用来修改划分索引:
. rebuild partition -- 重建一个划分索引
. drop partition -- 从一个全局索引中移走一个划分
. split partition -- 将一个全局索引划分分为两个划分
. unusable -- 标示索引不可用
. rename partition -- 重新命名一个划分
--逻辑备份
exp usr/pwd@sid file=file.dmp tables=(partition_table_name:partition_name)
--逻辑恢复
imp usr/pwd@sid file=file.dmp tables=(partition_table_name:partition_name) ignore=y
注:在对分区表进行DDL操作时,应注意对表中global index的影响,特别是表的主键(主键默认是global index),当对分区表进行truncat or drop时,global index会变成不可用状态,应该rebuild global index或在执行DDL之前先disable global index然后再enable.

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

转载于:http://blog.itpub.net/802415/viewspace-823054/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值