爱易网页
数据库教程
从大表中删除小表中存在的记录有关问题
日期:2014-05-16 浏览次数:20447 次
【求助】从大表中删除小表中存在的记录问题
A表:30万,主键ID
B表:300万,主键ID
从B表中删除ID=A表ID的记录。
DELETE FROM B WHERE EXISTS (SELECT 1 FROM (SELECT ID FROM (SELECT T.ID, ROWNUM RN FROM A) WHERE RN > 0 AND RN <= 50000) AB WHERE A.ID = B.ID);
但执行计划显示COST较大,且瓶颈是B表的全表扫描。
需求是这里有B1 ... B10多个B表(都是300万),串行操作相当于10次B表的全表扫描,因为磁盘IO性能较差,执行单个DELETE时都可能占据较大CPU,所以不能并行。
是否还有优化空间呢?请高手指点,谢谢!
Execution Plan
----------------------
Plan hash value: 3752040547
-------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-------------------------------------------------------------
| 0 | SELECT STATEMENT | | 225K| 15M| | 18309 (1)| 00:03:40 |
|* 1 | HASH JOIN RIGHT SEMI | | 225K| 15M| 4168K| 18309 (1)| 00:03:40 |
|* 2 | VIEW | | 133K| 2604K| | 88 (2)| 00:00:02 |
| 3 | COUNT | | | | | | |
| 4 | INDEX FAST FULL SCAN| P_A | 133K| 911K| | 88 (2)| 00:00:02 |
| 5 | TABLE ACCESS FULL | B | 3598K| 171M| | 7448 (1)| 00:01:30 |
-------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."ID"="ID")
2 - filter("RN">0 AND "RN"<=50000)
Statistics
----------------------
1 recursive calls
0 db block gets
27479 consistent gets
0 physical reads
0 redo size
11651 bytes sent via SQL*Net to client
645 bytes received via SQL*Net from client
13 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
168 rows processed
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。