| Author |
Topic |
|
ramu143
Yak Posting Veteran
64 Posts |
Posted - 2008-05-21 : 05:40:39
|
| executing this procedure taking time please solve it for less time any modificationsSET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GO/****** Object: Stored Procedure dbo.r_routeGetCache2 Script Date: 5/21/2008 3:07:05 PM ******/if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[r_routeGetCache2]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[r_routeGetCache2]GO/* --------------- Upgrade Version of r_routeGetCache1 to Implement Grade By N Mohaed 2005 - 12 - 12 ---------------- */ CREATE procedure r_routeGetCache2 @pLongest varchar(32), @pLongestCls int, @pDate datetime, @pSrcInt varchar(7), @pSrcIntGroup varchar(64), @pSrcIntDom varchar(64), @routeclass int=0 , @pCLI varchar(32)='', @pOperatorGroup int = 0 , @isgrade int=0, @pRouteName varchar(32) = '' as begin declare @pc varchar(2) declare @dd int declare @hh int declare @mm int set @pc=left(@pLongest,2) set @dd=1+(@@datefirst+datepart(dw,@pDate)-2)%7 --select @hh=(datepart(hh, @pDate)-timezone) from r_info set @hh=(datepart(hh, @pDate)-0) set @mm=datepart(mi, @pDate) set nocount on --- Azam select top 1 @routeclass = routecls from r_interface where [group] = @pSrcIntGroup and state='I' if @routeclass is null set @routeclass=0 --- End --insert CREATE TABLE #operator_selected ( [routecls] [int] NOT NULL , [oprId] [int] NOT NULL , [cls] [varchar] (1) NOT NULL , [pc] [varchar] (2) NOT NULL ) --CREATE UNIQUE CLUSTERED INDEX [idx1] ON --[dbo].[#operator_selected]([routecls], [oprId], [cls], [pc]) ON [PRIMARY] insert into #operator_selected(routecls,oprid,cls,pc) select x.routecls,x.oprid,x.cls,x.pc from r20_route_timecls x (nolock), r_TimeCls y with (nolock), r_interface tit with (nolock), r_timecode tco with (nolock), r_daycode dco with (nolock) where x.routecls=0 and tit.id = x.oprid and tit.state = 'I' and y.tintid =x.oprid and y.cls=x.cls and y.dc=dco.id and y.tc=tco.id and y.sc=0 and @dd between dco.d1 and dco.d2 and ((24+@hh+isnull(tit.prefixcls,0))%24) * 100 + @mm between tco.h1 and tco.h2-1 and x.pc=@pc CREATE TABLE #timecls_selected ( [routecls] [int] NOT NULL , [oprId] [int] NOT NULL , [pc] [varchar] (2) NOT NULL , [prefixcode] [varchar] (50) NOT NULL , cnt int, clsA int, clsP int, clsO int, clsW int, [cls] [varchar] (1) NOT NULL ) insert into #timecls_selected(routecls,oprid,pc,prefixcode,cnt,clsA,clsP,clsO,clsW,cls) select a.routecls, a.oprid, a.pc, max(a.prefixCode) prefixCode, count(*) cnt, sum(case when a.cls='A' then 1 else 0 end) clsA, sum(case when a.cls='P' then 1 else 0 end) clsP, sum(case when a.cls='O' then 1 else 0 end) clsO, sum(case when a.cls='W' then 1 else 0 end) clsW, 'Z' cls from r20_route12 a(nolock), #operator_selected b where a.routeCls=@routeclass --b.routeCls and a.oprId=b.oprId and a.cls=b.cls and a.pc=b.pc and left(@pLongest,prefixLen)=a.prefixcode group by a.routecls, a.oprid, a.pc update #timecls_selected set cls = (case when (clsW>0) and (cnt = clsW) then 'W' when (clsO>0) and (cnt = clsO) then 'O' when (clsP>0) and (cnt = clsP) then 'P' when (clsA>0) and (cnt = clsA) then 'A' else 'Z' end) update #timecls_selected set cls = (select max(a.cls) from r20_route12 a (nolock) where a.routecls=#timecls_selected.routecls and a.oprid = #timecls_selected.oprId and a.pc=#timecls_selected.pc and a.prefixCode=#timecls_selected.prefixCode and ((a.cls='A' and #timecls_selected.clsA<>0) or (a.cls='P' and #timecls_selected.clsP<>0) or (a.cls='O' and #timecls_selected.clsO<>0) or (a.cls='W' and #timecls_selected.clsW<>0)) ) where cls = 'Z' CREATE TABLE #route ( seqno int identity(10,10), priority int, [id] int, isactive int, reason int, exception int, exceptionCls int, calcexception int, ext int, oprid int, parentid int, routecls int, prefixcode varchar(50), universe varchar(5), domain varchar(5), pdomain varchar(5), [group] varchar(40), interface varchar(40), userinfo varchar(40), hint varchar(100), clsorg char(1), cls char(1), cost float, flag int, rating int, access varchar(10), redlist int ,quality float) if @isgrade =0 begin insert into #route(isactive,reason, exception, exceptionCls, calcexception,[id],parentid,routecls,oprid,prefixcode,clsorg,cls,cost, priority,rating,flag,ext,quality) select x.state isactive, x.reason, isnull(x.exception,0) exception, isnull(x.exceptionCls,0) exceptionCls, case when (isnull(x.exception,0) = 0) then 0 when x.exception > 0 then cast((x.exception+0.5)*10 as int) else cast((x.exception-0.5)*10 as int) end [calcException], x.id, x.parentId, x.routeCls, x.oprId, x.prefixCode, x.clsOrg, x.cls, x.cost, x.priority, rating, x.flag, x.ext,x.quality from r20_route12 x(nolock), #timecls_selected b where x.routecls=b.routecls and x.oprid=b.oprid and x.pc=b.pc and x.prefixcode=b.prefixcode and x.cls=b.cls order by x.cost end else begin insert into #route(isactive,reason, exception, exceptionCls, calcexception,[id],parentid,routecls,oprid,prefixcode,clsorg,cls,cost, priority,rating,flag,ext,quality) select x.state isactive, x.reason, isnull(x.exception,0) exception, isnull(x.exceptionCls,0) exceptionCls, case when (isnull(x.exception,0) = 0) then 0 when x.exception > 0 then cast((x.exception+0.5)*10 as int) else cast((x.exception-0.5)*10 as int) end [calcException], x.id, x.parentId, x.routeCls, x.oprId, x.prefixCode, x.clsOrg, x.cls, x.cost, x.priority, rating, x.flag, x.ext,x.quality from r20_route12 x(nolock), #timecls_selected b where x.routecls=b.routecls and x.oprid=b.oprid and x.pc=b.pc and x.prefixcode=b.prefixcode and x.cls=b.cls order by x.quality, x.cost end select 'r20_route12' routeset, x.seqno priority, x.id, x.isactive, x.reason, x.exception, x.exceptionCls, x.calcexception, isnull(x.ext,0) ext, x.routecls, x.prefixcode, y.universe, y.domain, y.pdomain, y.[group], y.name interface, y.userinfo, isnull(y.hint, '') hint, x.clsOrg, x.cls timecls, x.cost, x.flag, x.rating, '11111' access, 0 redlist,x.quality grade, oprId, @pLongest routepfx, @pRouteName routename --into #all Deleted By N Mohamed 051129 from #route x, r_interface y with (nolock) ---, r_interfaceGroup ig with (nolock) where x.oprId=y.id and x.quality < 10 --and ig.tintid=x.oprId --and ig.intgroupid=@poperatorGroup --and ig.flag=1 and x.isactive=1 and @pLongest like x.prefixcode+'%' order by seqno+[calcException] --order by x.quality, seqno+[calcException], x.cost --drop table #route --drop table #timecls_selected --drop table #operator_selected end GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-21 : 05:44:55
|
You want help for free with a complete SP? Which you have been working on for four days now?I think it's time to call for help and actually PAY an consultant to assist you.Or, if you are running on SQL Server 2005, try to use the new ROW_NUMBER() function. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2008-05-21 : 07:56:44
|
| Run that proc with profiler connected to the server, trace the SP_StmtCompleted events and see which of the statements are the bottleneck.Run the offending statements with the execution plan switched on, and see where the high costs appear.What kind of time are we talking about for this? How many rows are in the base tables? Do you have appropriate indexing?--Gail Shaw |
 |
|
|
|
|
|