2014-02-07 205 views
0

我在嘗試優化以下Teradata查詢。任何人都可以請這個。檢索記錄花費很多時間。需要優化Teradata查詢

select top 100 I.item_sku_nbr,L.loc_nbr,MIS.MVNDR_PRTY_ID from 
QA_US_MASTER_VIEWS.item I, 
qa4_US_MASTER_VIEWS.location L, 
qa4_US_MASTER_VIEWS.item_str IST, 
qa4_US_MASTER_VIEWS.mvndr_item_str MIS 
    where MIS.str_LOC_ID = L.loc_id and  
mis.str_loc_id = IST.str_loc_id and  
IST.str_loc_id = L.loc_id and 
MIS.ITEM_STAT_CD = IST.ITEM_STAT_CD and  
IST.ITEM_ID = I.ITEM_ID and  
MIS.ITEM_ID = IST.ITEM_ID  and  
I.ITEM_STAT_CD = 100   and 
IST.curr_rmeth_cd = 2   and 
MIS.curr_dsvc_typ_cd = 3  and 
MIS.OK_TO_ORD_FLG = 'Y' and   
MIS.EFF_END_DT = DATE '9999-12-31' and 
IST.EFF_END_DT = DATE '9999-12-31' and 
MIS.ACTV_FLG ='Y' and  
IST.ACTV_FLG ='Y' and I.ACTV_FLG='Y' 

解釋計劃QA_US_MASTER.LOCATION

1)首先,鎖定鑑於 qa4_US_MASTER_VIEWS.Location QA_US_MASTER.LOCATION訪問。

2)接下來,我們做全AMP通過的方式檢索圖qa4_US_MASTER_VIEWS.Location從QA_US_MASTER.LOCATION 步驟的所有行掃描 沒有剩餘條件到線軸1(group_amps),這是 內置在AMP上本地。 Spool 1的大小估計爲 高置信度爲10,903行(1,613,644字節)。此步驟的估計時間爲0.01秒。

3)最後,我們發送一個END TRANSACTION步驟給涉及處理請求的所有AMPs 。

- >作爲 聲明1的結果,假脫機1的內容被髮回給用戶。總估計時間爲0.01秒。

解釋計劃qa4_US_MASTER_VIEWS.item_str

1)首先,我們針對 qa4_US_MASTER_VIEWS.item_str訪問鎖定QA_US_MASTER.item_str。

2)接下來,我們做全AMP通過的方式檢索圖qa4_US_MASTER_VIEWS.item_str從QA_US_MASTER.item_str 步驟的所有行掃描 沒有剩餘條件到線軸1(group_amps),這是 內置在AMP上本地。輸入表不會被緩存在 內存中,但它有資格進行同步掃描。假脫機文件的結果 不會被緩存在內存中。 Spool 1的大小爲 ,低置信度估計爲1,229,047,917行( 325,697,698,005字節)。此步驟的估計時間爲4分鐘和51秒。

3)最後,我們發送一個END TRANSACTION步驟給涉及處理請求的所有AMPs 。

- >作爲 聲明1的結果,假脫機1的內容被髮回給用戶。總估計時間爲4分51秒。

解釋計劃QA_US_MASTER.ITEM

1)首先,鎖定QA_US_MASTER.ITEM鑑於qa4_US_MASTER_VIEWS.item 訪問。

2)接下來,我們做全AMP通過的所有行的方式檢索 視圖qa4_US_MASTER_VIEWS.item從QA_US_MASTER.ITEM步驟沒有 殘餘條件到線軸1(group_amps),其內置 掃描在AMP上本地。假設1的大小估計爲具有很高的置信度爲1413284行(357,560,852字節)。此步驟的估計時間爲0.40秒。

3)最後,我們發送一個END TRANSACTION步驟給涉及處理請求的所有AMPs 。

- >作爲 聲明1的結果,假脫機1的內容被髮回給用戶。總估計時間爲0.40秒。

解釋計劃QA_US_MASTER.MVNDR_ITEM_STR:

1)首先,我們針對 qa4_US_MASTER_VIEWS.mvndr_item_str訪問鎖定QA_US_MASTER.MVNDR_ITEM_STR。

2)接下來,我們做全AMP通過的所有行的方式檢索圖 qa4_US_MASTER_VIEWS.mvndr_item_str從 QA_US_MASTER.MVNDR_ITEM_STR步驟與 掃描沒有剩餘條件到線軸1(group_amps),這是建 本地在AMP上。輸入表格不會被緩存在內存中, 但它有資格進行同步掃描。結果線軸 文件不會被緩存在內存中。 Spool 1的大小爲 ,估計可信度高達1,316,279,746行( 327,753,656,754字節)。此步驟的估計時間爲6分鐘,時間爲12分鐘,時間爲4分鐘。

3)最後,我們發送一個END TRANSACTION步驟給涉及處理請求的所有AMPs 。

- >作爲 聲明1的結果,假脫機1的內容被髮回給用戶。總估計時間爲6分4秒。

解釋計劃整個查詢

