Index Usage Report Project / Expensive Queries Table
I created this ETL process (SSIS) to populate my WH Expensive Queries table, so I can later join this table using plan_handle to determine if an index is used within those expensive queries.
Every time I run this ETL I am truncating this WH table and inserting new rows.
Control flow > SQL Task
SQL Task
After that under the Data Flow, I created data source and destination of my ETL process
For OLE DB Source I used SQL command
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;WITH XMLNAMESPACES
(DEFAULT ‘http://schemas.microsoft.com/sqlserver/2004/07/showplan’),expensive_queries AS (SELECTph.plan_handle [PlanHandle],ISNULL(CAST(nodes.value(‘(@StatementSubTreeCost)[1]’, ‘VARCHAR(128)’) as float),0) AS SubTreeCost,ph.usecounts [UseCounts],ph.size_in_bytes [SizeInBytes]FROMsys.dm_exec_cached_plans AS phCROSS APPLY sys.dm_exec_query_plan(ph.plan_handle) AS eqCROSS APPLY query_plan.nodes (‘//StmtSimple’) AS qn (nodes))SELECT TOP 20PlanHandle,SubTreeCost,UseCounts,SubTreeCost * UseCounts [TotalCost],SizeInBytesFROMexpensive_queriesORDER BYTotalCost
DESC
If you want to read more detailed about SHOWPLAN XML Structure you should visit Jason Strate blog, there you can find what else is available within the SHOWPLAN XML for an execution plan.
Leave a Reply