设为首页 加入收藏

TOP

删除大表的数据:普通删除语句和游标处理的比较(四)
2015-07-24 12:05:16 来源: 作者: 【 】 浏览:92
Tags:删除 数据 普通 语句 游标 处理 比较
iate v_sqltext using 2 3 4 5 6 7 8 9 10 v_rowid;
exit when c1%notfound;
end loop;
dbms_output.put_line(c1%rowcount||' row deleted.');
close c1;
end;
/
11 12 13 14 15 16

PL/SQL procedure successfully completed.

Elapsed: 00:04:12.89

?

性能数据:

-------------

delete from robo
where
rowid=:1


call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1909761 112.14 162.39 344 1909874 2124331 1909760
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1909762 112.14 162.39 344 1909874 2124331 1909760

Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 52 (recursive depth: 1)

Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 342 0.00 0.00
log file switch completion 19 0.97 12.66
log file switch (checkpoint incomplete) 76 0.97 39.72
********************************************************************************

declare
v_rowid varchar2(25);
v_sqltext varchar2(200);
cursor c1 is select rowid from robo where owner='SYS';
begin
v_sqltext := 'delete from robo where rowid=:1';
open c1;
loop
fetch c1 into v_rowid;
execute immediate v_sqltext using v_rowid;
exit when c1%notfound;
end loop;
dbms_output.put_line(c1%rowcount||' row deleted.');
close c1;
end;

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 77.46 75.43 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 77.46 75.43 0 0 0 1

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 52

Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
********************************************************************************

SELECT ROWID
FROM
ROBO WHERE OWNER='SYS'


call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 1 1 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1909761 11.68 11.27 59936 2035069 0 1909760
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1909763 11.69 11.27 59937 2035070 0 1909760

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 52 (recursive depth: 1)

Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 18.98 18.98
db file sequential read 7 0.00 0.00
db file scattered read 3798 0.00 0.21

?

游标执行一次,将所有符合条件的ROWID一次性查询出来,但提取次数和删除次数与结果集相当。比起直接删除效率来得慢.

?

3. 游标处理(批量提取)

declare
type var_tab is table of varchar2(25) index by pls_integer;
v_rowid var_tab;
v_sqltext varchar2(200);
cursor c1 is select rowid from robo where owner='SYS';
begin
v_sqltext := 'delete from robo where rowid=:1';
open c1;
loop
fetch c1 bulk collect into v_rowid limit 50000;
for i in 1..v_rowid.count loop
execute immediate v_sqltext using v_rowid(i);
end loop;
exit when c1%notfoun

首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇数据库中nextVal,currVal的应用. 下一篇OGGrep运行慢的分析步骤

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: