以下两个查询在SQL Server 2008 R2上生成完全相同的执行计划。
但我觉得第二个查询应该表现得更好。
为什么我会为这两个看到相同的查询执行计划?
DECLARE @user_id INT;
SET @user_id = 13;
IF @user_id IN (SELECT [USER_ID]
FROM DBO.[USER]
WHERE HOME_CUSTOMIZATION IS NOT NULL)
BEGIN
PRINT('USER HAS HOME CUSTOMIZATION...');
END
ELSE
BEGIN
PRINT('USER HAS NO HOME CUSTOMIZATION...');
END;
IF EXISTS (SELECT [USER_ID]
FROM DBO.[USER]
WHERE [USER_ID] = @user_id
AND HOME_CUSTOMIZATION IS NOT NULL)
BEGIN
PRINT('USER HAS HOME CUSTOMIZATION...');
END
ELSE
BEGIN
PRINT('USER HAS NO HOME CUSTOMIZATION...');
END