I've ran into an odd issue. I'm looking at the 'actual' execution plans of two different approaches to the same query. It tells me that the first approach is 97% of the cost, and the second is 3% cost relative to the batch. However, running the actual queries with TIME/IO statistics on shows that the cost is really the other way around. Further to that - the TIME/IO statistics show no physical reads, however when I watch the same query execute with an extended event session I get yet another different story.
The queries:
-- Aproach #1 DECLARE @ConversionRunID INT = ( SELECT MAX(conversionrunid) FROM admin.ConversionExceptionIt1 ) SELECT TableName , Reason , ColumnName , COUNT(*) AS Records FROM admin.ConversionExceptionIt1 WHERE ConversionRunID = @ConversionRunID GROUP BY TableName , Reason , ColumnName -- Approach #2 SELECT TableName , Reason , ColumnName , COUNT(*) AS Records FROM admin.ConversionExceptionIt1 WHERE ConversionRunID = ( SELECT MAX(conversionrunid) FROM admin.ConversionExceptionIt1 ) GROUP BY TableName , Reason , ColumnName
The execution plans:
And the extended event information:
I'm wondering how the execution plan cost can be so wrong, and why the extended event statistics show physical reads when the IO statistics do not.