Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

performance impact of "Try...Catch"? Expand / Collapse
Author
Message
Posted Sunday, July 20, 2008 10:50 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 4, 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

Post #537339
Posted Sunday, July 20, 2008 11:32 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, December 26, 2012 12:43 PM
Points: 1,330, Visits: 455
Hi

I guess NO.


Cheers,
Hari
Tips & Tricks for SQL BI Developers
Post #537360
Posted Sunday, July 20, 2008 11:40 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 7, 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.


--
Post #537371
Posted Sunday, July 20, 2008 11:42 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:03 AM
Points: 1,154, Visits: 866
I guess TRY CATCH block improves the error handling in store procedure, it doesn't have any performance issues with it.
Post #537373
Posted Monday, July 21, 2008 1:03 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, June 27, 2014 8:02 AM
Points: 3,241, Visits: 4,996
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

Post #537437
Posted Monday, July 21, 2008 6:30 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:51 AM
Points: 15,517, Visits: 27,897
TRY/CATCH itself has no performance implications. What you do in the CATCH statement could have serious performance implications.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #537613
Posted Monday, July 21, 2008 10:53 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #537837
Posted Monday, July 21, 2008 6:09 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 4, 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
Post #538082
Posted Tuesday, July 22, 2008 11:32 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #538674
Posted Tuesday, July 22, 2008 5:36 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 4, 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
Post #538908
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse