---sql text 和执行计划select top 200 c.creation_time ,c.last_execution_time ,c.execution_count, --c.query_text,plan1.query_plan , c.total_worker_time/execution_count/1000/1000.00 AGV_worker_time_S,c.total_elapsed_time/execution_count/1000/1000.00 AGV_elapsed_time_S from (SELECT ( SELECT SUBSTRING(text, statement_start_offset/2 + 1, (CASE WHEN statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(max), text)) * 2 ELSE statement_end_offset END - statement_start_offset)/2)FROM sys.dm_exec_sql_text(sql_handle)) AS query_text,dqs.*FROM sys.dm_exec_query_stats dqs) cCROSS APPLY sys.dm_exec_query_plan(c.plan_handle) plan1 where lower(c.query_text) like '%table%' --and lower(c.query_text) like '%table_column%' --索引的第一个列order by c.total_elapsed_time/execution_count desc -- 按照执行时间排序---索引的使用时间select i.name,diu. * from sys.dm_db_index_usage_stats diu left join sys.indexes i
on diu.index_id=i.index_id
where diu.object_id=OBJECT_ID('dbo.table')and i.object_id=OBJECT_ID('dbo.table')
把第一个执行结果导出为txt文本后,有execl程序打开,筛选列为query_plan 的执行计划,用 index name 筛选,有用的话会显示