|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, December 04, 2008 9:09 PM
Points: 6,
Visits: 19
|
|
Hello guys,
my question is: Is there any performance defects if I use Try...catch blocks in my stored procedure?
Regards, Elton
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, December 26, 2012 12:43 PM
Points: 1,330,
Visits: 455
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, March 07, 2011 3:15 AM
Points: 375,
Visits: 1,255
|
|
before using it just go through the Try-Catch Concepts in Sql Server 2005, because it has some limitation, I personally prefer to use custom error handling method in SQL Server 2005 too.
Cheers!
Sandy.
--
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 8:06 AM
Points: 1,134,
Visits: 818
|
|
| I guess TRY CATCH block improves the error handling in store procedure, it doesn't have any performance issues with it.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Thursday, March 14, 2013 4:15 AM
Points: 3,240,
Visits: 4,960
|
|
Just for error handeing, no issue of performance. Also, I think, using try / catch isd fast in case of execution, as it directly goes to error - handeler on error. In another casem, the next lines are executed or tried to be executed (in some cases.)
Atif Sheikh
---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sometimes, winning is not an issue but trying. You can check my BLOG here
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 12:19 PM
Points: 13,371,
Visits: 25,144
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
Just as a test, I ran:
create table #Runtime ( Version int, Runtime int) go declare @Start datetime, @X int select @start = getdate()
select @x = col2 from dbo.sometable
insert into #runtime (version, runtime) select 1, datediff(ms, @start, getdate()) go 100 begin try
declare @Start datetime, @X int select @start = getdate()
select @x = col2 from dbo.sometable
end try begin catch
end catch
insert into #runtime (version, runtime) select 2, datediff(ms, @start, getdate()) go 100 select version, avg(runtime) as [avg], max(runtime) as [max], min(runtime) as [min] from #runtime group by version
Average runtime was identical (289 ms), max was nearly so (330 vs 313, try/catch had lower number), min was identical (280). The slight variation in max doesn't mean anything.
So, Try/Catch doesn't impact performance, unless your Catch does something intensive.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, December 04, 2008 9:09 PM
Points: 6,
Visits: 19
|
|
Odd SSCrazy:
When I do the test with select:
declare @Runtime table ( Version int, Runtime int)
declare @Start datetime, @X int select @start = getdate()
select top 100 * from b_order
insert into @Runtime (version, runtime) select 1, datediff(ms, @start, getdate())
begin try
select @start = getdate()
select top 100 * from b_order
insert into @Runtime (version, runtime) select 2, datediff(ms, @start, getdate()) end try begin catch the result I got is
version runtime 1 0 2 30 (average result)
When I use "select top 1000 * from b_order" the result I got is
version runtime 1 390 2 420
When I use "select top 10000 * from b_order" the result I got is
version runtime 1 700 2 717
Seems there's some overhead for try..catach, is it?
Elton
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
Your test has more variables in it than just Try/Catch. For example, the time to return the result-set to the connection and paint it to the screen. (That's why I did my select the way I did.)
Try the test I did, using whatever table you like. Mine's a 1-million-row table of random data.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, December 04, 2008 9:09 PM
Points: 6,
Visits: 19
|
|
Yes your are right GSquared,
I did sth stupid,
The test should be:
declare @Runtime table ( Version int, Runtime int)
declare @Start datetime, @X int select @start = getdate()
select top 1000 * from b_order
insert into @Runtime (version, runtime) select 1, datediff(ms, @start, getdate())
begin try
select @start = getdate()
select top 1000 * from b_order
insert into @Runtime (version, runtime) select 2, datediff(ms, @start, getdate()) end try begin catch end catch Thanks
|
|
|
|