SELECT user_seeks * avg_total_user_cost * ( avg_user_impact * 0.01 ) AS [index_advantage]
, migs.last_user_seek
, mid.[statement] AS [Database.Schema.Table]
, mid.equality_columns
, mid.inequality_columns
, mid.included_columns
, migs.unique_compiles
, migs.user_seeks
, migs.avg_total_user_cost
, migs.avg_user_impact
FROM sys.dm_db_missing_index_group_stats AS migs WITH ( NOLOCK )
INNER JOIN sys.dm_db_missing_index_groups AS mig WITH ( NOLOCK )
ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details AS mid WITH ( NOLOCK )
ON mig.index_handle = mid.index_handle
WHERE mid.database_id = DB_ID()
ORDER BY index_advantage DESC
-- 인덱스에대해카운터가되었는지확인
-- Index_id NULL 인경우는인덱스를타지않은경우, NULL 이아닌경우는인덱스를탄경우
SELECT object_name( idx.object_id) as 'table',
idx.name as 'index',
idx.index_id as 'id',
idx.type_desc as 'type',
icol.column_id,
--col.name,
usg.user_seeks,
usg.last_user_seek,
usg.user_scans,
usg.last_user_scan,
usg.user_lookups,
usg.last_user_lookup
FROM sys.indexes idx inner join sys.dm_db_index_usage_stats usg
ON usg.object_id = idx.object_id and idx.index_id = usg.index_id and usg.database_id = db_id()
LEFT JOIN sys.index_columns icol on icol.index_id = usg.index_id and icol.object_id = idx.object_id
AND usg.index_id IS null
AND idx.type_desc not in ('heap','clustered')
'Database > SQL Server' 카테고리의 다른 글
조인 조건자 없음 (0) | 2020.08.27 |
---|---|
DB 보안 (0) | 2020.08.27 |
SQL Server의 동적 데이터 마스킹 (0) | 2020.08.27 |
인덱스 리빌드는 통계를 업데이트 할까? (0) | 2020.08.27 |
INDEX 인덱스 상세 정보 확인 (0) | 2020.08.27 |