Performance of TableValuedFunctions | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Performance of TableValuedFunctions

I have a table valued Functions which return records in 110 milliseconds while if i run the query with the same input parameters as the table valued function it return in 46 milliseconds. I need to know why there is so much difference. I wanted to know what should I do in the table valued function to return the dataset in 46 milliseconds. Since I am using a lot of Table valued function for security access and it used everywhere, am I looking for a consistent performance. Any Help or information would be appreciated. Regards,
santosh Verma
Please post your code. Looks like a case of parameter sniffing. See if this applies:
Frank Kalis
Microsoft SQL Server MVP
Contributing Editor, Writer & Forum Moderator
Did you clear cache, checkpoint, etc. between each run? That could have an impact on the execution times. fyi on the table fragmentation.
quote:There are 2 parts in Table-valued functions (TVF) execution firstly, the attributes applied to the method must fully declare the structure of the table that is returned. Second, there are two methods involved. The first returns an enumerable object instead of the actual result of the function. The second method is passed the enumerated objects to populate the fields of each row. Each value retrieved via the enumerator should correspond with one row of the resultset. fyi.
Satya SKJ
Microsoft SQL Server MVP
Writer, Contributing Editor & Moderator
This posting is provided AS IS with no rights for the sake of knowledge sharing. Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it.