我正在尝试使用分别具有 2 亿和 30 百万条记录的 REF_TAB 表从表 TAB1 更新一列 CODE,但更新记录需要 3-4 小时。
TAB1 -- 200000000(200mn)
ID VARCHAR2(10) PK on ID
T_ID VARCHAR2(10) --- duplicate values
X_CD VARCHAR2(2)
CODE VARCHAR2(2) -- list partition with 30 codes
REF_TAB --30000000(30 mn)
T_ID VARCHAR2(10) --- unique values
CODE VARCHAR2(2)
TAB1.ID 主键上的唯一索引是唯一索引。
我试过合并。有没有其他方法可以提高查询的性能或通过任何其他方式?
MERGE /*+ parallel(A,4) append */ INTO TAB1 A
USING (SELECT T_ID,CODE FROM REF_TAB) R
ON ( A.T_ID = R.T_ID
AND A.X_CD IS NOT NULL
)
WHEN MATCHED THEN
UPDATE
SET A.CODE = R.CODE;
COMMIT;
with append
Plan hash value: 3594611329
--------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | MERGE STATEMENT | | 93M| 714M| 494K (4)| 00:00:03 | | | | | |
| 1 | MERGE | TAB1 | | | | | | | | | |
| 2 | PX COORDINATOR | | | | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10001 | 93M| 27G| 494K (4)| 00:00:03 | | | Q1,01 | P->S | QC (RAND) |
| 4 | VIEW | | | | | | | | Q1,01 | PCWP | |
|* 5 | HASH JOIN | | 93M| 27G| 494K (4)| 00:00:03 | | | Q1,01 | PCWP | |
| 6 | PX RECEIVE | | 32M| 374M| 8430 (5)| 00:00:01 | | | Q1,01 | PCWP | |
| 7 | PX SEND BROADCAST | :TQ10000 | 32M| 374M| 8430 (5)| 00:00:01 | | | Q1,00 | S->P | BROADCAST |
| 8 | PX SELECTOR | | | | | | | | Q1,00 | SCWC | |
| 9 | TABLE ACCESS FULL| REF_TAB | 32M| 374M| 8430 (5)| 00:00:01 | | | Q1,00 | SCWP | |
| 10 | PX BLOCK ITERATOR | | 93M| 26G| 484K (3)| 00:00:03 | 1 | 35 | Q1,01 | PCWC | |
|* 11 | TABLE ACCESS FULL | TAB1 | 93M| 26G| 484K (3)| 00:00:03 | 1 | 35 | Q1,01 | PCWP | |
--------------------------------------------------------------------------------------------------------------------------------------------------
without append
Plan hash value: 3594611329
--------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | MERGE STATEMENT | | 103M| 790M| 494K (4)| 00:00:03 | | | | | |
| 1 | MERGE | TAB1 | | | | | | | | | |
| 2 | PX COORDINATOR | | | | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10001 | 103M| 30G| 494K (4)| 00:00:03 | | | Q1,01 | P->S | QC (RAND) |
| 4 | VIEW | | | | | | | | Q1,01 | PCWP | |
|* 5 | HASH JOIN | | 103M| 30G| 494K (4)| 00:00:03 | | | Q1,01 | PCWP | |
| 6 | PX RECEIVE | | 32M| 374M| 8430 (5)| 00:00:01 | | | Q1,01 | PCWP | |
| 7 | PX SEND BROADCAST | :TQ10000 | 32M| 374M| 8430 (5)| 00:00:01 | | | Q1,00 | S->P | BROADCAST |
| 8 | PX SELECTOR | | | | | | | | Q1,00 | SCWC | |
| 9 | TABLE ACCESS FULL| REF_TAB | 32M| 374M| 8430 (5)| 00:00:01 | | | Q1,00 | SCWP | |
| 10 | PX BLOCK ITERATOR | | 103M| 29G| 485K (4)| 00:00:03 | 1 | 35 | Q1,01 | PCWC | |
|* 11 | TABLE ACCESS FULL | TAB1 | 103M| 29G| 485K (4)| 00:00:03 | 1 | 35 | Q1,01 | PCWP | |
--------------------------------------------------------------------------------------------------------------------------------------------------