У меня есть оператор вставки, который выполняется слишком долго или выполняется вечно. Я выполняю этот запрос из sql * plus. Ниже приведены значения и ключи / индексы, определенные для каждой таблицы, используемой в запросе выбора.
TAB_A; --1000000(composite keys defined ORD_ID,C_TYPE)
TAB_B;--40000000(ID,GAME_ID,START_TIME)
TAB_C;--1000000(EMAIL_ADDR,SRC_FILE_DT)
TAB_D;--100000(EMAIL_ADDR)
TAB_E;--900000
TAB_F ;--7000
TAB_G;--250
Insert statement
-----------------
INSERT /*+ append */ INTO TEST1
select * from
(
SELECT 'TAG' AS CAT,
A.ID AS CAT_ID,
A.ORD_ID,
B.P_NAME AS P_NAME,
A.C_TYPE AS C_TYPE,
round(NVL(A.AMT,0)/E.RATE,2) as PAY_USD,
C.CNTY_CD AS BILL_CNTY,
F.YEAR AS YEAR,
G.COUNTRY AS COUNTY,
D.VAT_ID AS VAT_ID,
C.CONV,
A.KEY_ORG AS KEY_ORG,
row_number() over (partition by A.KEY_ORG order by A.KEY_ORG) AS RNK
FROM (SELECT * FROM TAB_A) A
LEFT JOIN TAB_B B on B.ID = A.ID
LEFT JOIN TAB_C C ON C.ID = A.ID
LEFT JOIN TAB_D D ON D.ID = A.ID
LEFT JOIN TAB_E E on trunc(A.FROM_DT) = trunc(E.cal_dt) and A.CURR_CD = E.CURR_CD
LEFT JOIN TAB_F F ON TRUNC(F.CAL_DT) = TRUNC(A.YEAR)
LEFT JOIN TAB_G G ON UPPER(TRIM(G.COUNTRY)) = UPPER(TRIM(A.COUNTY))
)a
where RNK = 1;
Что-то не так в используемом соединении или любом другом способе написания этого запроса более эффективным способом. Пожалуйста, позвольте мнезнать, если какая-либо информация отсутствует.
Объяснить план
Plan hash value: 2478932650
-------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 1 | 2199 | | 940M (3)| 01:18:01 | | | |
| 1 | LOAD AS SELECT | TEST1 | | | | | | | | |
| 2 | PX COORDINATOR | | | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10005 | 1 | 2199 | | 940M (3)| 01:18:01 | Q1,05 | P->S | QC (RAND) |
| 4 | OPTIMIZER STATISTICS GATHERING | | 1 | 2199 | | 940M (3)| 01:18:01 | Q1,05 | PCWC | |
|* 5 | VIEW | | 1 | 2199 | | 940M (3)| 01:18:01 | Q1,05 | PCWP | |
|* 6 | WINDOW SORT PUSHED RANK | | 218G| 62T| 64T| 940M (3)| 01:18:01 | Q1,05 | PCWP | |
| 7 | PX RECEIVE | | 218G| 62T| | 940M (3)| 01:18:01 | Q1,05 | PCWP | |
| 8 | PX SEND HASH | :TQ10004 | 218G| 62T| | 940M (3)| 01:18:01 | Q1,04 | P->P | HASH |
|* 9 | WINDOW CHILD PUSHED RANK | | 218G| 62T| | 940M (3)| 01:18:01 | Q1,04 | PCWP | |
|* 10 | HASH JOIN RIGHT OUTER | | 218G| 62T| 446M| 6387K (20)| 00:00:32 | Q1,04 | PCWP | |
| 11 | PX RECEIVE | | 42M| 1298M| | 148K (1)| 00:00:01 | Q1,04 | PCWP | |
| 12 | PX SEND BROADCAST | :TQ10000 | 42M| 1298M| | 148K (1)| 00:00:01 | Q1,00 | P->P | BROADCAST |
| 13 | PX BLOCK ITERATOR | | 42M| 1298M| | 148K (1)| 00:00:01 | Q1,00 | PCWC | |
| 14 | TABLE ACCESS FULL | TAB_B | 42M| 1298M | | 148K (1)| 00:00:01 | Q1,00 | PCWP |
|* 15 | HASH JOIN RIGHT OUTER | | 1468M| 384G| | 22273 (39)| 00:00:01 | Q1,04 | PCWP | |
|* 16 | TABLE ACCESS FULL | TAB_E | 757K| 15M | | 177 (7)| 00:00:01 | Q1,04 | PCWP |
|* 17 | HASH JOIN RIGHT OUTER | | 23M| 5813M| | 13894 (3)| 00:00:01 | Q1,04 | PCWP | |
| 18 | TABLE ACCESS FULL | TAB_B | 1631K| 29M| | 7019 (1)| 00:00:01 | Q1,04 | PCWP | |
|* 19 | HASH JOIN RIGHT OUTER | | 4033K| 927M| | 6730 (2)| 00:00:01 | Q1,04 | PCWP | |
| 20 | PX RECEIVE | | 247 | 3211 | | 11 (0)| 00:00:01 | Q1,04 | PCWP | |
| 21 | PX SEND BROADCAST | :TQ10001 | 247 | 3211 | | 11 (0)| 00:00:01 | Q1,01 | S->P | BROADCAST |
| 22 | PX SELECTOR | | | | | | | Q1,01 | SCWC | |
| 23 | TABLE ACCESS FULL | TAB_G | 247 | 3211 | | 11 (0)| 00:00:01 | Q1,01 | SCWP | |
|* 24 | HASH JOIN RIGHT OUTER | | 1633K| 355M| | 6697 (2)| 00:00:01 | Q1,04 | PCWP | |
| 25 | PX RECEIVE | | 117K| 6979K| | 848 (1)| 00:00:01 | Q1,04 | PCWP | |
| 26 | PX SEND BROADCAST | :TQ10002 | 117K| 6979K| | 848 (1)| 00:00:01 | Q1,02 | P->P | BROADCAST |
| 27 | PX BLOCK ITERATOR | | 117K| 6979K| | 848 (1)| 00:00:01 | Q1,02 | PCWC | |
| 28 | TABLE ACCESS FULL | TAB_D | 117K| 6979K| | 848 (1)| 00:00:01 | Q1,02 | PCWP | |
|* 29 | HASH JOIN RIGHT OUTER| | 1629K| 259M| | 5838 (2)| 00:00:01 | Q1,04 | PCWP | |
| 30 | PX RECEIVE | | 7671 | 92052 | | 10 (10)| 00:00:01 | Q1,04 | PCWP | |
| 31 | PX SEND BROADCAST | :TQ10003 | 7671 | 92052 | | 10 (10)| 00:00:01 | Q1,03 | S->P | BROADCAST |
| 32 | PX SELECTOR | | | | | | | Q1,03 | SCWC | |
| 33 | TABLE ACCESS FULL| TAB_F | 7671 | 92052 | | 10 (10)| 00:00:01 | Q1,03 | SCWP | |
| 34 | PX BLOCK ITERATOR | | 1873K| 276M| | 5818 (2)| 00:00:01 | Q1,04 | PCWC | |
| 35 | TABLE ACCESS FULL | TAB_A | 1873K| 276M| | 5818 (2)| 00:00:01 | Q1,04 | PCWP | |
-------------------------------------------------------------------------------------------------------------------------------------------------------
введите описание изображения здесь