您的位置:首页 > 其它

使用exchange 和split partition 来将一个非分区表转换为分区表

2008-04-18 22:48 477 查看
在线重定义表可以将一个非分区表转换成一个分区表。使用exchange 和split partition 也可以将一个非分区表转换为分区表。后者相比较前者,因为不受要转换的数据量影响,因此也更方便、快捷一些。

exchange partition 操作能将一个分区表的一个分区和另一张表的数据互换,这里的互换是segment 头部信息的修改,数据block 并不做改动,因此,和数据量无关,速度会非常快;完成后,再可以按照需要将分区具体split 成其他多个分区。

总的有三个步骤:
1.建立一个空的,只有一个分区的同构分区表
2.exchange partition with table 来互换数据
3.split 分区表的分区为合适的个数

举例如下:

-- 建立空的分区表
create table test_part
partition by range ( created )
( partition all_data values less than (MAXVALUE))
as select owner,object_name,object_type,created from test2 where 1=2;

-- 执行exchange partition 操作
SQL> alter table test_part exchange partition all_data with table test2 ;

Table altered

SQL> select * from test_part where rownum<4; --分区表中有数据了,原表没有了数据

OWNER OBJECT_NAME OBJECT_TYPE CREATED
------------------------------ -------------------------------------------------------------------------------- ------------------ -----------
SYS I_CDEF1 INDEX 2000-5-12 1
SYS IND$ TABLE 2000-5-12 1
SYS FILE$ TABLE 2000-5-12 1

SQL> select * from test2 where rownum<4;

OWNER OBJECT_NAME OBJECT_TYPE CREATED
------------------------------ -------------------------------------------------------------------------------- ------------------ -----------

SQL>

-- split range 分区
SQL> alter table test_part split partition all_data AT (to_date('20070101','YYYYMMDD')) into ( partition before_2007 , partition after_2007 ) ;

Table altered

SQL>

SQL> select table_name,partition_name,high_value,composite,subpartition_count from user_tab_partitions;

TABLE_NAME PARTITION_NAME HIGH_VALUE COMPOSITE SUBPARTITION_COUNT
------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------- ------------------
TEST_PART AFTER_2007 MAXVALUE NO 0
TEST_PART BEFORE_2007 TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA NO 0

SQL>

--对 exchange partition with table 操作做了10046 trace,分析trace 可以看出,这个ddl 操作实际上递归出了若干个dml,正是这些dml ,直接修改了某些头部信息,完成了所谓的数据互换工作

oratest@cwdata:/u01/oracle/testdb/9.2.0/admin/test_cwdata/udump/test> grep where *.trc | grep -v select | grep -v "WAIT #"
delete from superobj$ where subobj# = :1
update tab$ set ts#=:2,file#=:3,block#=:4,bobj#=decode(:5,0,null,:5),tab#=decode(:6,0,null,:6),intcols=:7,kernelcols=:8,clucols=decode(:9,0,null,:9),audit$=:10,flags=:11,pctfree$=:12,pctused$=:13,initrans=:14,maxtrans=:15,rowcnt=:16,blkcnt=:17,empcnt=:18,avgspc=:19,chncnt=:20,avgrln=:21,analyzetime=:22,samplesize=:23,cols=:24,property=:25,degree=decode(:26,1,null,:26),instances=decode(:27,1,null,:27),dataobj#=:28,avgspc_flb=:29,flbcnt=:30,trigflag=:31,spare1=:32,spare2=decode(:33,0,null,:33),spare4=:34,spare6=:35 where obj#=:1
delete from superobj$ where subobj# = :1
update tab$ set ts#=:2,file#=:3,block#=:4,bobj#=decode(:5,0,null,:5),tab#=decode(:6,0,null,:6),intcols=:7,kernelcols=:8,clucols=decode(:9,0,null,:9),audit$=:10,flags=:11,pctfree$=:12,pctused$=:13,initrans=:14,maxtrans=:15,rowcnt=:16,blkcnt=:17,empcnt=:18,avgspc=:19,chncnt=:20,avgrln=:21,analyzetime=:22,samplesize=:23,cols=:24,property=:25,degree=decode(:26,1,null,:26),instances=decode(:27,1,null,:27),dataobj#=:28,avgspc_flb=:29,flbcnt=:30,trigflag=:31,spare1=:32,spare2=decode(:33,0,null,:33),spare4=:34,spare6=:35 where obj#=:1
update tabpart$ set dataobj# = :1, part# = :2, ts# = :3, file# = :4, block# = :5, pctfree$ = :6, pctused$ = :7, initrans = :8, maxtrans = :9, flags = :10, analyzetime = :11, samplesize = :12, rowcnt = :13, blkcnt = :14, empcnt = :15, avgspc = :16, chncnt = :17, avgrln = :18 where obj# = :19 and bo# = :20
update obj$ set obj#=:6,type#=:7,ctime=:8,mtime=:9,stime=:10,status=:11,dataobj#=:13,flags=:14,oid$=:15,spare1=:16, spare2=:17 where owner#=:1 and name=:2 and namespace=:3 and(remoteowner=:4 or remoteowner is null and :4 is null)and(linkname=:5 or linkname is null and :5 is null)and(subname=:12 or subname is null and :12 is null)
update obj$ set obj#=:6,type#=:7,ctime=:8,mtime=:9,stime=:10,status=:11,dataobj#=:13,flags=:14,oid$=:15,spare1=:16, spare2=:17 where owner#=:1 and name=:2 and namespace=:3 and(remoteowner=:4 or remoteowner is null and :4 is null)and(linkname=:5 or linkname is null and :5 is null)and(subname=:12 or subname is null and :12 is null)
update obj$ set obj#=:6,type#=:7,ctime=:8,mtime=:9,stime=:10,status=:11,dataobj#=:13,flags=:14,oid$=:15,spare1=:16, spare2=:17 where owner#=:1 and name=:2 and namespace=:3 and(remoteowner=:4 or remoteowner is null and :4 is null)and(linkname=:5 or linkname is null and :5 is null)and(subname=:12 or subname is null and :12 is null)
oratest@cwdata:/u01/oracle/testdb/9.2.0/admin/test_cwdata/udump/test>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