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)