SQL SERVER INDEX (Part 4): Statistics

Firstly, I recommend watching this How to Think Like the Engine - YouTube by Brent Ozar on YouTube (all parts). It is incredibly helpful foundational material before you begin your SQL performance tuning journey. Throughout my SQL Server Index series, I have emphasized the importance of accurate statistics in helping SQL Server choose the best execution plan. I've mentioned that if a query has accurate indexes and correct cardinality estimates , the optimizer's choices are usually optimal. However, I haven't discussed the scenario when row estimates are inaccurate , leading the optimizer to make suboptimal choices. This post will cover some examples of that. To demonstrate, I will use the StackOverflow2010 database. Feel free to follow along with my examples. (If you haven't, please checkout Tools I Used During Query Performance Troubleshooting to see how I setup to obtain execution plan and logical reads info.) Problem Consider the follow...