Skip to content

Instantly share code, notes, and snippets.

@FilipDeVos
Created March 16, 2021 18:31
Show Gist options
  • Save FilipDeVos/3f9f0ab9396e2761b7420e7573d584c2 to your computer and use it in GitHub Desktop.
Save FilipDeVos/3f9f0ab9396e2761b7420e7573d584c2 to your computer and use it in GitHub Desktop.
Compare Select 1 vs Select * in SQL Server
Table 'test'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
if exists(select 1 from test)
|--Compute Scalar(DEFINE:([Expr1004]=CASE WHEN [Expr1005] THEN (1) ELSE (0) END))
|--Nested Loops(Left Semi Join, DEFINE:([Expr1005] = [PROBE VALUE]))
|--Constant Scan
|--Clustered Index Scan(OBJECT:([master].[dbo].[test].[ck_test1]))
Table 'test'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
if exists(select 1 from test)
|--Compute Scalar(DEFINE:([Expr1004]=CASE WHEN [Expr1005] THEN (1) ELSE (0) END))
|--Nested Loops(Left Semi Join, DEFINE:([Expr1005] = [PROBE VALUE]))
|--Constant Scan
|--Clustered Index Scan(OBJECT:([master].[dbo].[test].[ck_test1]))
select id into test from sysobjects
create clustered index ck_test1 on test(id)
set statistics io on
set statistics profile on
if exists(select * from test)
begin
print 'yes'
end
if exists(select 1 from test)
begin
print 'yes'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment