I have a view in SQL Server that calls a function. When I show the actual execution plan for querying the view, what happens inside the function is completely opaque though.
As a small example, I made a function called MyFunction
:
CREATE OR ALTER FUNCTION MyFunction
(@lower int, @upper int)
RETURNS @ReturnTable TABLE
(
[Id] int,
[Value] int
)
AS
BEGIN
DECLARE @SomeTable TABLE
(
[Id] int,
[Value] int
)
INSERT INTO @SomeTable
SELECT EE.Id, M.[ID, Bolag1]
FROM DataModel.EconomicEstate AS EE
LEFT OUTER JOIN DataModel.Metadata AS M ON M.[ID, Kstn] = EE.Id
LEFT OUTER JOIN DataModel.Metadata AS M2 ON M2.[Period] = M.[Period]
INSERT INTO @ReturnTable
SELECT [Id], [Value]
FROM @SomeTable
WHERE [Value] >= @lower AND [Value] <= @upper
RETURN
END
And a view called MyView
that calls MyFunction
:
CREATE OR ALTER VIEW MyView
AS
SELECT *
FROM MyFunction(200000, 400000)
GO
Next, I query the view:
SELECT
[Id], [Value]
FROM
[Test].[dbo].[MyView]
But in the actual execution plan, in SQL Server Management Studio, this is all I see:
Is it possible to dig deeper into MyFunction
to see the performance it uses for joining the tables together? Can I somehow analyze the performance of a multi-statement table valued function?
SELECT * FROM MyFunction(200000, 400000)
, it shows the same execution plan without any details about what happens insideMyFunction
. – Perilselect * from sys.dm_exec_query_statistics_xml(session_id_of_other_session)
in another window to see if that gives you the live plan – AppelleeSQL Server
? – Bowspritsys.dm_exec_cached_plans
and friends. – Gracious