当我看到这样的变化时,我的第一个想法是确保您已为所有表重新生成统计信息。网上有很多脚本可以做到这一点,并且有很多关于是否使用内置存储过程、是否进行全扫描等的讨论。这是一个快速而肮脏的脚本,我会在进行比较之前运行它。
CREATE PROCEDURE sp_UtilityUpdateStats AS
SET NOCOUNT ON
DECLARE @iCounter INT
DECLARE @iCounterMax INT
DECLARE @TableList TABLE
(
iTable INT IDENTITY(1,1) PRIMARY KEY,
szTableName VARCHAR(128)
)
INSERT @TableList (szTableName)
SELECT [name] FROM sysobjects
WHERE [type] = 'u'
ORDER BY [name] DESC
SET @iCounterMax = (SELECT MAX(iTable) FROM @TableList)
SET @iCounter = 0
DECLARE @szTableName VARCHAR(128)
RAISERROR(N'------STARTING sp_UtilityUpdateStats------', 10, 1) WITH LOG
WHILE @iCounter < @iCounterMax
BEGIN
SET @iCounter = @iCounter + 1
SELECT @szTableName = szTableName
FROM @TableList
WHERE iTable = @iCounter
RAISERROR(N'UPDATE STATISTICS YourDB.dbo.%s', 10, 1, @szTableName) WITH LOG
EXEC ('UPDATE STATISTICS YourDB.dbo.' + @szTableName)
END
RAISERROR(N'------FINISHING sp_UtilityUpdateStats------', 10, 1) WITH LOG
SET NOCOUNT OFF
GO