Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Defined Function performance - how to quantify

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Hello all,

We don't run a lot of transactions through our system so I don't know how to quantify a recent lunch discussion among our developers. The discussion pertained to avoiding functions in Where clauses where they potentially have to be evaluated over and over.

For purposes of discussion, assume the following two situations, Case 1 where the function result is stored into a local variable and thus is run once and Case 2 where the function is actually included in the Where clause.
Code:
-- Case 1
declare @lGuid uniqueidentifier
set @lGuid = [dbo].[GetGuidFromFunction]()

-- Now use local variable value in Where clause
select * 
from ViewName
where ShapeTypeID = @lGuid
Code:
-- Case 2 - Use function call in Where clause
select * 
from ViewName
where ShapeTypeID = [dbo].[GetGuidFromFunction]()
Presumably, the cost differential between the two cases will be approximately linear based on the number of rows being processed. Can someone give me some kind of a ration between the two? Also, with compiler optimizations, inlining, etc, is this even a significant issue?

If it makes a difference, we are running Sql Server 2005. Thanks in advance for any ideas and/or suggestions!

Have a great day!

j2associatesNO_SPAM@gmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top