You should not expect to see the same values for logical reads in these two cases (SET STATISTICS IO ON
and SQL Profiler:Batch Completed
) because they have measure different things:
SET STATISTICS IO ON
will returnlogical reads
for statement[s] only,SQL Profiler:Batch Completed column Reads
will return logical reads for entire batch including here logical reads generated by compilation (your batch has a DBCC FREEPROCCACHE statement which force a compilation and this means logical reads because SQL Server have to read metadata information). Also, if you activateQuery > Actual execution plan
in SQL Server Management Studio you will see an increase inReads
column).
For example, when I run these the two batches in SSMS
-- Without Query > Actual Execution Plan
DBCC DROPCLEANBUFFERS;
DBCC FREEPROCCACHE;
exec MyTableLoadByPK @MyTableID=1001
GO
-- With Query > Actual Execution Plan
DBCC DROPCLEANBUFFERS;
DBCC FREEPROCCACHE;
exec MyTableLoadByPK @MyTableID=1001
GO
the output from SET STATISTICS IO ON
is 0 logical reads
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Table 'MyTable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Table 'MyTable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
but SQL Profiler
shows for Batch completed
event another results in Reads
column:
TLDR: Simple explanation is that you're trying to compare different things.