1) First, we lock QA_US_MASTER.ITEM in view QA_US_MASTER_VIEWS.item 
    for access, we lock QA_US_MASTER.LOCATION in view 
    qa4_US_MASTER_VIEWS.location for access, we lock 
    QA_US_MASTER.MVNDR_ITEM_STR in view 
    qa4_US_MASTER_VIEWS.mvndr_item_str for access, and we lock 
    QA_US_MASTER.item_str in view qa4_US_MASTER_VIEWS.item_str for 
    access. 

    2) Next, we execute the following steps in parallel. 
    1) We do an all-AMPs RETRIEVE step from QA_US_MASTER.LOCATION in 
     view qa4_US_MASTER_VIEWS.location by way of an all-rows scan 
     with no residual conditions into Spool 3 (all_amps) 
     (compressed columns allowed), which is duplicated on all AMPs. 
     The size of Spool 3 is estimated with high confidence to be 
     1,013,979 rows (20,279,580 bytes). The estimated time for 
     this step is 0.03 seconds. 

    2) We do an all-AMPs RETRIEVE step from QA_US_MASTER.ITEM in 
     view QA_US_MASTER_VIEWS.item by way of an all-rows scan with 
     a condition of ("(QA_US_MASTER.ITEM in view 
     QA_US_MASTER_VIEWS.item.ITEM_STAT_CD = 100) AND 
     (QA_US_MASTER.ITEM in view QA_US_MASTER_VIEWS.item.ACTV_FLG = 
     'Y')") into Spool 4 (all_amps) (compressed columns allowed) 
     fanned out into 14 hash join partitions, which is duplicated 
     on all AMPs. The size of Spool 4 is estimated with low 
     confidence to be 30,819,363 rows (678,025,986 bytes). The 
     estimated time for this step is 0.81 seconds. 

    3) We do an all-AMPs JOIN step from Spool 3 (Last Use) by way of an 
    all-rows scan, which is joined to QA_US_MASTER.item_str in view 
    qa4_US_MASTER_VIEWS.item_str by way of an all-rows scan with a 
    condition of 
    ("(QA_US_MASTER.item_str in view 
    qa4_US_MASTER_VIEWS.item_str.CURR_RMETH_CD = 2) AND 
    ((QA_US_MASTER.item_str in view 
    qa4_US_MASTER_VIEWS.item_str.EFF_END_DT = DATE '9999-12-31') AND 
    (QA_US_MASTER.item_str in view 
    qa4_US_MASTER_VIEWS.item_str.ACTV_FLG = 'Y'))"). Spool 3 and 
    QA_US_MASTER.item_str are joined using a dynamic hash join, with a 
    join condition of ("QA_US_MASTER.item_str.STR_LOC_ID = LOC_ID"). 
    The input table QA_US_MASTER.item_str will not be cached in memory. 
    The result goes into Spool 5 (all_amps) (compressed columns 
    allowed), which is built locally on the AMPs into 14 hash join 
    partitions. The size of Spool 5 is estimated with no confidence 
    to be 69,133,946 rows (2,419,688,110 bytes). The estimated time 
    for this step is 1 minute and 8 seconds. 

    4) We do an all-AMPs JOIN step from Spool 4 (Last Use) by way of an 
    all-rows scan, which is joined to Spool 5 (Last Use) by way of an 
    all-rows scan. Spool 4 and Spool 5 are joined using a hash join 
    of 14 partitions, with a join condition of ("(ITEM_ID = ITEM_ID) 
    AND (ACTV_FLG = ACTV_FLG)"). The result goes into Spool 6 
    (all_amps) (compressed columns allowed), which is redistributed by 
    the hash code of (QA_US_MASTER.item_str.STR_LOC_ID, 
    QA_US_MASTER.item_str.ITEM_STAT_CD, QA_US_MASTER.item_str.ITEM_ID, 
    QA_US_MASTER.ITEM.ITEM_ID, QA_US_MASTER.LOCATION.LOC_ID) to all 
    AMPs into 33 hash join partitions. The size of Spool 6 is 
    estimated with no confidence to be 36,434,893 rows (1,603,135,292 
    bytes). The estimated time for this step is 9.11 seconds. 

    5) We do an all-AMPs RETRIEVE step from QA_US_MASTER.MVNDR_ITEM_STR 
    in view qa4_US_MASTER_VIEWS.mvndr_item_str by way of an all-rows 
    scan with a condition of ("(QA_US_MASTER.MVNDR_ITEM_STR in view 
    qa4_US_MASTER_VIEWS.mvndr_item_str.CURR_DSVC_TYP_CD = 3) AND 
    ((QA_US_MASTER.MVNDR_ITEM_STR in view 
    qa4_US_MASTER_VIEWS.mvndr_item_str.EFF_END_DT = DATE '9999-12-31') 
    AND ((QA_US_MASTER.MVNDR_ITEM_STR in view 
    qa4_US_MASTER_VIEWS.mvndr_item_str.ACTV_FLG = 'Y') AND 
    (QA_US_MASTER.MVNDR_ITEM_STR in view 
    qa4_US_MASTER_VIEWS.mvndr_item_str.OK_TO_ORD_FLG = 'Y')))") into 
    Spool 7 (all_amps) (compressed columns allowed) fanned out into 33 
    hash join partitions, which is redistributed by the hash code of (
    QA_US_MASTER.MVNDR_ITEM_STR.ITEM_ID, 
    QA_US_MASTER.MVNDR_ITEM_STR.STR_LOC_ID, 
    QA_US_MASTER.MVNDR_ITEM_STR.ITEM_STAT_CD, 
    QA_US_MASTER.MVNDR_ITEM_STR.ITEM_ID, 
    QA_US_MASTER.MVNDR_ITEM_STR.STR_LOC_ID) to all AMPs. The input 
    table will not be cached in memory, but it is eligible for 
    synchronized scanning. The size of Spool 7 is estimated with no 
    confidence to be 173,967,551 rows (5,914,896,734 bytes). The 
    estimated time for this step is 2 minutes and 23 seconds. 

    6) We do an all-AMPs JOIN step from Spool 6 (Last Use) by way of an 
    all-rows scan, which is joined to Spool 7 (Last Use) by way of an 
    all-rows scan. Spool 6 and Spool 7 are joined using a hash join 
    of 33 partitions, with a join condition of ("(STR_LOC_ID = 
    STR_LOC_ID) AND ((ITEM_STAT_CD = ITEM_STAT_CD) AND ((ITEM_ID = 
    ITEM_ID) AND ((ACTV_FLG = OK_TO_ORD_FLG) AND ((ACTV_FLG = ACTV_FLG) 
    AND ((EFF_END_DT = EFF_END_DT) AND ((ACTV_FLG = ACTV_FLG) AND 
    ((OK_TO_ORD_FLG = ACTV_FLG) AND ((ITEM_ID = ITEM_ID) AND 
    (STR_LOC_ID = LOC_ID)))))))))"). The result goes into Spool 2 
    (all_amps) (compressed columns allowed), which is built locally on 
    the AMPs. The size of Spool 2 is estimated with no confidence to 
    be 12,939,628 rows (336,430,328 bytes). The estimated time for 
    this step is 4.00 seconds. 

    7) We do an all-AMPs STAT FUNCTION step from Spool 2 by way of an 
    all-rows scan into Spool 10, which is redistributed by hash code 
    to all AMPs. The result rows are put into Spool 1 (group_amps), 
    which is built locally on the AMPs. This step is used to retrieve 
    the TOP 100 rows. Load distribution optimization is used. 
    If this step retrieves less than 100 rows, then execute step 8. 
    The size is estimated with no confidence to be 100 rows (3,200 
    bytes). 

    8) We do an all-AMPs STAT FUNCTION step from Spool 2 (Last Use) by 
    way of an all-rows scan into Spool 10 (Last Use), which is 
    redistributed by hash code to all AMPs. The result rows are put 
    into Spool 1 (group_amps), which is built locally on the AMPs. 
    This step is used to retrieve the TOP 100 rows. The size is 
    estimated with no confidence to be 100 rows (3,200 bytes). 

    9) Finally, we send out an END TRANSACTION step to all AMPs involved 
    in processing the request. 

