Files
sql-snippets/find_query_plan_handle-e179aa64-7830-440b-a199-9c0a65750a8f.json
2023-06-12 15:56:45 +02:00

6 lines
734 B
JSON

{
"id": "e179aa64-7830-440b-a199-9c0a65750a8f",
"prefix": "find_query_plan_handle",
"description": "find a query plan from the cache and if needed drop it from the cache",
"body": "DECLARE @SearchForSql AS NVARCHAR(MAX) = N'TEXT_TO_FIND';\r\n\r\nSELECT usecounts,\r\n cacheobjtype,\r\n objtype,\r\n text,\r\n query_plan,\r\n [plan_handle]\r\n FROM sys.dm_exec_cached_plans\r\n CROSS APPLY sys.dm_exec_sql_text(plan_handle)\r\n CROSS APPLY sys.dm_exec_query_plan(plan_handle)\r\n WHERE text LIKE CONCAT('%', @SearchForSql, '%')\r\n AND text NOT LIKE '%-- Self Reference Marker --%';\r\n\r\n--DBCC FREEPROCCACHE (plan_handle_id_goes_here)"
}