我在SQL2008 R2中使用更改跟踪,并看到一个非常奇怪的行为,当试图确定在批处理中受影响的行,存储过程需要约30秒运行时使用参数值,但是当我将这些文字值放入调用CHANGETABLE函数时,它会返回< 1秒。存储过程/ CHANGETABLE函数速度慢参数,与文字快速
下图的呼叫需要30秒〜:
DECLARE @sync_last_received_anchor BigInt;
DECLARE @sync_new_received_anchor BigInt;
SET @sync_last_received_anchor = 272361;
SET @sync_new_received_anchor = 273361;
SELECT [Customer].[CustomerID]
FROM dbo.tblCustomer AS [Customer] WITH (NOLOCK)
INNER JOIN CHANGETABLE(CHANGES [REDACTED].[dbo].[tblCustomer], @sync_last_received_anchor) AS [theChangeTable]
ON [theChangeTable].[CustomerID] = [Customer].[CustomerID]
WHERE ([theChangeTable].[SYS_CHANGE_OPERATION] = 'U'
AND [theChangeTable].[SYS_CHANGE_VERSION] <= @sync_new_received_anchor
)
然而改变CHANGETABLE线,如下,它减少至〜1秒。
INNER JOIN CHANGETABLE(CHANGES [REDACTED].[dbo].[tblCustomer], 272361) AS [theChangeTable]
我们正在运行SP1我相信在SQL2008 CU4发布CHANGETABLE正在缓慢补丁已被固定(http://support.microsoft.com/kb/2276330)。
虽然为什么将参数改为字面值会产生如此大的差异,但我不知所措?
,你能否告诉我们执行计划? –
@Igor当然 - 不确定是否有最佳格式分享它们,所以导出为XML,并将模式名称更改为[删除],因为它标识了我们的客户端。从[link](http://dl.dropbox.com/u/9443257/WithLiteral.sqlplan)和Variable(参数)[link](http://dl.dropbox.com)下载文字(数字) /u/9443257/WithVariable.sqlplan)。谢谢。 –