Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SP Performance question

Author  Topic 

solent
Starting Member

33 Posts

Posted - 2012-08-15 : 10:12:16
Hello,

We have the below SP that when run it has the below performance.
Reads: 9492
CPU: 1633
Duration: 277ms

We run SQL Server 2008 R2 ENT. With 8 cores @ 3.GHz each and Memory 70GB

view_user count is @ 167 thousand rows
table_records count is @ 47 million rows
view_PR count is @ 1 million rows.

Are there any changes that can be done on the SP to boost the performance?

Any help is greatly appriciated.


BEGIN
SET NOCOUNT ON;

Select
t.sml,
round(100.0 * t.SVU /case
when ( t.SVU + t.LVU ) = null then 1.0
when ( t.SVU + t.LVU ) = 0 then 1.0
else t.SVU + t.LVU
end, 1) as SVUPercent,
round(100.0 * t.LVU/ case
when t.SVU + t.LVU = null then 1.0
when t.SVU + t.LVU = 0 then 1.0
else t.SVU + t.LVU
end,1) as LVUPercent,
round(100.0 * t.VU / case
when Sum(t.VU) over () = null then 1.0
when Sum(t.VU) over () = 0 then 1.0
else Sum(t.VU) over ()
end,1) as VUPercent,
round(100.0 * t.TTR / case
when Sum(t.TTR) over () = null then 1.0
when Sum(t.TTR) over () = 1 then 1.0
else Sum(t.TTR) over ()
end,1) as TTRPercent
from
(
SELECT
s.sml,
SUM(
case when t.CMD = 0 then
CASE WHEN s.MMode = 0 THEN ( s.CS / s.MD )
WHEN s.MMode = 1 THEN ( s.CS * t.[OP] / s.MD )
WHEN s.MMode = 2 THEN ( s.MI / s.MD )
END * ( t.VOL / 100.0 ) * ps.RT
else 0.0
end
) AS LVU,

SUM(
case when t.CMD = 1 then
CASE WHEN s.MMode = 0 THEN ( s.CS / s.MD )
WHEN s.MMode = 1 THEN ( s.CS * t.[OP] / s.MD )
WHEN s.MMode = 2 THEN ( s.MI / s.MD )
END * ( t.VOL / 100.0 ) * ps.RT
else 0.0
end
) AS SVU,

SUM(
CASE WHEN s.MMode = 0 THEN ( s.CS / s.MD )
WHEN s.MMode = 1 THEN ( s.CS * t.[OP] / s.MD )
WHEN s.MMode = 2 THEN ( s.MI / s.MD )
END * ( t.VOL / 100.0 ) * ps.RT
) AS VU,

COUNT(t.t_id) as Total_T

FROM [dbo].[view_user] u (NOLOCK)
JOIN [dbo].[table_records] t (NOLOCK)
ON [t].[U_FID] = [u].[U_ID]
JOIN [dbo].[table_cs] s (NOLOCK)
ON [s].[sym_ID] = [t].[sym_FID]
LEFT JOIN [dbo].[view_PR] ps (NOLOCK)
ON [ps].[Sym] = [s].[MAC] + 'AAA'
AND [ps].[Date] = CAST([t].[OTime] AS DATE)
WHERE
[t].[CMD] IN (0, 1)
AND t.CTime = '1970-01-01'
AND s.MD > 0
group by s.sml
)t
OPTION ( OPTIMIZE FOR UNKNOWN )
END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-15 : 10:27:47
one small issue i noticed is you're using conditions like =null inside case. please keep in mind that this wont work under default ANSI NULL settings. you should be using IS NULL instead

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -