Results 1 to 4 of 4

Thread: Performance evaluation of User defined functions

  1. #1
    Join Date
    Jul 2005
    Posts
    9

    Performance evaluation of User defined functions

    Hi
    While its known and acknowledge that stored procedures greatly help in increasing the speed of our database queries, i am unaware of the benefits of user defined functions. In a current project, i have used them quite a lot espically in stored procedures.

    For example,
    if i hav a table Users with
    UserID int,
    Username nvarchar(50),
    one of the functions i made was fn_GetUserNameFromUserID(@UserID)
    which returns the name of the person,

    so instead of long joins to get usernames, i wud easily be able to get the name of a person if userid is another table say X.
    so i could so select fn_GetUsernamefromUserid(X.UserID).

    While i do realize that a simple join is nice, but sometime when a query involoves 3 + tables, it makes life simopler. CAn anyone tell me about the performance overhead of this, or is this the proper approach to using user defined functions.

    Thanks

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    You can put query with function and query with stored procedure call in same batch and compare their cost in execution plan.

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    If you are using a UDF in a SELECT you have to be aware that the function is executed for each row of the result set which may make the query very slow. If you are using to get just one row back then whether you use SP or UDF, it may perform equally well.

  4. #4
    Join Date
    Jul 2005
    Posts
    9
    HI skanal, thanks for the info.
    Check
    http://forums.databasejournal.com/sh...ad.php?t=39791

    for a really wierd anomaly which i am seeing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •