请建议我更好的代码
方法(A)
MERGE /*+ Idx_Mrx_Strategy */INTO stgMurex m
USING
(
SELECT m.RowId AS mRowId
FROM stgMurex m
INNER JOIN LovDF_EMIR t
ON m.Strategy = t.Strategy
WHERE t.NonDF = 'Y'
) l
ON (m.RowId = l.mRowId)
WHEN MATCHED THEN
UPDATE SET
m.DF = 'N'
WHERE m.DF IS NULL
;
Rows Plan 199448 MERGE STATEMENT MERGE STGMUREX VIEW 199448 HASH JOIN 199448 HASH JOIN 130 TABLE ACCESS FULL LOVDF_EMIR 576864 TABLE ACCESS FULL STGMUREX 1426340 TABLE ACCESS FULL STGMUREX
方法(B)
MERGE INTO stgMurex m
USING
(
SELECT t.Strategy
FROM LovDF_EMIR t
WHERE t.NonDF = 'Y'
) l
ON (m.Strategy = l.Strategy)
WHEN MATCHED THEN
UPDATE SET
m.DF = 'N'
WHERE m.DF IS NULL
;
Rows Plan 199448 MERGE STATEMENT MERGE STGMUREX VIEW 199448 HASH JOIN 130 TABLE ACCESS FULL LOVDF_EMIR 576864 TABLE ACCESS FULL STGMUREX
我可以说方法B最好吗?
答案 0 :(得分:0)
我想(假设"从驾驶表返回的成功行的百分比很小"这可能是由" t.NonDF =' Y'&#34引起的;)与join的合并效率更高:
UPDATE stgMurex m
SET m.DF = 'N'
WHERE m.DF IS NULL
AND EXISTS
(SELECT 1 FROM LovDF_EMIR t WHERE t.NonDF = 'Y' AND m.Strategy = t.Strategy
);
这里有很好的解释:http://www.toadworld.com/platforms/oracle/w/wiki/4778.table-joins-versus-exists.aspx