SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


performance impact of "Try...Catch"?


performance impact of "Try...Catch"?

Author
Message
eltont9404
eltont9404
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 19
Hello guys,

my question is: Is there any performance defects if I use Try...catch blocks in my stored procedure?

Regards,
Elton
Hari.Sharma
Hari.Sharma
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1616 Visits: 455
Hi

I guess NO.

Cheers,
Hari
Tips & Tricks for SQL BI Developers

IN_Sandeep
IN_Sandeep
SSChasing Mays
SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)

Group: General Forum Members
Points: 637 Visits: 1255
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.

--
abmore
abmore
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1251 Visits: 931
I guess TRY CATCH block improves the error handling in store procedure, it doesn't have any performance issues with it.
Atif-ullah Sheikh
Atif-ullah Sheikh
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3806 Visits: 5190
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


Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41569 Visits: 32666
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
GSquared
GSquared
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24355 Visits: 9730
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
eltont9404
eltont9404
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 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
GSquared
GSquared
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24355 Visits: 9730
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
eltont9404
eltont9404
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search