Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

¿Alternatives to increase the performance of this query? - response (9) by AshishPatil

$
0
0

Hi ,
  We are getting different behaviour while firing same query multiple times on database. Every time its takes different time to execute. First it took 2 min then 5 min then 15 min. its increasing. Not getting why this is happening. Can anyone pls help to understand and tune it properly ?
Please find the query and explain plan below.
Query:
 

SELECT DISTINCT 0 AS c1 , D1.c2 AS c2 , D1.c3 AS c3 , D1.c4 AS c4 ,

D1.c5 AS c5 , D1.c6 AS c6 , D1.c7 AS c7 , D1.c8 AS c8 , D1.c9 AS c9 ,

D1.c10 AS c10 , D1.c11 AS c11 , D1.c12 AS c12 , D1.c13 AS c13 ,

D1.c1 AS c14 , 0 AS c15 , 0 AS c16 , D1.c14 AS c17 

FROM ( 

SELECT SUM ( T57657."ITEM_DTL_AMT" ) AS c1 , 

CASE WHEN T12446."PARTNER_BANK" IN ( 'IL' , 'NIC' , 'RS' , 'UIIC' ) THEN 'TMI' 

ELSE 'Others' 

END AS c2 , T45548."DAY_DT" AS c3 , T37817."X_SLS_AREA" AS c4 ,

T37817."NAME" AS c5 , T37817."X_SLS_REGION" AS c6 , T12468."TOP_LVL_PROD_NAME" AS c7 ,

T12446."ASSET_NUM" AS c8 , T12446."PREMIUM" AS c9 , T12446."PREMIUM_DT" AS c10 ,

T12446."PARTNER_BRANCH" AS c11 , T12446."PURCHASE_DT" AS c12 ,

T12446."INTEREST_RATE" AS c13 , T45548."ROW_WID" AS c14 

FROM

"W_LOV_D" T55657 , 

"W_LOV_D" T55645 ,

 "W_DAY_D" T45548 ,

  "W_INT_ORG_D" T37817 ,

"W_ASSET_D" T12446 , 

"W_PRODUCT_D" T12467 , 

"W_PRODUCT_DH" T12468 ,

"WC_INVOICE_ITEM_F" T57657 ,

"W_INVOICE_F" T112407 

WHERE ( T45548."ROW_WID" = T57657."INVC_DT_WID" 

AND T37817."ROW_WID" = T57657."PR_VIS_ORG_WID" 

AND T12446."ROW_WID" = T57657."ASSET_WID" 

AND T12467."ROW_WID" = T12468."ROW_WID" 

AND T12467."ROW_WID" = T57657."PROD_WID" 

AND T55657."ROW_WID" = T57657."INVC_STATUS_WID" 

AND T55645."ROW_WID" = T57657."INVC_TYPE_WID" 

AND T55645."ROW_WID" = T112407."INVC_TYPE_CD_WID" 

AND T12467."PRODUCT_TYPE_DESC" = 'Vehicle' 

AND T55645."R_TYPE" = 'FS_INVOICE_TYPE' 

AND T55645."VAL" = 'Standard' 

AND T55657."ROW_WID" = T112407."STATUS_CD_WID" 

AND T55657."R_TYPE" = 'PS_SUBCONTRACTOR_STATUS' 

AND T55657."VAL" = 'New' 

AND T57657."INVOICE_WID" = T112407."ROW_WID" 

AND T12446."ASSET_NUM"<> 'Unspecified' 

AND ( T12467."X_BU_UNIT" = 'TM' 

OR T12467."X_BU_UNIT" = 'TMPC' ) 

AND T12446."PARTNER_BANK" IS NOT NULL 

AND T45548."DAY_DT" BETWEEN TIMESTAMP'2013-02-01 00:00:00' 

AND TIMESTAMP'2013-02-28 00:00:00' ) 

GROUP BY T12446."ASSET_NUM" , T12446."INTEREST_RATE" , T12446."PREMIUM" ,

T12446."PREMIUM_DT" , T12446."PURCHASE_DT" , T12446."PARTNER_BRANCH" ,

T12468."TOP_LVL_PROD_NAME" , T37817."NAME" , T37817."X_SLS_AREA" ,

T37817."X_SLS_REGION" , T45548."ROW_WID" , T45548."DAY_DT" ,

CASE 

WHEN T12446."PARTNER_BANK" IN ( 'IL' , 'NIC' , 'RS' , 'UIIC' ) THEN 'TMI' 

ELSE 'Others' 

END ) D1 

 

 

 

 

