我在以前成功的存储过程中遇到了奇怪的经历,它执行了以下操作: -
ALTER INDEX ALL ON Prices_Staging REBUILD;
TRUNCATE TABLE Prices_Empty;
ALTER TABLE Prices switch TO Prices_Empty;
ALTER TABLE Prices_Staging switch TO Prices;
这在过去总是起作用,但经常是“改变指数全部打开dbo.Prices_Staging REBUILD”;'声明是及时的,碎片只有0.3%!
我在sp中引入了一个测试来检查表索引的平均碎片......
SET @Frag = (SELECT
sum(avg_fragmentation_in_percent)
FROM sys.dm_db_index_physical_stats
(
DB_ID(@DATABASE)
,OBJECT_ID(@TableName)
,OBJECT_ID(@IndexName)
,NULL
,NULL
))
If @Frag > 30
BEGIN
ALTER INDEX ALL ON Prices_Staging REBUILD;
END
ELSE
BEGIN
ALTER INDEX ALL ON Prices_Staging SET(ALLOW_PAGE_LOCKS = ON);
ALTER INDEX ALL ON Prices_Staging REORGANIZE;
END
Now, the final SWITCH fails as it reports that the indexes are not the same between staging and prices ?
进一步调查显示,表格中的所有索引都已禁用页面级别锁定。
我可以通过重建表中的所有索引来解决问题。
那么是什么导致REORGANIZE禁用了Page Level Locking?