根据此查询,如果我发现总读取量很少(非常接近0或0,例如1或2),而用户更新量则较高或中等(我无法通过此查询找到插入或删除的内容),行数很大时,理论上我应该删除索引。
SELECT DISTINCT
OBJECT_NAME(s.[object_id]) AS ObjectName
, p.rows TableRows
, i.name AS [INDEX NAME]
, (user_seeks + user_scans + user_lookups) AS TotalReads
, user_updates UserUpdates
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
INNER JOIN sys.partitions p ON p.object_id = i.object_id
WHERE OBJECTPROPERTY(s.[object_id],'IsUserTable') = 1
AND s.database_id = DB_ID()
AND i.name IS NOT NULL
ORDER BY (user_seeks + user_scans + user_lookups) ASC
我想在这里交叉检查这种假设的准确性。例如,已经存在了一年以上但从未被读取过但已被高度更新的索引似乎是一个坏主意。是否存在这种假设无效的情况?