同事过来问我,truncate 比 delete 慢,怎么回事,我说应该不可能。不过接下来,我眼睛所看到的,却告诉我,确实如此。
SQL> delete from ac95;
已删除2行。
已用时间: 00: 00: 00.01
SQL> truncate table ac95;
表被截断。
已用时间: 00: 01: 32.88
而且不管是你执行truncate 多少次,每次都很慢。用10046跟踪了下truncate.输出如下:
truncate table ac95
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.15 82.94 2493 16 9069 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.15 82.95 2493 16 9069 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
reliable message 8 0.00 0.00
enq: RO - fast object reuse 8 0.53 1.38
db file sequential read 2493 0.44 15.95
local write wait 2131 0.39 65.41
rdbms ipc reply 16 0.00 0.00
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.00 0.00
********************************************************************************
时间主要花费在了local write wait,db file sequential read上面。思考中,希望大家讨论讨论,怎么回事。
SQL> delete from ac95;
已删除2行。
已用时间: 00: 00: 00.01
SQL> truncate table ac95;
表被截断。
已用时间: 00: 01: 32.88
而且不管是你执行truncate 多少次,每次都很慢。用10046跟踪了下truncate.输出如下:
truncate table ac95
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.15 82.94 2493 16 9069 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.15 82.95 2493 16 9069 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
reliable message 8 0.00 0.00
enq: RO - fast object reuse 8 0.53 1.38
db file sequential read 2493 0.44 15.95
local write wait 2131 0.39 65.41
rdbms ipc reply 16 0.00 0.00
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.00 0.00
********************************************************************************
时间主要花费在了local write wait,db file sequential read上面。思考中,希望大家讨论讨论,怎么回事。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22034023/viewspace-666582/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22034023/viewspace-666582/
本文通过实际案例展示了在Oracle数据库中使用truncate与delete操作时的性能差异,发现truncate操作相较于delete更为耗时,并通过10046跟踪分析了原因。

480

被折叠的 条评论
为什么被折叠?



