设为首页 加入收藏

TOP

删除大表的数据:普通删除语句和游标处理的比较(五)
2015-07-24 12:05:16 来源: 作者: 【 】 浏览:93
Tags:删除 数据 普通 语句 游标 处理 比较
d;
end loop;
dbms_output.put_line(c1%rowcount||' row deleted.');
close c1;
end;

/

性能数据:
------------

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 1909760 113.98 154.81 36737 2053459 2121671 1909760
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1909761 113.98 154.81 36737 2053459 2121671 1909760

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

Rows Row Source Operation
------- ---------------------------------------------------
1909760 DELETE ROBO (cr=2053679 pr=36737 pw=0 time=79817096 us)
1909760 TABLE ACCESS BY USER ROWID ROBO (cr=2053394 pr=36266 pw=0 time=12527588 us)


Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 36735 0.00 0.22
log file switch completion 21 0.97 12.30
log file switch (checkpoint incomplete) 72 0.97 30.14
********************************************************************************

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%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 49.21 47.42 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 49.21 47.42 0 0 0 1

Misses in library cache during parse: 0
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 2 0.00 0.00
SQL*Net message from client 2 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 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 39 2.48 2.42 126813 221222 1 1909760
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 41 2.48 2.42 126813 221222 1 1909760

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

Rows Row Source Operation
------- ---------------------------------------------------
1909760 TABLE ACCESS FULL ROBO (cr=221222 pr=126813 pw=0 time=1910539 us)


Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 306 0.00 0.00
db file scattered read 7945 0.00 0.47
latch: object queue header operation 2 0.00 0.00
db file parallel read 1 0.00 0.00

全表扫描一次,但由于是批量提取数据(每次定为5万条)提高,减少提取次数,比起上一种方法节省了很

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

评论

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