我在 SQL2008 R2 中使用更改跟踪,并在尝试确定批处理中受影响的行时看到一个非常奇怪的行为,使用参数值时,存储的过程需要大约 30 秒才能运行,但是当我将文字值放入调用中时到它在 <1s 内返回的 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 行,会将其减少到 ~1s。
INNER JOIN CHANGETABLE(CHANGES [REDACTED].[dbo].[tblCustomer], 272361) AS [theChangeTable]
当我们运行 SP1 时,我认为 SQL2008 CU4 中发布的 CHANGETABLE 速度较慢的补丁已修复 (http://support.microsoft.com/kb/2276330)。
我很茫然,但为什么将参数更改为文字值会产生如此大的差异?