Based on Query Performance and multi-statement table valued functions and other articles, SQL Server assumes that a multi-line table valued function returns one row. This causes the selection of a poor execution plan for the calling statement if it actually returns many rows.
Does adding SCHEMABINDING
to the function result in a more correct cardinality estimate for the returned value set of the function?
If we assume that we are passing a UserId to this function and getting back a table of RecordId values that the user is allowed to access, and that some users are only allowed to see a few records and that some are allowed to see many or even all records, would either the function or the calling statements (or the procedures that include them) benefit from using RECOMPILE
? Does the use of SCHEMABINDING
in the function change this answer?
I realize that I could figure this out by experimentation, but I am hoping that someone has already figured out the answer. A pointer to someplace where this is well documented would be helpful.