奇怪的是,此查询在我的AWR报告中显示为" UnOptimized"。我希望每个人都能帮助我理解表现的差异。
以下是表格
CREATE TABLE STGE_TABLE(
FIELD_01 NUMBER,
FIELD_02 NUMBER,
FIELD_03 DATE,
BATCH_ID NUMBER
) PARTITION BY RANGE (BATCH_ID) INTERVAL(1)
PARTITION EMPTY VALUES LESS THAN (0);
CREATE TABLE LIVE_TABLE(
FIELD_01 NUMBER,
FIELD_02 NUMBER,
FIELD_03 DATE
);
这是包裹:
CREATE OR REPLACE PACKAGE MY_MERGE_PKG
AS
PROCEDURE MERGE_MY_TWO_TABLES;
END MY_MERGE_PKG;
CREATE OR REPLACE PACKAGE BODY MY_MERGE_PKG
AS
PROCEDURE MERGE_MY_TWO_TABLES
AS
ln_batch_id number;
lc_queue_src varchar(10);
BEGIN
LOOP
BEGIN
--GET THE NEXT BATCH_ID FROM THE QUEUE ALONG WITH THE lc_queue_src
IF lc_queue_src = 'TYPE_01' THEN
MERGE INTO LIVE_TABLE TGT
USING (
SELECT FIELD_01, FIELD_02, FIELD_03
FROM STGE_TABLE
WHERE BATCH_ID=ln_batch_id
) SRC
ON (SRC.FIELD_01 = TGT.FIELD_01)
WHEN MATCHED THEN
UPDATE SET TGT.FIELD_03 = SRC.FIELD_03
WHEN NOT MATCHED THEN
INSERT(TGT.FIELD_01, TGT_FIELD_03)
VALUES(SRC.FIELD_01, SRC.FIELD_03);
ELSE
MERGE INTO LIVE_TABLE TGT
USING (
SELECT FIELD_01, FIELD_02, FIELD_03
FROM STGE_TABLE
WHERE BATCH_ID=ln_batch_id
) SRC
ON (SRC.FIELD_01 = TGT.FIELD_01)
WHEN MATCHED THEN
UPDATE SET TGT.FIELD_02 = SRC.FIELD_02
WHEN NOT MATCHED THEN
INSERT(TGT.FIELD_01, TGT_FIELD_02)
VALUES(SRC.FIELD_01, SRC.FIELD_02);
END IF;
END;
END LOOP;
END MERGE_MY_TWO_TABLES;
在AWR报告中,它显示ELSE块中的合并未进行优化。我不太明白为什么它们实际上是相同的合并声明。
非常感谢任何有关此事的帮助。