机器配置:IBM P690 6U12G
数据库版本: Oracle 9.2.0.6
需求: 根据主外键关系迁移tb1446表内数据至tb1446_copy
表tb1446内有20个Hash分区,根据分区结合bulk collect技术,一次提交25000条记录(需要测试后得出一次提交的记录数),使得整个单表迁移过程耗时最短.
[@more@]SQL> select count(*) from ecifupdate.tb1446;
COUNT(*)
----------
7087611
SQL> select count(*) from ecifupdate.tb1560;
COUNT(*)
----------
74735643
编写bulk collect方式的存储过程.
migration_tb1446_part_00
migration_tb1446_part_01
migration_tb1446_part_02
migration_tb1446_part_03
.
.
.
migration_tb1446_part_19
给个sample参考(待完善)
create or replace procedure migration_tb1446_part_00
is
type tb_bulk_type is table of tb1446_copy%rowtype;
ref_bulk tb_bulk_type;
Cursor c_bulk is
select a.*
from ecifupdate.tb1446 partition(part_00) a,
ecifupdate.tb1560 b
where a.arrangement_id = b.linkedarrangement;
begin
open c_bulk;
loop
fetch c_bulk bulk collect into ref_bulk limit 25000;
forall i in 1 .. ref_bulk.count
insert into tb1446_copy values ref_bulk(i);
exit when c_bulk%notfound;
end loop;
close c_bulk;
end;
单个进程执行一个hash分区的耗时是00:01:16.68
SQL> exec migration_tb1446_part_00;
PL/SQL procedure successfully completed.
Elapsed: 00:01:16.68
考虑资源配置(cpu,i/o)可以采用并行方式处理.
我这里四个进程并行处理20个分区总共耗时7分17秒完成.
迁移后tb1446_copy表记录数
SQL> select count(*) from tb1446_copy;
COUNT(*)
----------
2890208
这里要说明一点:
a.arrangement_id = b.linkedarrangement必须是主外键连接才能保证tb1446_copy表内没有重复数据.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/76065/viewspace-873617/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/76065/viewspace-873617/