在 SQL Server 2005 中,我遇到了一个带有唯一 ID 列(上面有唯一索引)和主键聚集索引的表(所以这个列上有明确的 2 个索引)。这是在此表上插入/更新/删除的主要性能因素吗?
我正在尝试提高很久以前创建的数据库的性能,我想知道删除这些冗余的唯一索引是否会有所帮助。数据库是否在每次内容修改时检查/重建这两个索引?或者性能增益会不会太小以至于不能为此烦恼?
这是一个示例索引使用输出:
INDEX UserSeeks UserScans UserLookups UserUpdates
--------------------------------------------------------
1_PK 45517046 42911 245353 0
1_UQ 45517046 42911 245353 0
1_Other 45517046 42911 245353 0
--------------------------------------------------------
2_PK 21538111 5685 231030 1121
2_UQ 21538111 5685 231030 1121
3_other 21538111 5685 231030 1121
这是我用来获取该数据的查询:
SELECT OBJECT_NAME(I.OBJECT_ID) AS ObjectName,
I.NAME AS IndexName,
S.user_seeks AS UserSeeks,
S.user_scans AS UserScans,
S.user_lookups AS UserLookups,
S.user_updates AS UserUpdates
FROM sys.indexes I
JOIN sys.dm_db_index_usage_stats S
ON (S.OBJECT_ID = I.OBJECT_ID)
WHERE(database_id = DB_ID())
并固定加入条件:
SELECT OBJECT_NAME(I.OBJECT_ID) AS ObjectName,
I.NAME AS IndexName,
S.user_seeks AS UserSeeks,
S.user_scans AS UserScans,
S.user_lookups AS UserLookups,
S.user_updates AS UserUpdates
FROM sys.indexes I
JOIN sys.dm_db_index_usage_stats S
ON (S.OBJECT_ID = I.OBJECT_ID)
AND(S.index_id = I.index_id)
WHERE(database_id = DB_ID())