-----------------------------------------------------------------------------
/*
SQL Server در Execution Plan آشنایی با مفهوم  
Site:        http://www.NikAmooz.com
Instagram:   https://instagram.com/nikamooz/
Telegram:	 https://telegram.me/nikamooz
Created By:  Iman Bagheri
*/
-----------------------------------------------------------------------------

/* Plan Cache پاک کردن   */
DBCC FREEPROCCACHE


/******Plan Cache بررسی   ******/
SELECT  top 100 *
  FROM [AdventureWorksDW2019].[dbo].[DimEmployee]


/* لیست تمام پلن های موجود  */
SELECT cplan.usecounts, cplan.objtype, qtext.text, qplan.query_plan
FROM sys.dm_exec_cached_plans AS cplan
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS qtext
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qplan
where objtype='adhoc'
ORDER BY cplan.usecounts DESC
 


