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