plsql更新百万条记录表的性能检查
下面的块尝试使用表 t2 中找到的数据更新大表 t1。当我更新具有 500 条记录的注释代码但需要 30 分钟才能更新超过 1000 条记录时,这似乎很好。我尝试了批量收集更新和注释代码索引,没有太多时间差异。
DECLARE
lv_row_count NUMBER(9) := 0;
lv_total_count NUMBER(9) := 0;
lv_commit_cnt SIMPLE_INTEGER:=0;
BEGIN
FOR rec in
(SELECT
a.t1_id,
a.t1_orig_code,
t2_orig_code,
a.t1_comment_code,
t2_code,
a.t1_restrict_update_ind,
t2_restrict_update_ind,
a.t1_data_origin,
t2_data_origin,
a.t1_purge_ind,
t2_purge_ind,
a.t1_created_date,
a.rowid
FROM t1 a
JOIN t2 ON t2_code = a.t1_comment_code
WHERE a.t1_comment_code in ('A','B','C','C1','D3')
AND ( a.t1_orig_code != t2_orig_code OR a.t1_restrict_update_ind !=t2_restrict_update_ind
OR a.t1_data_origin != t2_data_origin OR a.t1_purge_ind != t2_purge_ind)
)
LOOP
lv_total_count := lv_total_count + 1;
UPDATE t1
SET t1_ORIG_CODE= rec.t2_orig_code
t1_RESTRICT_UPDATE_IND = 'Y',,
t1_DATA_ORIGIN = rec.t2_data_origin,
t1_PURGE_IND =rec.t2_purge_ind
WHERE t1.rowid =rec.rowid ;
lv_commit_cnt:=lv_commit_cnt+1;
IF MOD(lv_commit_cnt,lv_limit)=0 THEN
lv_commit_cnt:=0;
COMMIT;
END IF;
dbms_output.put_line('a.t1_pidm -'||rec.t1_pidm ||
'a.t1_orig_code -'||rec.t1_orig_code ||'Updated');
END LOOP;
COMMIT;
dbms_output.put_line('Total_count- '||lv_total_count);
-- dbms_output.put_line('No record');
END;
感谢对此的投入。
The below block tries to update a large table t1 with data found in table t2.It seems fine when i update for comment code that has 500 records but takes 30 minutes to update more than 1000 records. I tried the bulk collect update and index on comment code there is not much of time difference.
DECLARE
lv_row_count NUMBER(9) := 0;
lv_total_count NUMBER(9) := 0;
lv_commit_cnt SIMPLE_INTEGER:=0;
BEGIN
FOR rec in
(SELECT
a.t1_id,
a.t1_orig_code,
t2_orig_code,
a.t1_comment_code,
t2_code,
a.t1_restrict_update_ind,
t2_restrict_update_ind,
a.t1_data_origin,
t2_data_origin,
a.t1_purge_ind,
t2_purge_ind,
a.t1_created_date,
a.rowid
FROM t1 a
JOIN t2 ON t2_code = a.t1_comment_code
WHERE a.t1_comment_code in ('A','B','C','C1','D3')
AND ( a.t1_orig_code != t2_orig_code OR a.t1_restrict_update_ind !=t2_restrict_update_ind
OR a.t1_data_origin != t2_data_origin OR a.t1_purge_ind != t2_purge_ind)
)
LOOP
lv_total_count := lv_total_count + 1;
UPDATE t1
SET t1_ORIG_CODE= rec.t2_orig_code
t1_RESTRICT_UPDATE_IND = 'Y',,
t1_DATA_ORIGIN = rec.t2_data_origin,
t1_PURGE_IND =rec.t2_purge_ind
WHERE t1.rowid =rec.rowid ;
lv_commit_cnt:=lv_commit_cnt+1;
IF MOD(lv_commit_cnt,lv_limit)=0 THEN
lv_commit_cnt:=0;
COMMIT;
END IF;
dbms_output.put_line('a.t1_pidm -'||rec.t1_pidm ||
'a.t1_orig_code -'||rec.t1_orig_code ||'Updated');
END LOOP;
COMMIT;
dbms_output.put_line('Total_count- '||lv_total_count);
-- dbms_output.put_line('No record');
END;
Appreciate inputs on this .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
毫不奇怪,这需要很长时间。逐行处理是很慢的。
那么
合并
怎么样?就这样;没有 PL/SQL,没有循环,循环中间没有提交……什么都没有。只需
合并
即可。No surprise it takes ages; row-by-row processing is slow-by-slow.
How about
merge
, instead?Just like that; no PL/SQL, no loop, no commit in the middle of the loop ... nothing. Just
merge
.