Sql-Server-2008
如何防止每天99%的索引碎片
我有一個 100.000 名玩家的高分錶,每天插入 2 次,每個玩家一條記錄。在一天結束時,該表中索引的索引碎片為 99%。有沒有辦法通過調整設置來防止這種情況?
CREATE TABLE HighScore( [id] [int] IDENTITY(1,1) NOT NULL, [user] [int] NULL, [player] [int] NULL, [round] [tinyint] NULL, [group] [int] NULL, [rank] [int] NULL, [delta] [int] NULL, [roundpoints] [int] NULL, [totalpoints] [int] NULL, PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY] ) ON [PRIMARY] CREATE NONCLUSTERED INDEX [HighScore_RoundGroup_Nidx] ON .[HighScore] ( [round] ASC, [group] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY] GO
我認為您應該嘗試更高的
FILLFACTOR
設置HighScore_RoundGroup_Nidx
(例如 50 或 40)。您可以將 設置FILLFACTOR
為 0 或 100,PRIMARY KEY
因為它不應該碎片 如果仍然存在,FILLFACTOR
則無濟於事,因為原因是新分配的頁面與其他新分配的頁面交錯。這是一個眾所周知的 SQL Server 問題。您可以將此索引移動到其自己的文件組中,這將停止此問題。
也許您認為您正在重建,但索引沒有重建,因為索引不夠大。
看看這個問題 Why index REBUILD does not reduce index fragmentation?
重建後檢查碎片嗎?是否真的進行了碎片整理。