Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SQL Server cache execution plan of a view?

In SQL Server, stored procedures execution plans are cached but view execution plan are never cached. Is that true? If yes, why does SQL Server not cache view execution plans?

If a optimizer is taking a long time to create execution plan, is it helpful to wrap the query in a view?

like image 895
Costa Avatar asked May 03 '14 15:05

Costa


1 Answers

There is no such thing as an execution plan for a view (at best, a parse tree is cached). View is always optimized as a part of the outer query (somewhat simplified, the text of the view is merged with text of the outer query and then optimized).

Will an execution plan of a query using a view be cached or not depends on the very same factors as with any other query.

like image 151
dean Avatar answered Sep 30 '22 06:09

dean