SELECT TOP 10
[ИмяТаблицы] = OBJECT_NAME(sys_indexes.object_id, sys_indexes.database_id),
[ИздержкиОтсутствия] = ROUND(migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans),0),
[СреднийПроцентВыигрыша] = migs.avg_user_impact,
[Поиск] = migs.user_seeks,
[Просмотр] = migs.user_scans,
[Использование] = (migs.user_seeks + migs.user_scans),
[ДатаПоследнегоПоиска] = ISNULL(migs.last_user_seek, CAST('1900-01-01 00:0:00' AS datetime)),
[ДатаПоследнегоПросмотра] = ISNULL(migs.last_user_scan, CAST('1900-01-01 00:0:00' AS datetime)),
[ЧислоКомпиляций] = migs.unique_compiles,
[СредняяСтоимость] = migs.avg_total_user_cost,
[ОсновныеПоляИндекса] = CASE
WHEN sys_indexes.equality_columns IS NULL
AND sys_indexes.inequality_columns IS NULL THEN ''
WHEN sys_indexes.inequality_columns IS NULL THEN sys_indexes.equality_columns
WHEN sys_indexes.equality_columns IS NULL THEN sys_indexes.inequality_columns
ELSE sys_indexes.equality_columns + ', ' + sys_indexes.inequality_columns
END,
[ДополнительныеПоляИндекса] = ISNULL(sys_indexes.included_columns,'')
FROM sys.dm_db_missing_index_groups AS mig
JOIN sys.dm_db_missing_index_group_stats AS migs
ON migs.group_handle = mig.index_group_handle
JOIN sys.dm_db_missing_index_details AS sys_indexes
ON mig.index_handle = sys_indexes.index_handle
ORDER BY [ИздержкиОтсутствия] Desc