All,
I've been running this script below regularly to see the supposed usage of my indexes:
SELECT object_name(s.object_id) AS ObjectName
, s.object_id
, i.name as IndexName
, i.index_id
, user_seeks
, user_scans
, user_lookups
, user_updates
FROM sys.dm_db_index_usage_stats s
INNER JOIN sys.indexes i
ON i.object_id = s.object_id
AND i.index_id = s.index_id
WHERE database_id = db_id ()
AND objectproperty(s.object_id,'IsUserTable') = 1
ORDER BY (user_seeks + user_scans + user_lookups + user_updates) ASC
Before I start disabling/dropping indexes, just how accurate is the this dmv?
Thanks,
Ian
The data for the dmvs is real time.|||It records all activity since SQL was last started, in real-time. I have found it to be very reliable and helpful in deciding which indexes are actually being used for reads. Try running this query to get a better picture:
-- Possible bad Indexes (writes > reads)
DECLARE @.dbid int
SELECT @.dbid = db_id()
SELECT 'Table Name' = object_name(s.object_id), 'Index Name' =i.name, i.index_id,
'Total Writes' = user_updates, 'Total Reads' = user_seeks + user_scans + user_lookups,
'Difference' = user_updates - (user_seeks + user_scans + user_lookups)
FROM sys.dm_db_index_usage_stats AS s
INNER JOIN sys.indexes AS i
ON s.object_id = i.object_id
AND i.index_id = s.index_id
WHERE objectproperty(s.object_id,'IsUserTable') = 1
AND s.database_id = @.dbid
AND user_updates > (user_seeks + user_scans + user_lookups)
ORDER BY 'Difference' DESC, 'Total Writes' DESC, 'Total Reads' ASC
No comments:
Post a Comment