使用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>
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>
相关文章推荐
- 使用exchange 和split partition 来将一个Oracle非分区表转换为分区表
- 使用exchange 和split partition 来将一个Oracle非分区表转换为分区表
- 使用exchange做为outlook2003的服务器,现在我想添加一个新的邮件账户进去,怎么操作
- 如果域控制器使用虚拟机的考虑--一个exchange的潜在问题
- 每天一道LeetCode-----使用最少的操作将一个字符串转换成另一个字符串,只有插入,删除,替换三种操作
- js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式
- 《剑指offer》-将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数
- jQuery EasyUI使用教程之将一个HTML表格转换为数据网格
- 二者都是将 byte[] 转换成字符串,一个区别在于 Convert.ToBase64String 使用 base 64 数字编码,所以它生成的全部是 ASCII 字符。
- 使用在线重定义方式将普通表转换成分区表
- 【Java面试题】17 如何把一个逗号分隔的字符串转换为数组? 关于String类中split方法的使用,超级详细!!!
- 练习 3-2 编写一个函数escape(s, t),将字符串t 复制到字符串s 中,并在复制过程中将换行符、制表符等不可见字符分别转换为\n、\t等相应的可见的转义字符序列。要求使用swich语句。
- 编写一个函数escape(s,t),将字符串t复制到字符串s中,并在复制过程中将换行符、制表符等不可见字符分别转换为\n、\t等相应的可见的转义字符序列。要求使用switch语句。
- 使用dynamic_cast转换的一个例子
- 编写程序,将用分钟表示的时间转换成以小时 和分钟表示的时间。使用#define来创建一个代 表60的符号常量。使用while循环来允许用户重 复键入值并当键入一个小于等于0的时间是终止循环。
- 将mysql非分区表转换为分区表(转)
- 非分区表转换为分区表(非联机)
- VC中一个关于宏的使用问题,字符串之间转换,宽字符与普通字符
- 使用数组,编写一个任意进制正整数转换为十进制的转换工具。
- 使用Dbms_Redefinition转换普通表-》分区表