Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 template plan guide

Author  Topic 

DenisSun
Starting Member

2 Posts

Posted - 2011-10-05 : 11:58:28
How can I know if there are any queries that are using any template plan guides in a database?

I was able to answer above question regarding object or sql plan guide with the following query
--------------------------------------
SELECT
SUBSTRING(st.TEXT, (qs.statement_start_offset/2)+1 , ((CASE qs.statement_end_offset WHEN -1 THEN datalength(st.TEXT)
ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS sql_txt
, qp.query_plan.value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/showplan";
(/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple/@PlanGuideDB)[1]' , 'varchar(100)') AS [PlanGuideDB]
, qp.query_plan.value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/showplan";
(/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple/@PlanGuideName)[1]' , 'varchar(100)') AS [PlanGuideName]
,qp.query_plan
, total_worker_time/execution_count AS AvgCPU
, total_elapsed_time/execution_count AS AvgDuration
, (total_logical_reads+total_physical_reads)/execution_count AS AvgReads
, execution_count
FROM sys.dm_exec_query_stats qs
cross apply sys.dm_exec_sql_text(sql_handle) st
cross apply sys.dm_exec_query_plan(plan_handle) qp
WHERE qp.query_plan.exist('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/showplan";
/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple[(@PlanGuideName)]') = 1
ORDER BY [PlanGuideDB], [PlanGuideName] DESC
go
------------------------------------------

But the problem with template plan guide is there won't be any attributes like 'PlanGuidename' appear in the xml plan ( at least in 2008R2 which I tested). Any idea?

Denis

DenisSun
Starting Member

2 Posts

Posted - 2011-10-05 : 18:47:32
To describe my intention more clearly, I wrote a blog.
http://oracle-study-notes.blogspot.com/2011/10/sql-server-are-there-any-queries-using.html

Just starting to learn SQL Server, hope I did not miss sth obvious.

Thanks!

Denis

----------
Thanks
Denis
Go to Top of Page
   

- Advertisement -