2011-12-13 62 views
1

我有以下查詢需要12小時執行,是否可以優化?表YYYYYDRV_START_DATENUMBER數據類型,因此將輸入值轉換爲to_number將有所幫助。合併查詢花費超過12小時執行任何優化

MERGE INTO XXXX D USING(
    SELECT /*+parallel(a 10)*/ 
      a.BATCH_NUMBER,COUNT(*) AS CALL_COUNT 
    FROM [email protected]_RAPROD a 
    WHERE a.DRV_START_DATE BETWEEN TO_CHAR(SYSDATE-7,'YYYYMMDD') 
           AND TO_CHAR(SYSDATE,'YYYYMMDD') 
     AND a.TOTAL_TYPE =195 
    GROUP BY a.BATCH_NUMBER) 
ON (D.BATCH_NUMBER=S.BATCH_NUMBER) 
WHEN MATCHED THEN 
    UPDATE SET D.CALL_COUNT=S.CALL_COUNT 
WHEN NOT MATCHED THEN 
    INSERT (D.BATCH_NUMBER,D.CALL_COUNT) 
    VALUES (S.BATCH_NUMBER,S.CALL_COUNT) 
+0

DRV_START_DATE是DATE還是VARCHAR2列? – Ollie

+0

@Ollie:表YYYYY的DRV_START_DATE是「NUMBER」數據類型。我提到 –

+0

所以你做了,我應該學會完全閱讀這篇文章!我很抱歉。 – Ollie

回答

3

你有一個分佈式查詢,從遠程站點的數據來。 Oracle工作的默認方式是從遠程站點提取所有數據並在本地站點上進行過濾。

根據相關數據量的不同,這可能是您的情況不好的選擇。如果是這樣,您可以使用DRIVING_SITE提示,該提示將評估遠程站點上的聯接並將結果返回到本地數據庫。

我從來沒有使用DRIVING_SITE用MERGE,但我覺得這樣的事情應該工作:

MERGE INTO XXXX D USING(
    SELECT /*+parallel(a 10) DRIVING_SITE(YYYYY)*/ 
      a.BATCH_NUMBER,COUNT(*) AS CALL_COUNT 
    FROM [email protected]_RAPROD a 
    WHERE a.DRV_START_DATE BETWEEN TO_CHAR(SYSDATE-7,'YYYYMMDD') 
           AND TO_CHAR(SYSDATE,'YYYYMMDD') 
     AND a.TOTAL_TYPE =195 
    GROUP BY a.BATCH_NUMBER) 
ON (D.BATCH_NUMBER=S.BATCH_NUMBER) 
WHEN MATCHED THEN 
    UPDATE SET D.CALL_COUNT=S.CALL_COUNT 
WHEN NOT MATCHED THEN 
    INSERT (D.BATCH_NUMBER,D.CALL_COUNT) 
    VALUES (S.BATCH_NUMBER,S.CALL_COUNT) 

順便說一句,你確定並行提示幫助你嗎?

+0

謝謝,我會嘗試 –

+0

PARALLEL暗示是由我們的dba團隊給出的。對不起,我不擅長深入sql。 –

+0

問題是,哪個數據庫並行(恐懼詞)? – APC

相關問題