Here are some of my findings
Test Table
CREATE TABLE Test_Table (ID INT , Value INT)
GO
INSERT INTO Test_Table
VALUES
(1, 100),
(2, 100),(2, 100),
(3, 100),(3, 100),(3, 100)
GO
View on that table
CREATE VIEW vw_Test_View
AS
SELECT ID, SUM(Value) AS Total
FROM Test_Table
GROUP BY ID
GO
Clear_Chached Plans
-- Clear chache for any chached plans
-- (Warning do not execute this on Production server)
DBCC FREEPROCCACHE;
GO
Calling View
-- Execute the same select from view twice
SELECT * FROM dbo.vw_Test_View
GO
SELECT * FROM dbo.vw_Test_View
GO
Chached Plans Inspection
-- Inspect Chached execution plans
SELECT UseCounts, Cacheobjtype, Objtype, [TEXT]
FROM sys.dm_exec_cached_plans
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
WHERE [TEXT] LIKE '%vw_Test%'
GO
╔═══════════╦═══════════════╦═════════╦════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ UseCounts ║ Cacheobjtype ║ Objtype ║ TEXT ║
╠═══════════╬═══════════════╬═════════╬════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
║ 1 ║ Compiled Plan ║ Adhoc ║ SELECT UseCounts, Cacheobjtype, Objtype, TEXT, query_plan FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) CROSS APPLY sys.dm_exec_query_plan(plan_handle) WHERE [TEXT] LIKE '%vw_Test%' ║
║ 2 ║ Compiled Plan ║ Adhoc ║ SELECT * FROM dbo.vw_Test_View ║
╚═══════════╩═══════════════╩═════════╩════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
Conclusion
As you can see the execution plan for our SELECT * FROM View
was compiled once and reused on second execution of the same query.
It is a view, Plan was chached and it was reused on subsequent execution. Hope this explanation helps . Thank you.
SELECT
on a view is really in the end a select query, and like any other query, it's execution plan will be cached - it's no different from an ad-hoc query or a query from inside a stored procedure ..... a query is a query is a query in SQL Server, and all execution plans are cached (until evicted from cache) – Harrisonharrod