누락 된 인덱스를 식별하기위한 '표준'쿼리 중 일부는 예를 들어 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
, 아니면 여전히 가치가있는 관련 비트가 너무 많이 없습니까? 여가 시간이 필요합니다. :)