And nothing about the functions. Why is the function information
missing in the actual plan?
This is by design, for performance reasons.
Functions that contain
END in the definition create a new T-SQL stack frame for each input row. Put another way, the function body is executed separately for each input row. This single fact explains most performance problems associated with T-SQL scalar and multi-statement functions (note that in-line table valued functions do not use the
In the context of your question, this would result in full
SHOWPLAN output for each row. XML plan output is quite verbose and expensive to produce, so producing full output for every row would be a bad idea in general terms.
Consider the T-SQL scalar function below, created in the AdventureWorks sample database, which returns the name of a product given its ID:
CREATE FUNCTION dbo.DumbNameLookup
FROM Production.Product AS p
p.ProductID = @ProductID
A pre-execution plan (estimated plan in SSMS) shows plan information for the parent statement and nested function calls:
-- Pre-execution plan shows main query and nested function call
SET SHOWPLAN_XML ON;
SET SHOWPLAN_XML OFF;
The same XML viewed in SQL Sentry Plan Explorer shows the nested nature of the calls more clearly:
SSMS shows details for only the main query when post-execution plan output is requested:
-- Post-execution plan shows main query only
SET STATISTICS XML ON;
SET STATISTICS XML OFF;
The performance impact of doing otherwise can be shown using the Showplan XML Statistics Profile Event Class in SQL Server Profiler, using a query that calls the function multiple times (once per input row):
SELECT TOP (5)
FROM Production.Product AS p;
There are five separate post-execution plans for the function executions, and one for the parent query. The five function plans look like this in the profiler lower pane:
The parent query plan is:
Executing the query without the
TOP (5) clause results in a full execution plan for each of the 504 rows in the Product table. You can probably see how this would quickly get out of hand with larger tables.
The situation for triggers is reversed. These do not show any pre-execution plan information, but do include a post-execution plan. This reflects the set-based nature of triggers; each is fired once for all rows affected, rather than once per row.