我正在尝试更新一个包含137459条记录的表。我的查询正在使用Cost运行:4,但它不执行。
我的执行查询如下:
UPDATE TF_IMPORT_BILL_ISSUE N
SET N.OPERATION_ID =
(SELECT TRANSACTION_ID
FROM ( SELECT /*+ INDEX(BT TF_IMP_BILL_TXN_BILLID) */
MAX (BT.TRANSACTION_ID) TRANSACTION_ID, BI.BILL_ID
FROM TF_IMP_BILL_TRANSACTIONS BT,
TF_IMPORT_BILL_ISSUE BI,
CONV_BRANCH_INFO BRANCH
WHERE BRANCH.IS_FOR_MIGRATION = 1
AND BI.OPERATION_ID IS NULL
AND BRANCH.BRANCH_ID = BI.OWNER_BRANCH_ID
AND BT.BILL_ID = BI.BILL_ID
GROUP BY BI.BILL_ID) v
WHERE v.bill_id = n.bill_id)
WHERE N.BILL_ID IN (SELECT bill_id
FROM ( SELECT /*+ INDEX(BI) */
MAX (BT.TRANSACTION_ID) TRANSACTION_ID,
BI.BILL_ID
FROM TF_IMP_BILL_TRANSACTIONS BT,
TF_IMPORT_BILL_ISSUE BI,
CONV_BRANCH_INFO BRANCH
WHERE BRANCH.IS_FOR_MIGRATION = 1
AND BI.OPERATION_ID IS NULL
AND BRANCH.BRANCH_ID = BI.OWNER_BRANCH_ID
AND BT.BILL_ID = BI.BILL_ID
GROUP BY BI.BILL_ID) V);
执行计划如下:
------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT | | 1 | 52 | 4 (25)| 00:00:01 |
| 1 | UPDATE | TF_IMPORT_BILL_ISSUE | | | | |
| 2 | NESTED LOOPS | | 1 | 52 | 1 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 1 | 52 | 1 (0)| 00:00:01 |
| 4 | VIEW | VW_NSO_1 | 1 | 13 | 0 (0)| 00:00:01 |
| 5 | SORT GROUP BY | | 1 | 58 | 0 (0)| 00:00:01 |
| 6 | NESTED LOOPS SEMI | | 1 | 58 | 0 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 1 | 52 | 0 (0)| 00:00:01 |
| 8 | INDEX FULL SCAN | TF_IMP_BILL_TXN_BILLID | 1 | 13 | 0 (0)| 00:00:01 |
|* 9 | TABLE ACCESS BY INDEX ROWID BATCHED| TF_IMPORT_BILL_ISSUE | 1 | 39 | 0 (0)| 00:00:01 |
| 10 | INDEX FULL SCAN | TF_IMPORT_BILL_ISSUE_ONBR | 1 | | 0 (0)| 00:00:01 |
|* 11 | TABLE ACCESS BY INDEX ROWID BATCHED | CONV_BRANCH_INFO | 2 | 12 | 0 (0)| 00:00:01 |
|* 12 | INDEX RANGE SCAN | CBI_BR_ID | 1 | | 0 (0)| 00:00:01 |
|* 13 | INDEX UNIQUE SCAN | SYS_C0016767 | 1 | | 0 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID | TF_IMPORT_BILL_ISSUE | 1 | 39 | 1 (0)| 00:00:01 |
| 15 | VIEW | | 1 | 26 | 1 (0)| 00:00:01 |
| 16 | SORT GROUP BY | | 1 | 71 | 1 (0)| 00:00:01 |
| 17 | NESTED LOOPS | | 1 | 71 | 1 (0)| 00:00:01 |
| 18 | NESTED LOOPS | | 1 | 45 | 1 (0)| 00:00:01 |
|* 19 | TABLE ACCESS BY INDEX ROWID | TF_IMPORT_BILL_ISSUE | 1 | 39 | 1 (0)| 00:00:01 |
|* 20 | INDEX UNIQUE SCAN | SYS_C0016767 | 1 | | 1 (0)| 00:00:01 |
|* 21 | TABLE ACCESS BY INDEX ROWID BATCHED | CONV_BRANCH_INFO | 1 | 6 | 0 (0)| 00:00:01 |
|* 22 | INDEX RANGE SCAN | CBI_BR_ID | 1 | | 0 (0)| 00:00:01 |
| 23 | TABLE ACCESS BY INDEX ROWID BATCHED | TF_IMP_BILL_TRANSACTIONS | 1 | 26 | 0 (0)| 00:00:01 |
|* 24 | INDEX RANGE SCAN | TF_IMP_BILL_TXN_BILLID | 1 | | 0 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
9 - filter("BI"."OPERATION_ID" IS NULL AND "BT"."BILL_ID"="BI"."BILL_ID")
11 - filter("BRANCH"."IS_FOR_MIGRATION"=1)
12 - access("BRANCH"."BRANCH_ID"="BI"."OWNER_BRANCH_ID")
13 - access("N"."BILL_ID"="BILL_ID")
19 - filter("BI"."OPERATION_ID" IS NULL)
20 - access("BI"."BILL_ID"=:B1)
21 - filter("BRANCH"."IS_FOR_MIGRATION"=1)
22 - access("BRANCH"."BRANCH_ID"="BI"."OWNER_BRANCH_ID")
24 - access("BT"."BILL_ID"=:B1)
请帮助我如何优化此查询执行。
**注意:**查询的引用表记录为TF_IMPORT_BILL_ISSUE(137,459)、TF_IMP_BILL_TRANSACTIONS(239,712)和CONV_分支_INFO(2)。
2条答案
按热度按时间41zrol4v1#
merge
怎么样?fzsnzjdm2#
你可以使用
MERGE
语句: