Sql-server – How to get information about query plans that are out of cache

execution-plansql server

In SQL Server there are a lot of DMV/Fs and other options which allow me to get information about query plans that are in cache, but I can't find any method to get information about all query plans, not just ones saved in cache. Can you, please, show how can I explore all query plans such as a number of times it has been used, its size, etc.?

Best Answer

As Dan noted, you can use Query Store on SQL Server 2016+.

If you're on an earlier version, you can try Open Source Query Store, though I don't have any experience with using it.

As a last resort, you could log sp_BlitzCache to a table. There are instructions on doing that in the README. I'm not going to post them here. Fair warning: I contribute to that open source project.