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)
 bad practice or necessary evil? Performance tuning

Author  Topic 

cwfontan
Yak Posting Veteran

87 Posts

Posted - 2010-12-01 : 12:16:42
Is it bad practice to have two procedures and do something like the following..?

select @i = count(id) from dbo.tblHist
if @@rowcount < 100000
exec sp_TunedForSmallAmountOfData
else
exec sp_TunedForLargeAmountOfData


Differences in the procs are the temp tables mainly...

sp_TunedForSmallAmountOfData - Declares Table Variables and is very quick for small jobs

sp_TunedForLargeAmountOfData - Creates Temp Tables and is quicker for large jobs


Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-01 : 12:37:04
The information you provided is too limited to be able to answer your question.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-01 : 12:38:08
Table variables aren't really meant for such large data sets (up to 100,000). Although I'm a firm believer that table variables are a bad idea (due to a performance issue I ran into and support from MS), the recommendation for table variable is that the data sets be very small such as a few hundred rows.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-12-01 : 12:41:29
I think you will find that the performance difference (if any) between table variables and temp tables to be negligible. If someone can make a case that the table variable version of the stored procedure is so much faster that it makes sense, then I'd say it's reasonable. Without knowing the specifics, I doubt that the performance difference between the two would warrant a special case. So, ultimately, I would think you would want to go with just one version.

Out of curiosity, do you know the performance difference between the two?
Go to Top of Page

cwfontan
Yak Posting Veteran

87 Posts

Posted - 2010-12-01 : 12:48:28
performace difference is very noticable.

00:10(@tbl) vs 00:45(#tbl) seconds with small queries

04:45(@tbl) vs 01:15(#tbl) seconds with large queries

There is several temp tables and a very large procedure. So i would say it is possible to need two ways of handeling..?



Thanks

quote:
Originally posted by Lamprey

I think you will find that the performance difference (if any) between table variables and temp tables to be negligible. If someone can make a case that the table variable version of the stored procedure is so much faster that it makes sense, then I'd say it's reasonable. Without knowing the specifics, I doubt that the performance difference between the two would warrant a special case. So, ultimately, I would think you would want to go with just one version.

Out of curiosity, do you know the performance difference between the two?


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-01 : 13:01:25
Then it sounds like you've answered your own question.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cwfontan
Yak Posting Veteran

87 Posts

Posted - 2010-12-01 : 13:03:54
yes.. thanks,
Go to Top of Page
   

- Advertisement -