What is the better option (performance wise) Inline Scalar UDF, or Outer Apply in SQL 2012

StackOverflow https://stackoverflow.com/questions/22874390

  •  28-06-2023
  •  | 
  •  

Question

I am currently using a bigger, more complex version of:

Select A.Address, A.City, A.State, A.Zip, S.MeterNumber, Ac.AccountNumber, C.CustomerName,
uci.fnGetAttribute(S.ServiceID, 'AMW') as Avg1Mw,
uci.fnGetAttribute(S.ServiceID, 'RateCode') as Rate

from Address a inner join Service s on a.addressid = s.serviceid
inner join vwAccountService v on s.serviceid = v.serviceid
inner join Account ac on v.accountid = ac.accountid
inner join Customer on ac.customerid = c.customerid

The function gathers the most recent attribute requested from a historical data table that has one entry per month.

Would an outer apply be a better choice here performancewise? Or is there a better construct for this?

Was it helpful?

Solution

1) Write the queries you want to test

2) Click the "Include Actual Execution Plan" button in SQL Server Management Studio

3) Run both queries and it'll display how they perform versus each other. One might say it uses 80% of the entire amount of resources used for both queries. That would mean the other one is a lot better.

OTHER TIPS

My gut tells me that a CROSS APPLY, but the true test will be on how they perform against your actual data. It will depend, in part, of what the UDF is actually doing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top