某些用于识别缺失索引的“标准”查询确实在Azure上运行,例如:
SELECT
migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) AS improvement_measure,
'CREATE INDEX [missing_index_' + CONVERT (varchar, mig.index_group_handle) + '_' + CONVERT (varchar, mid.index_handle)
+ '_' + LEFT (PARSENAME(mid.statement, 1), 32) + ']'
+ ' ON ' + mid.statement
+ ' (' + ISNULL (mid.equality_columns,'')
+ CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columns IS NOT NULL THEN ',' ELSE '' END
+ ISNULL (mid.inequality_columns, '')
+ ')'
+ ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS create_index_statement,
migs.*, mid.database_id, mid.[object_id]
FROM sys.dm_db_missing_index_groups mig
INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle
WHERE migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) > 10
ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESC
它们可能没有用得多,sp_BlitzIndex
但值得一试。
这是另一个方便的查询,用于识别最热门的查询,然后可以将其与执行计划一起运行,以通过SQL Management Studio识别丢失的索引。乏味地一步一步地做它们,但总比没有好:
SELECT TOP 1000 qs.execution_count,
qs.total_worker_time,
qs.total_worker_time / qs.execution_count AS 'Avg CPU Time',
qs. total_physical_reads,
qs.total_physical_reads / qs.execution_count AS 'Avg Physical Reads',
qs.total_logical_reads,
qs.total_logical_reads / qs.execution_count AS 'Avg Logical Reads',
qs.total_logical_writes,
qs.total_logical_writes / qs.execution_count AS 'Avg Logical Writes',
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 statement_text
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle)AS st
ORDER BY qs.execution_count DESC;
sp_BlitzIndex
在V12 上进行工作,还是它仍然缺少太多相关位而不值得?只要您有空闲时间/需求。:)