请问如果我们不需要进行任何更新,插入语句会比 Oracle 中的合并语句执行得更好吗?
我知道,如果我们需要同时为同一个表运行插入和更新语句,则单个合并语句通常是首选选项。但是如果我只有一个插入语句呢?
我有20张这样的桌子
Create Table Txn_History nologging (
ID number,
Comment varchar2(300),
... (Another 20 columns),
Std_hash raw(1000)
);
Alter table Txn_History add constraint Order_line_PK Primary (Std_hash);
还有20个这样的临时表
Create Table Order_line_staging nologging (
ID number,
Comment varchar2(300),
... (Another 20 columns),
Std_hash raw(1000)
);
Alter table Order_line_staging add constraint Order_line_PK Primary (Std_hash);
每个 Txn_History 表现在有 4000 万行,我将分批从每个对应的 Txn_History_staging 中插入另外 5000 万行。每批有 100 万行。在每次迭代结束时,将使用 purge 语句删除临时表。
以下是我的合并声明
Merge into Txn_History Target
using Txn_History_Staging source on
(source.std_hash = Target.std_has)
when not matched then
insert(
ID,
Comment,
... (Another 20 columns),
std_hash
),
values
(
Target.ID,
Target.comment,
... (Another 20 columns),
Target.std_hash
);
我的数据库处于归档日志模式(FORCE_LOGGING = 'NO'),我注意到每次迭代需要 2 小时才能运行,并且仍然生成 25GB 归档日志事件 nologging is on。
所以我怀疑合并语句已经生成了归档日志。
如果我使用以下插入语句会更好:
insert /*+append */ into Txn_History Target
select
*
from
Txn_History_staging Source
where
Source.std_hash not in (select distinct std_hash from txn_history);
它会有更好的性能(即运行速度更快并且生成的日志更少)吗?
提前致谢!