优化oracle中的合并查询

时间:2014-12-10 04:48:41

标签: plsql oracle11g

我在源表中有大约400000行,在目标表中有大约100000行。 我正在使用合并查询来插入和更新目标表。 目标表也对查询的on子句中使用的列进行唯一索引。 执行查询需要10分钟。

查询:

merge into target_table tgt 
using source_table src 
on(TGT.tgt_column=SRC.src_column) 
when matched 
then update(...) when not matched then insert(...)

解释查询计划是:

---------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------------
|   0 | MERGE STATEMENT                |                        |    10 | 94870 |    33   (0)| 00:00:01 |
|   1 |  MERGE                         | tgt_table   |       |       |            |          |
|   2 |   VIEW                         |                        |       |       |            |          |
|   3 |    NESTED LOOPS OUTER          |                        |    10 | 24070 |    33   (0)| 00:00:01 |
|   4 |     TABLE ACCESS FULL          | src_table     |    10 | 12040 |     3   (0)| 00:00:01 |
|   5 |     TABLE ACCESS BY INDEX ROWID| tgt_table    |     1 |  1203 |     3   (0)| 00:00:01 |
|*  6 |      INDEX RANGE SCAN          | tgt_index_01 |     1 |       |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   6 - access("TGT"."tgt_column"(+)="SRC"."src_column")

执行查询需要10分钟。 我需要将执行时间缩短到4-5分钟。

0 个答案:

没有答案