More issues during development | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

More issues during development

Hello everybody,<br /><br />I have a query which updates the target table from a staging area. <br /><br />Query:<br />UPDATE [EDGE].[dbo].[tblBusnPartEmp]<br />SET <br />EmpDeceasedIndCd=<br />CASE<br />WHEN B.EmpDynastyCd=1<br />THEN 1<br />ELSE 2<br />END<br />,EmpDynastyCd=<br />CASE WHEN B.EmpDynastyCd=1 THEN 0<br />ELSE B.EmpDynastyCd<br />END<br />,UpdateDt=GetDate()<br />,UpdateId=1<br />,AppId=’OD2-Cleanup'<br />,FunctionId=60606<br />FROM <br /> [EDGE_Staging].[dbo].[Edge_CusttblBusnPartEmpDynastyCd] B<br />INNER JOIN<br />[EDGE].[dbo].[tblBusnPartEmp] A <br />ON<br />A.BusnPartEmpId = B.BusnPartEmpId<br />WHERE B.ConvStatus=0 <br /><br />Execution Plan:<br /> |–Table Update(OBJECT<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[EDGE].[dbo].[tblBusnPartEmp]), SET<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[tblBusnPartEmp].[EmpDeceasedIndCd]=RaiseIfNull([Expr1004]), [tblBusnPartEmp].[FunctionId]=RaiseIfNull(60606), [tblBusnPartEmp].[UpdateDt]=RaiseIfNull(getdate()), [tblBusnPartEmp].[UpdateId]=Ra 10 2 1 Table Update Update OBJECT<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[EDGE].[dbo].[tblBusnPartEmp]), SET<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[tblBusnPartEmp].[EmpDeceasedIndCd]=RaiseIfNull([Expr1004]), [tblBusnPartEmp].[FunctionId]=RaiseIfNull(60606), [tblBusnPartEmp].[UpdateDt]=RaiseIfNull(getdate()), [tblBusnPartEmp].[UpdateId]=RaiseIfNull(1), [tbl NULL 749539.94 1.0754779E-2 0.74953991 21 48.861309 NULL NULL PLAN_ROW 0 1.0<br /> |–Compute Scalar(DEFINE<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Expr1004]=If (<B>.[EmpDynastyCd]=1) then 1 else 2, [Expr1005]=If (<B>.[EmpDynastyCd]=1) then 0 else <B>.[EmpDynastyCd], [Expr1016]=getdate())) 10 3 2 Compute Scalar Compute Scalar DEFINE<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Expr1004]=If (<B>.[EmpDynastyCd]=1) then 1 else 2, [Expr1005]=If (<B>.[EmpDynastyCd]=1) then 0 else <B>.[EmpDynastyCd], [Expr1016]=getdate()) [Expr1004]=If (<B>.[EmpDynastyCd]=1) then 1 else 2, [Expr1005]=If (<B>.[EmpDynastyCd]=1) then 0 else <B>.[EmpDynastyCd], [Expr1016]=getdate() 749539.94 0.0 7.4953996E-2 91 48.101013 [Bmk1000], [Expr1004], [Expr1005], [Expr1016], [Expr1007], [Expr1008], [Expr1009] NULL PLAN_ROW 0 1.0<br /> |–Top(ROWCOUNT est 0) 10 4 3 Top Top NULL NULL 749539.94 0.0 7.4953996E-2 19 48.026062 [Bmk1000], <B>.[EmpDynastyCd] NULL PLAN_ROW 0 1.0<br /> |–Hash Match(Aggregate, HASH<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Bmk1000]), RESIDUAL<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Bmk1000]=[Bmk1000]) DEFINE<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ /><B>.[EmpDynastyCd]=ANY(<B>.[EmpDynastyCd]))) 10 5 4 Hash Match Aggregate HASH<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Bmk1000]), RESIDUAL<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Bmk1000]=[Bmk1000]) <B>.[EmpDynastyCd]=ANY(<B>.[EmpDynastyCd]) 749539.94 15.852559 19.073994 19 47.951107 [Bmk1000], <B>.[EmpDynastyCd] NULL PLAN_ROW 0 1.0<br /> |–Merge Join(Inner Join, MERGE<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[A].[BusnPartEmpId])=(<B>.[BusnPartEmpId]), RESIDUAL<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ /><B>.[BusnPartEmpId]=[A].[BusnPartEmpId])) 10 6 5 Merge Join Inner Join MERGE<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[A].[BusnPartEmpId])=(<B>.[BusnPartEmpId]), RESIDUAL<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ /><B>.[BusnPartEmpId]=[A].[BusnPartEmpId]) NULL 749539.94 0.0 4.6337261 27 13.024555 [Bmk1000], <B>.[EmpDynastyCd] NULL PLAN_ROW 0 1.0<br /> |–Index Scan(OBJECT<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[EDGE].[dbo].[tblBusnPartEmp].[XPKBusnPartEmp] AS [A]), ORDERED FORWARD) 10 7 6 Index Scan Index Scan OBJECT<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[EDGE].[dbo].[tblBusnPartEmp].[XPKBusnPartEmp] AS [A]), ORDERED FORWARD [Bmk1000], [A].[BusnPartEmpId] 1114430.0 1.5805415 1.2259516 19 2.806493 [Bmk1000], [A].[BusnPartEmpId] NULL PLAN_ROW 0 1.0<br /> |–Clustered Index Seek(OBJECT<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Edge_Staging].[dbo].[Edge_CusttblBusnPartEmpDynastyCd].[IX_Edge_CusttblBusnPartEmpDynastyCd] AS <B>), SEEK<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ /><B>.[ConvStatus]=0) ORDERED FORWARD) 10 8 6 Clustered Index Seek Clustered Index Seek OBJECT<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />[Edge_Staging].[dbo].[Edge_CusttblBusnPartEmpDynastyCd].[IX_Edge_CusttblBusnPartEmpDynastyCd] AS <B>), SEEK<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ /><B>.[ConvStatus]=0) ORDERED FORWARD <B>.[BusnPartEmpId], <B>.[EmpDynastyCd] 957792.0 4.5278101 1.0565231 42 5.5843329 <B>.[BusnPartEmpId], <B>.[EmpDynastyCd] NULL PLAN_ROW 0 1.0<br /><br /><br />I tried tweaking with execution plan as best possible, but still I have issues running the query to its end. I am unable to avoid hash join, which is the one taking 71% of query execution time.<br /><br />Please help if this query could be rewritten or any advises is a welcome for me. I have been struggling with this for past 2 days.<br /><br />I can’t add any indexes to the target tables, the only playing could be done on table in staging area.<br /><br />TIA.<br /><br /><br />RoyalSher.<br />*********<br />The world is the great gymnasium where we come to make ourselves strong.
Your query looks fine to me. So I don’t think a rewrite would make it more efficient. Not sure if this also works with UPDATEs, but you can specify a JOIN hint like INNER LOOP JOIN to force a certain JOIN type. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Thanks for the quick look thro’ Frank. I tried with the option you have given, and still its running for nearly half hour. I suspect a Hash Join in the query which is taking 71% of time based on execution plan. Is there any other way for me to change the query so that Hash Join is not used. RoyalSher.
*********
The world is the great gymnasium where we come to make ourselves strong.
]]>