Why are Logical Reads So High for Windowed Aggregate Functions with Common Subexpression Spools?
You've noticed that in execution plans with common subexpression spools, the reported logical reads for large tables are significantly higher than expected. Investigation reveals a formula that appears to hold true: Worktable logical reads = 1 NumberOfRows 2 NumberOfGroups 4.
Understanding the Formula
The high logical reads arise from the unique way worktables handle reads. Logical reads in this context refer to the number of rows read, not hashed pages. This means that for each row processed, the worktable registers one logical read.
Breakdown of Logical Reads
Replication Attempt with Lower Logical Reads
Your attempt to replicate the process with a heap table shows only 11 logical reads because:
Conclusion
The formula you found holds true because it accurately reflects the number of rows read by the worktable. The higher logical reads are due to the row-based counting method, not inefficiency. The nested loops plan used in your original query amplifies this count further.
The above is the detailed content of Why Do Windowed Aggregate Functions with Common Subexpression Spools Result in Such High Logical Reads?. For more information, please follow other related articles on the PHP Chinese website!