Posted on 2008-12-21 10:17
陜西BOY 閱讀(234)
評論(0) 編輯 收藏
在應(yīng)用系統(tǒng)中,如果某個表的數(shù)據(jù)量很大時(shí),為了保持?jǐn)?shù)據(jù)庫的性能,一般都考慮使用分區(qū)表,分區(qū)表主要有三種分區(qū)方式,分別是范圍(RANGE)、列表(LIST)、哈希(HASH)分區(qū),根據(jù)表的特性選擇分區(qū)類型,一般情況下用RANGE和LIST兩種就夠了
.................
下面就只說RANGE和LIST兩種分區(qū)表的創(chuàng)建和管理(列表LIST分區(qū)是9I之后才有,8I沒有的)
1、創(chuàng)建分區(qū)
--創(chuàng)建范圍(RANGE)分區(qū)表的語法:
create table test_tbl(emp_name varchar2(50), emp_loc varchar2(50), emp_hire_date date)
partition by range(emp_hire_date)(
partition p_hire_date1 values less than (to_date('2000-01-01','yyyy-mm-dd')) tablespace t_hire_date1,
partition p_hire_date2 values less than (to_date('2001-01-01','yyyy-mm-dd')) tablespace t_hire_date2,
partition p_hire_date3 values less than (to_date('2002-01-01','yyyy-mm-dd')) tablespace t_hire_date3
...
partition p_hire_dateN values less than (maxvalue) tablespace t_hire_dateN
)
--創(chuàng)建列表(LIST)分區(qū)表的語法:
create table test_tbl(emp_name varchar2(50), emp_loc varchar2(50), emp_hire_date date)
partition by list(emp_loc)(
partition p_loc1 values ('GZ') tablespace t_hire_date1,
partition p_loc2 values ('BJ') tablespace t_hire_date2,
partition p_loc3 values ('SH') tablespace t_hire_date3
)
2、管理分區(qū)
--增加分區(qū)(如果表分區(qū)有MAXVALUE,不能再增加分區(qū))
alter table test_tbl add partition p_hire_date4 values less than(to_date('2002-06-01','yyyy-mm-dd'))
--刪除分區(qū)
alter table test_tbl drop partition p_hire_date4
--截?cái)喾謪^(qū)(刪除分區(qū)的數(shù)據(jù))
alter table test_tbl truncate partition p_hire_date4
--拆分分區(qū)(拆分后,數(shù)據(jù)以1999-01-01為臨界分別存放在兩個分區(qū),p_hire_date1不再存在)
alter table test_tbl split partition p_hire_date1 at(to_date('1999-01-01','yyyy-mm-dd'))
into
(
partition p_hire_date11,
partition p_hire_date12
)
--合并分區(qū)(合并后,p_hire_date11和p_hire_date12兩個分區(qū)就不存在了)
alter table test_tbl merge partitions p_hire_date11,p_hire_date12 into partition p_hire_date1
--交換分區(qū)
alter table test_tbl exchange partition p_hire_date1 with table test_tbl2
當(dāng)要把數(shù)據(jù)很大的表test_tbl2的數(shù)據(jù)插入分區(qū)表test_tbl中,如果用insert into是很低性能的,最好方法是用交換分區(qū)方法。但要注意,交換分區(qū)時(shí),當(dāng)使用without validation時(shí),數(shù)據(jù)是不驗(yàn)證test_tbl2表的數(shù)據(jù)是否都能滿足分區(qū)p_hire_date1的條件