Last active
December 16, 2019 17:54
-
-
Save mdickin/f4f6744774e650bf4c3aae2d313bd71a to your computer and use it in GitHub Desktop.
Finding and clearing SQL execution plans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT cp.plan_handle, cp.objtype, cp.usecounts, | |
DB_NAME(st.dbid) AS [DatabaseName], st.text, cp.refcounts--, qp.query_plan | |
FROM sys.dm_exec_cached_plans AS cp | |
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st | |
CROSS APPLY sys.dm_exec_query_plan(plan_handle) qp | |
where objtype = 'Prepared' and | |
cp.usecounts > 4 and | |
st.text LIKE N'%some text in the query you want to search for%' OPTION (RECOMPILE); | |
-- For SQL Server | |
DBCC FREEPROCCACHE (some plan_handle you want to clear) | |
-- For Azure | |
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE plan_handle_you_want_to_clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment