开发者

Strange behavior of stored procedure runtime

开发者 https://www.devze.com 2022-12-07 17:55 出处:网络
We are facing a performance issue while executing a stored procedure. It usually takes between 10-15 minutes to run, but sometimes it takes up to more than 30 minutes to execute.

We are facing a performance issue while executing a stored procedure. It usually takes between 10-15 minutes to run, but sometimes it takes up to more than 30 minutes to execute.

We captured visualize plan execute files for the Normal run and Long run cases.

By checking the visualized plan we came to know that, one particular Insert block of code takes extra time in the long run. And by checking "EXPLAIN PLAN FOR SQL PLAN CACHE ENTRY <plan_id> " the table we found that the order of execution differs in the long run.

This is the block which takes extra time to run sometimes.

INSERT INTO #TMP_DATI_SALDI_LORDI_BASE (
                 "COD_SCENARIO","COD_PERIODO","COD_CONTO","COD_DEST1","COD_DEST2","COD_DEST3","COD_DEST4","COD_DEST5"
                ,"IMPORTO","COD_VALUTA","IMPORTO_VALUTA_ORIGINARIA","COD_VALUTA_ORIGINARIA","NOTE"
            )
            (   SELECT
                     SCEN_P.SCENARIO
                    ,SCEN_P.PERIOD
                    ,ACCOUT_ADJ.ATTRIBUTO1 AS "COD_CONTO"
                    ,DATAS_rev.COD_DEST1
                    ,DATAS_rev.COD_DEST2
                    ,DATAS_rev.COD_DEST3
                    ,__typed_NString__($1, 50)
                    ,'RPT_NON'
                    ,SUM(
                            CASE WHEN INFO.INCOT = 'FOB' THEN
                                CASE ACCOUT_rev.ATTRIBUTO1 WHEN 'CalcInsurance' THEN
                                    0
                                ELSE
                                    DATAS_rev.IMPORTO
                                END
                            ELSE
                                DATAS_rev.IMPORTO
                            END
                            * (DATAS_ADJ.IMPORTO - DATAS.IMPORTO)
                        )
                    ,DATAS_rev.COD_VALUTA
                    ,SUM(
                            CASE WHEN INFO.INCOT = 'FOB' THEN
                                CASE ACCOUT_rev.ATTRIBUTO1 WHEN 'CalcInsurance' THEN
                                    0
                                ELSE
                                    DATAS_rev.IMPORTO_VALUTA_ORIGINARIA
                                END
                            ELSE
                                DATAS_rev.IMPORTO_VALUTA_ORIGINARIA
                            END
                            * (DATAS_ADJ.IMPORTO_VALUTA_ORIGINARIA - DATAS.IMPORTO_VALUTA_ORIGINARIA)
                        )
                    ,DATAS_rev.COD_VALUTA_ORIGINARIA
                    ,'CPM_SP_CACL_FY_E3 Parts Option ADJ'
                 FROM #TMP_TAGERT_SCEN_P SCEN_P
                 
                INNER JOIN #TMP_DATI_SALDI_LORDI_BASE DATAS_rev
                   ON DATAS_rev.COD_SCE开发者_Python百科NARIO        = SCEN_P.SCENARIO
                  AND DATAS_rev.COD_PERIODO         = SCEN_P.PERIOD
                  AND LEFT(DATAS_rev.COD_DEST3, 1)  = 'O'
                  
                INNER JOIN CONTO ACCOUT_rev
                   ON ACCOUT_rev.COD_CONTO          = DATAS_rev.COD_CONTO
                  AND ACCOUT_rev.ATTRIBUTO1 IN ('CalcFOB','CalcInsurance')   --FOB,Insurance(Ocean freight is Nothing by Option)
                  
                INNER JOIN #DSL DATAS
                   ON DATAS.COD_SCENARIO            = 'LAUNCH'
                  AND DATAS.COD_PERIODO             = 12
                  AND DATAS.COD_DEST1               = 'NC'
                  AND DATAS.COD_DEST2               = 'NC'
                  AND DATAS.COD_DEST3               = 'F001'
                  AND DATAS.COD_DEST4               = DATAS_rev.COD_DEST4
                  AND DATAS.COD_DEST5               = 'INP'
                  
                INNER JOIN CONTO ACCOUT
                   ON ACCOUT.COD_CONTO              = DATAS.COD_CONTO
                  AND ACCOUT.ATTRIBUTO2             = 'E3'
                  
                INNER JOIN CONTO ACCOUT_ADJ
                   ON ACCOUT_ADJ.ATTRIBUTO3         = DATAS.COD_CONTO
                  AND ACCOUT_ADJ.ATTRIBUTO2         = 'HE3'
                  
                  
                INNER JOIN #DSL DATAS_ADJ
                   ON LEFT(DATAS_ADJ.COD_SCENARIO,4) = LEFT(SCEN_P.SCENARIO,4)
                  AND DATAS_ADJ.COD_PERIODO         = 12
                  AND DATAS_ADJ.COD_DEST1           = DATAS.COD_DEST1
                  AND DATAS_ADJ.COD_DEST2           = DATAS.COD_DEST2
                  AND DATAS_ADJ.COD_DEST3           = DATAS.COD_DEST3
                  AND DATAS_ADJ.COD_DEST4           = DATAS.COD_DEST4
                  AND DATAS_ADJ.COD_DEST5           = DATAS.COD_DEST5
                  AND DATAS_ADJ.COD_CONTO           = ACCOUT_ADJ.COD_CONTO

                 LEFT OUTER JOIN #TMP_KDPWT_INCOTERMS INFO
                   ON INFO.P_CODE                   = DATAS.COD_DEST4
                   
                   
                GROUP BY
                     SCEN_P.SCENARIO,SCEN_P.PERIOD,ACCOUT_ADJ.ATTRIBUTO1,DATAS_rev.COD_DEST1,DATAS_rev.COD_DEST2
                    ,DATAS_rev.COD_DEST3, DATAS.COD_DEST4,DATAS_rev.COD_VALUTA,DATAS_rev.COD_VALUTA_ORIGINARIA,INFO.INCOT
            )

I will share the order of execution details also for normal and long run case.

Strange behavior of stored procedure runtime

Strange behavior of stored procedure runtime

Could someone please help us to overcome this issue? And also we don't know how to fix the order of the join execution. Is there any way to fix the join order execution, Please guide us.

Thanks in advance

Vinothkumar

0

精彩评论

暂无评论...
验证码 换一张
取 消