Explain Plan:
 

1) First, we lock a distinct OLAP_DEV."pseudo table" for read on a

     RowHash to prevent global deadlock for OLAP_DEV.T12468. 

  2) Next, we lock a distinct OLAP_DEV."pseudo table" for read on a

     RowHash to prevent global deadlock for OLAP_DEV.T12467. 

  3) We lock a distinct OLAP_DEV."pseudo table" for read on a RowHash

     to prevent global deadlock for OLAP_DEV.T112407. 

  4) We lock a distinct OLAP_DEV."pseudo table" for read on a RowHash

     to prevent global deadlock for OLAP_DEV.T37817. 

  5) We lock a distinct OLAP_DEV."pseudo table" for read on a RowHash

     to prevent global deadlock for OLAP_DEV.T45548. 

  6) We lock a distinct OLAP_DEV."pseudo table" for read on a RowHash

     to prevent global deadlock for OLAP_DEV.T12446. 

  7) We lock a distinct OLAP_DEV."pseudo table" for read on a RowHash

     to prevent global deadlock for OLAP_DEV.T57657. 

  8) We lock OLAP_DEV.T12468 for read, we lock OLAP_DEV.T12467 for read,

     we lock OLAP_DEV.T112407 for read, we lock OLAP_DEV.T37817 for

     read, we lock OLAP_DEV.T45548 for read, we lock OLAP_DEV.T12446

     for read, and we lock OLAP_DEV.T57657 for read. 

  9) We do a BMSMS (bit map set manipulation) step that builds a bit

     map for OLAP_DEV.T12467 by way of a traversal of index # 24 which

     is placed in Spool 5.  The estimated time for this step is 0.00

     seconds. 

 10) We execute the following steps in parallel. 

      1) We do an all-AMPs RETRIEVE step from OLAP_DEV.T12467 by way of

         index # 16 "OLAP_DEV.T12467.PRODUCT_TYPE_DESC = 'Vehicle'" and

         the bit map in Spool 5 (Last Use) with a residual condition of

         ("((OLAP_DEV.T12467.X_BU_UNIT = 'TMPC') OR

         (OLAP_DEV.T12467.X_BU_UNIT = 'TM')) AND

         (OLAP_DEV.T12467.PRODUCT_TYPE_DESC = 'Vehicle')") into Spool 6

         (all_amps), which is built locally on the AMPs.  Then we do a

         SORT to order Spool 6 by the hash code of (

         OLAP_DEV.T12467.ROW_WID).  The size of Spool 6 is estimated

         with low confidence to be 18,214 rows (382,494 bytes).  The

         estimated time for this step is 2.83 seconds. 

      2) We do a two-AMP JOIN step from OLAP_DEV.T55645 by way of

         unique index # 8 "OLAP_DEV.T55645.R_TYPE = 'FS_INVOICE_TYPE',

         OLAP_DEV.T55645.VAL = 'Standard'" with a residual condition of

         ("(OLAP_DEV.T55645.R_TYPE = 'FS_INVOICE_TYPE') AND

         (OLAP_DEV.T55645.VAL = 'Standard')"), which is joined to

         OLAP_DEV.T55657 by way of unique index # 8

         "OLAP_DEV.T55657.R_TYPE = 'PS_SUBCONTRACTOR_STATUS',

         OLAP_DEV.T55657.VAL = 'New'" with no residual conditions. 

         OLAP_DEV.T55645 and OLAP_DEV.T55657 are joined using a nested

         join, with a join condition of ("(1=1)").  The result goes

         into Spool 7 (all_amps), which is duplicated on all AMPs. 

         Then we do a SORT to order Spool 7 by the hash code of (

         OLAP_DEV.T55657.ROW_WID).  The size of Spool 7 is estimated

         with high confidence to be 24 rows (696 bytes).  The estimated

         time for this step is 0.00 seconds. 

 11) We do an all-AMPs JOIN step from Spool 7 (Last Use) by way of an

     all-rows scan, which is joined to OLAP_DEV.T112407 by way of a

     traversal of index # 16 without accessing the base table

     extracting row ids only.  Spool 7 and OLAP_DEV.T112407 are joined

     using a nested join, with a join condition of ("ROW_WID =

     OLAP_DEV.T112407.STATUS_CD_WID").  The input table

     OLAP_DEV.T112407 will not be cached in memory.  The result goes

     into Spool 8 (all_amps), which is built locally on the AMPs.  Then

     we do a SORT to order Spool 8 by field Id 1.  The size of Spool 8

     is estimated with low confidence to be 9,615 rows (374,985 bytes). 

     The estimated time for this step is 0.09 seconds. 

 12) We do an all-AMPs JOIN step from Spool 8 (Last Use) by way of an

     all-rows scan, which is joined to OLAP_DEV.T112407 by way of an

     all-rows scan with a condition of ("NOT

     (OLAP_DEV.T112407.STATUS_CD_WID IS NULL)").  Spool 8 and

     OLAP_DEV.T112407 are joined using a row id join, with a join

     condition of ("ROW_WID = OLAP_DEV.T112407.INVC_TYPE_CD_WID").  The

     input table OLAP_DEV.T112407 will not be cached in memory.  The

     result goes into Spool 9 (all_amps), which is duplicated on all

     AMPs.  Then we do a SORT to order Spool 9 by the hash code of (

     OLAP_DEV.T112407.ROW_WID).  The size of Spool 9 is estimated with

     low confidence to be 230,760 rows (12,230,280 bytes).  The

     estimated time for this step is 1 minute and 21 seconds. 

 13) We execute the following steps in parallel. 

      1) We do an all-AMPs JOIN step from Spool 9 (Last Use) by way of

         an all-rows scan, which is joined to OLAP_DEV.T57657 by way of

         a traversal of index # 12 without accessing the base table

         extracting row ids only.  Spool 9 and OLAP_DEV.T57657 are

         joined using a nested join, with a join condition of (

         "OLAP_DEV.T57657.INVOICE_WID = ROW_WID").  The input table

         OLAP_DEV.T57657 will not be cached in memory.  The result goes

         into Spool 10 (all_amps), which is built locally on the AMPs. 

         Then we do a SORT to order Spool 10 by field Id 1.  The size

         of Spool 10 is estimated with low confidence to be 9,679 rows

         (532,345 bytes).  The estimated time for this step is 19.77

         seconds. 

      2) We do an all-AMPs RETRIEVE step from OLAP_DEV.T45548 by way of

         a traversal of index # 8 extracting row ids only with a

         residual condition of ("(OLAP_DEV.T45548.DAY_DT >= TIMESTAMP

         '2013-02-01 00:00:00.000000') AND (OLAP_DEV.T45548.DAY_DT <=

         TIMESTAMP '2013-02-28 00:00:00.000000')") into Spool 4

         (all_amps), which is built locally on the AMPs.  Then we do a

         SORT to order Spool 4 by row id eliminating duplicate rows. 

         The size of Spool 4 is estimated with high confidence to be 4

         rows.  The estimated time for this step is 0.07 seconds. 

 14) We do an all-AMPs JOIN step from Spool 10 (Last Use) by way of an

     all-rows scan, which is joined to OLAP_DEV.T57657 by way of an

     all-rows scan with a condition of ("NOT

     (OLAP_DEV.T57657.INVC_DT_WID IS NULL)").  Spool 10 and

     OLAP_DEV.T57657 are joined using a row id join, with a join

     condition of ("(ROW_WID = OLAP_DEV.T57657.INVC_TYPE_WID) AND

     ((INVC_TYPE_CD_WID = OLAP_DEV.T57657.INVC_TYPE_WID) AND

     ((STATUS_CD_WID = OLAP_DEV.T57657.INVC_STATUS_WID) AND (ROW_WID =

     OLAP_DEV.T57657.INVC_STATUS_WID )))").  The input table

     OLAP_DEV.T57657 will not be cached in memory.  The result goes

     into Spool 11 (all_amps), which is redistributed by the hash code

     of (OLAP_DEV.T57657.INVC_DT_WID) to all AMPs.  Then we do a SORT

     to order Spool 11 by row hash.  The size of Spool 11 is estimated

     with low confidence to be 9,679 rows (590,419 bytes).  The

     estimated time for this step is 43.67 seconds. 

 15) We execute the following steps in parallel. 

      1) We do an all-AMPs JOIN step from OLAP_DEV.T45548 by way of row

         ids from Spool 4 (Last Use) with no residual conditions, which

         is joined to Spool 11 (Last Use) by way of a RowHash match

         scan.  OLAP_DEV.T45548 and Spool 11 are joined using a merge

         join, with a join condition of ("OLAP_DEV.T45548.ROW_WID =

         INVC_DT_WID").  The result goes into Spool 12 (all_amps),

         which is redistributed by the hash code of (

         OLAP_DEV.T57657.PR_VIS_ORG_WID) to all AMPs.  Then we do a

         SORT to order Spool 12 by row hash.  The size of Spool 12 is

         estimated with low confidence to be 272 rows (19,312 bytes). 

         The estimated time for this step is 0.08 seconds. 

      2) We do an all-AMPs JOIN step from OLAP_DEV.T12468 by way of a

         RowHash match scan with no residual conditions, which is

         joined to Spool 6 (Last Use) by way of a RowHash match scan. 

         OLAP_DEV.T12468 and Spool 6 are joined using a merge join,

         with a join condition of ("ROW_WID = OLAP_DEV.T12468.ROW_WID"). 

         The result goes into Spool 13 (all_amps), which is built

         locally on the AMPs.  Then we do a SORT to order Spool 13 by

         the hash code of (OLAP_DEV.T12467.ROW_WID,

         OLAP_DEV.T12468.ROW_WID).  The size of Spool 13 is estimated

         with low confidence to be 18,214 rows (1,165,696 bytes).  The

         estimated time for this step is 0.44 seconds. 

 16) We do an all-AMPs JOIN step from OLAP_DEV.T37817 by way of a

     RowHash match scan with no residual conditions, which is joined to

     Spool 12 (Last Use) by way of a RowHash match scan. 

     OLAP_DEV.T37817 and Spool 12 are joined using a merge join, with a

     join condition of ("OLAP_DEV.T37817.ROW_WID = PR_VIS_ORG_WID"). 

     The result goes into Spool 14 (all_amps), which is duplicated on

     all AMPs.  Then we do a SORT to order Spool 14 by the hash code of

     (OLAP_DEV.T57657.PROD_WID, OLAP_DEV.T57657.PROD_WID).  The size of

     Spool 14 is estimated with low confidence to be 6,528 rows (

     842,112 bytes).  The estimated time for this step is 0.12 seconds. 

 17) We do an all-AMPs JOIN step from Spool 13 (Last Use) by way of a

     RowHash match scan, which is joined to Spool 14 (Last Use) by way

     of a RowHash match scan.  Spool 13 and Spool 14 are joined using a

     merge join, with a join condition of ("(ROW_WID = PROD_WID) AND

     (PROD_WID = ROW_WID)").  The result goes into Spool 15 (all_amps),

     which is redistributed by the hash code of (

     OLAP_DEV.T57657.ASSET_WID) to all AMPs.  Then we do a SORT to

     order Spool 15 by row hash.  The size of Spool 15 is estimated

     with low confidence to be 272 rows (42,160 bytes).  The estimated

     time for this step is 0.03 seconds. 

 18) We do an all-AMPs JOIN step from OLAP_DEV.T12446 by way of a

     RowHash match scan with a condition of ("(NOT

     (OLAP_DEV.T12446.PARTNER_BANK IS NULL )) AND

     ((OLAP_DEV.T12446.ASSET_NUM > 'Unspecified') OR

     (OLAP_DEV.T12446.ASSET_NUM < 'Unspecified'))"), which is joined to

     Spool 15 (Last Use) by way of a RowHash match scan. 

     OLAP_DEV.T12446 and Spool 15 are joined using a merge join, with a

     join condition of ("OLAP_DEV.T12446.ROW_WID = ASSET_WID").  The

     input table OLAP_DEV.T12446 will not be cached in memory, but it

     is eligible for synchronized scanning.  The result goes into Spool

     3 (all_amps), which is built locally on the AMPs.  The size of

     Spool 3 is estimated with low confidence to be 272 rows (73,984

     bytes).  The estimated time for this step is 0.20 seconds. 

 19) We do an all-AMPs SUM step to aggregate from Spool 3 (Last Use) by

     way of an all-rows scan , grouping by field1 (

     OLAP_DEV.T12446.ASSET_NUM ,OLAP_DEV.T12446.INTEREST_RATE

     ,OLAP_DEV.T12446.PREMIUM ,OLAP_DEV.T12446.PREMIUM_DT

     ,OLAP_DEV.T12446.PURCHASE_DT ,OLAP_DEV.T12446.PARTNER_BRANCH

     ,OLAP_DEV.T12468.TOP_LVL_PROD_NAME ,OLAP_DEV.T37817.NAME

     ,OLAP_DEV.T37817.X_SLS_AREA ,OLAP_DEV.T37817.X_SLS_REGION

     ,OLAP_DEV.T45548.ROW_WID ,OLAP_DEV.T45548.DAY_DT ,( CASE WHEN

     ((OLAP_DEV.T12446.PARTNER_BANK = 'IL') OR

     ((OLAP_DEV.T12446.PARTNER_BANK = 'NIC') OR

     ((OLAP_DEV.T12446.PARTNER_BANK = 'RS') OR

     (OLAP_DEV.T12446.PARTNER_BANK = 'UIIC')))) THEN ('TMI') ELSE

     ('Others') END)).  Aggregate Intermediate Results are computed

     globally, then placed in Spool 16.  The size of Spool 16 is

     estimated with low confidence to be 272 rows (214,880 bytes).  The

     estimated time for this step is 0.05 seconds. 

 20) We do an all-AMPs RETRIEVE step from Spool 16 (Last Use) by way of

     an all-rows scan into Spool 1 (used to materialize view, derived

     table or table function D1) (all_amps), which is built locally on

     the AMPs.  The size of Spool 1 is estimated with low confidence to

     be 272 rows (72,352 bytes).  The estimated time for this step is

     0.03 seconds. 

 21) We do an all-AMPs RETRIEVE step from Spool 1 (Last Use) by way of

     an all-rows scan into Spool 18 (all_amps), which is built locally

     on the AMPs.  The size of Spool 18 is estimated with low

     confidence to be 272 rows (85,680 bytes).  The estimated time for

     this step is 0.03 seconds. 

 22) Finally, we send out an END TRANSACTION step to all AMPs involved

     in processing the request.

  -> The contents of Spool 18 are sent back to the user as the result

     of statement 1.  The total estimated time is 2 minutes and 28

     seconds. 

 

Also what different alternatives we can think of while tuning database and queries other than distribution, indexing and stats ?

 
Thanks in advance.
Ashish Patil
 
 


Viewing all articles
Browse latest Browse all 27759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>