|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: 2 days ago @ 7:57 PM
Points: 6,998,
Visits: 13,949
|
|
GregoryAJackson (3/4/2008) function use in the SELECT List and or on the JOIN can also cause severe problems (maybe even worse then in the WHERE Clause).
by placing a Function in the select, that function will execute 1x per row.
We had these at my work also when I first got there. They were causing terrible performance system wide.
Removing them all helped immensely. typically you can replace the functions with some other mechanism of retrieving the data needed (Derived tables, correlated subQueries, etc)
you really need to pay close attention to the Query Plan and specifically to the SubTree cost of the plan. If the SubTree cost approaches 10.0 (in my experience), you need to consider modifying the query.
Cheers,
GAJ
Actually - there was a thread recently on this - and that is by no means true in general. Meaning - there are lots of exceptions. Simple scalar functions, especially deterministic ones, tend to be treated as scalar values that simply replicate on down the line.
It's largely a matter of what goes in (inputs), whether the inputs are based on the row, whether the function is in effect deterministic AND is marked correctly as such (as I came to find out).
Now - if you were using functions to mask a CSQ - then yes - that can be a terrible drag on your performance, but still - it depends a LOT on what the function is doing.
---------------------------------------------------------------------------------- Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:51 PM
Points: 32,923,
Visits: 26,811
|
|
Carl Federl and I did some pretty good testing a couple of years back and it very much supports what Matt says... it depends on the function, how it's written, how it's used, where it's used, etc. Carl and I found out that some functions actually operated quicker than the equivalent inline code while others cause huge drags... and everything in between. It also depends on whether or not parallelism is spawned and for what reason.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, February 26, 2013 2:11 PM
Points: 108,
Visits: 485
|
|
Ahh....good catch.
I was Assuming that the function used in the SELECT depended on the Row (as in a correlated subQuery).
Yes it very much depends on the function, what it's doing, how it's used, etc.
I needed to be more clear.
GAJ
Gregory A Jackson MBA, CSM
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: 2 days ago @ 7:57 PM
Points: 6,998,
Visits: 13,949
|
|
If you want to check out the thread I was referring to - it's over here:
http://www.sqlservercentral.com/Forums/Topic454846-371-2.aspx#bm455633
---------------------------------------------------------------------------------- Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, February 26, 2013 2:11 PM
Points: 108,
Visits: 485
|
|
Thanks a bunch Matt,
I definately will
GAJ
Gregory A Jackson MBA, CSM
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, August 13, 2008 11:30 PM
Points: 10,
Visits: 23
|
|
Thanks GAJ, Matt and Jeff for the valuable information on functions usage.
Rishi
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:51 PM
Points: 32,923,
Visits: 26,811
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, February 26, 2013 2:11 PM
Points: 108,
Visits: 485
|
|
Rishi,
You're very welcome.
I never imagined this trivial little article would have generated so much interest and such a vigorous discussion thread.
I'm very glad that SQLServerCentral published the article now.
cheers,
Gregory A Jackson MBA, CSM
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: 2 days ago @ 7:57 PM
Points: 6,998,
Visits: 13,949
|
|
Rishi - Glad it's been useful. I learned a lot from it for myself...
---------------------------------------------------------------------------------- Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:51 PM
Points: 32,923,
Visits: 26,811
|
|
GregoryAJackson (3/5/2008) Rishi,
You're very welcome.
I never imagined this trivial little article would have generated so much interest and such a vigorous discussion thread.
I'm very glad that SQLServerCentral published the article now. cheers,
Apprently, it wasn't so trivial... Thanks for taking the time to write it, Greg.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|