我创建的存储过程有效,但是有没有更高效的方法来做到这一点?公平地说,没有任何性能受到影响,也不需要优化,但我想知道为了正确地做事情。优化存储过程更新并选择
执行计划状态query 1: 17%
,query 2: 67%
,query 3: 16%
DECLARE @CurrentVoucherID int;
SET @CurrentVoucherID =
(
SELECT TOP(1) IdGiftVoucherPhysicalCode
from GiftVoucherPhysicalCodes
WHERE Activated = 0 and assigned = 0 and Value = 10
ORDER BY IdGiftVoucherPhysicalCode
);
UPDATE GiftVoucherPhysicalCodes
SET Activated = 1, Activated_at = GETDATE()
WHERE IdGiftVoucherPhysicalCode = @CurrentVoucherID;
SELECT * FROM GiftVoucherPhysicalCodes
WHERE IdGiftVoucherPhysicalCode = @CurrentVoucherID;
我看不出有什么不对的,会做同样的方式... – Hatsjoem 2014-12-04 19:26:49
谢谢你,给我的印象是,选择被运行两次尽管有哪些错误会导致我返回相同的记录。 – GJKH 2014-12-04 19:29:09
但执行计划没有考虑内存中的索引。如果IdGiftVoucherPhysicalCode被索引,最后在哪里寻找一个简单的索引。 – Paparazzi 2014-12-04 20:11:03