Statistics, or “stats,” are fundamental components of SQL Server performance, but vastly under-appreciated and misunderstood. They are at the core of query optimization and can have tremendous effect on query plan selection. The query optimizer uses statistics to estimate I/O costs and memory grants. Poor statistics, whether they are skewed or incorrect, can cause massive performance problems when they lead to selection of a bad plan. Regardless, having good statistics is still no guarantee that the plan will be optimal for the query. Statistics are mostly self-maintaining, though they can require a little care and feeding when they cause poor plan selection. However, caution is warranted when deciding to do regular maintenance on statistics. Sometimes doing maintenance on stats when it is not warranted can cause more harm than good. The key is to make sure you are addressing the problem, and not just the symptom.
Now, let's get to know statistics. We will take a look at what statistics are, how to view the information they provide, how they are used, and how to maintain them.