Hi,
I'm trying to understand the performance difference between two queries. I've had to change the table names as I can't post schema details online!
I stumbled across a stored procedure which seemed to produce a high number of logical reads so wanted to investigate.
One particular statement stood out which I tried to rewrite, but the logical reads went up.
--Original Code DELETE FROM dbo.ItemNumericAttribute WHERE ItemNumericAttributeId IN (SELECT ItemNumericAttributeId FROM dbo.Item WHERE ItemId IN (SELECT DISTINCT ItemId FROM #ItemToDelete)) --New Code DELETE dbo.ItemNumericAttribute FROM #ItemToDelete itd INNER JOIN dbo.Item i ON i.ItemId = itd.ItemId INNER JOIN dbo.ItemNumericAttribute ina ON ina.ItemNumericAttributeId = i.ItemNumericAttributeId
The execution plans are identical besides a stream aggregate in the original code (0% cost) and an additional sort (1% cost) in the new code.
The bulk of the work is the clustered index seek on the ItemNumericAttribute table which is 95% (original) and 94% (new).
The logical reads seems to jump by 60% on the ItemNumericAttribute table. I've tried different ordering of the tables in the joins to no avail and I am confused as to why I see such a jump in reads. Duration is the same in both cases and the number
rows deleted is the same.
I've gone through the execution plan and looked at the tooltips in both plans and I can see no difference when I compare the operators.
Any thoughts?