TSQL IN EXISTS上的运算符,有区别吗?

时间:2014-10-29 04:45:25

标签: sql tsql sql-server-2008-r2 query-performance sql-execution-plan

以下两个查询在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

Query Plans

0 个答案:

没有答案