Forum Discussion
TimD
Mar 08, 2024Copper Contributor
Is there a 'secret' limit for inlining scalar UDFs at a max of exactly 99 calls in the query?
I have been trying to improve the performance of a slow view that suffers from massive use of one particular scalar UDF (600 uses in the view). - DB compatibility is at 160 - hosted on Azure SQL (i...
olafhelper
Mar 11, 2024Bronze Contributor
We don't know what your UDF's do exactly, so impossible to even guess a cause.
- TimDMar 11, 2024Copper Contributor
olafhelper The content of the scalar udfs isn't relevant to the question. I've experimented with a mix of udfs including some string manipulation, maths, value lookups and other common patterns including those in Microsoft samples. All show as 'inlineable' and will properly inline in smaller queries. It doesn't matter in what combination they are used in a query, the magic limit of 99 calls is applied by the engine and beyond this inlining and parallelism doesn't happen.
I'm hoping someone recognises this behaviour and can point me at official documentation for this limit so I can understand it and potentially explore workarounds. So far I have been unable to find anything on it.