-> The contents of Spool 1 are sent back to the user as the result of 
statement 1. 
+0

粘貼說明計劃和統計上的每個基表 – emaillenin

+0

什麼是整個查詢說明計劃? – emaillenin

+0

爲整個查詢添加解釋計劃 – Arvinth

回答

0

在查詢有沒有ORDER BY,所以你只是想100個隨機行?

在Teradata頂部完成完整的結果集已創建。你應該將頂進樣派生表:

select I.item_sku_nbr,L.loc_nbr,MIS.MVNDR_PRTY_ID from 
QA_US_MASTER_VIEWS.item I, 
qa4_US_MASTER_VIEWS.location L, 
(SELECT TOP 100 * FROM qa4_US_MASTER_VIEWS.item_str) IST, 
qa4_US_MASTER_VIEWS.mvndr_item_str MIS 
    where MIS.str_LOC_ID = L.loc_id and  
mis.str_loc_id = IST.str_loc_id and  
IST.str_loc_id = L.loc_id and 
MIS.ITEM_STAT_CD = IST.ITEM_STAT_CD and  
IST.ITEM_ID = I.ITEM_ID and  
MIS.ITEM_ID = IST.ITEM_ID  and  
I.ITEM_STAT_CD = 100   and 
IST.curr_rmeth_cd = 2   and 
MIS.curr_dsvc_typ_cd = 3  and 
MIS.OK_TO_ORD_FLG = 'Y' and   
MIS.EFF_END_DT = DATE '9999-12-31' and 
IST.EFF_END_DT = DATE '9999-12-31' and 
MIS.ACTV_FLG ='Y' and  
IST.ACTV_FLG ='Y' and I.ACTV_FLG='Y' 
+0

隨機行很好。但它顯示語法錯誤(SELECT TOP 100 * FROM qa4_US_MASTER_VIEWS.item_str IST),預期的標識符betwenn和 – Arvinth

+0

糟糕,我把括號放在錯誤的地方,別名缺失。編輯我的查詢 – dnoeth

+0

@dnoeth不會使用'sample 100'比'top 100'更快嗎? – 2014-02-10 14:05:12