August 7, 2006 at 2:10 pm
I have inheritted an SP that I am trying to speed up.
Our data was radically changed, (legacy system) in 2001. I have a portion of the SP that checks if the @fyear < 2002. If that is true, the older tables are used, else the newer tables are used.
When I commented this section of the code out of the procedure, it ran substantailly faster, even though in both cases the fyear was 2002.
Any ideas what may be happening? TIA.
I wasn't born stupid - I had to study.
August 7, 2006 at 4:56 pm
can you do a PRINT @fyear just before the IF loop to see what is the value the variable has?
******************
Dinakar Nethi
Life is short. Enjoy it.
******************
August 8, 2006 at 2:13 am
I've had a similar problem before. It may have to do with procedure caches and compiling.
Try splitting the stored proc into 3. The main stored proc does a check of the year, if <2002 it calls one procedure, if >2002, it calls the other
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 8, 2006 at 5:26 am
Thanks. I was thinking about that approach - of course I'm dealing with a large #TempTable throughout the procedure, but maybe I can pass the information back and fourth...
I wasn't born stupid - I had to study.
August 8, 2006 at 5:39 am
If you create the #Temp in the outer, it will be available to the two subprocedures.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 8, 2006 at 6:13 am
Don't forget... temp tables are tables, too. You can add indexes...
--Jeff Moden
Change is inevitable... Change for the better is not.
August 8, 2006 at 4:10 pm
Do it all the time. Thanks! (beautiful thing, that...)
(bit of a bang up today, (our car was hit on the way to work - not so good) so I have not had a chance to test..., will let you know).
I wasn't born stupid - I had to study.
August 8, 2006 at 5:50 pm
Also... consider using RECOMPILE in the stored proc if the server would be better off not trying to re-use an execution plan. You could also use the query hint for specific queries in the sproc. If you simply want to recompile the sproc once, use "sp_recompile".
August 8, 2006 at 6:20 pm
Yeah... I forgot that you've been around a long time... didn't even read to see who did the post, Farrell.
Speaking of being around for a long time, whatcha doin' gettin' all banged up? Hope you and your's are OK... best of luck, old friend.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply