Introduction
Query Statistics:
By now, we have already learnt about the index in Chapter 9, Implementing Indexes, and Chapter 10, Maintaining Indexes. The optimizer chooses the index for a query if there are proper and updated statistics available for key columns of the index, because the SQL Server optimizer is a cost-based optimizer. An optimizer can decide the best way to execute the query, based on the data going to be displayed in result sets with the help of column(s) used in the WHERE
and ON
clauses. The optimizer can get all these details from statistics before executing the actual query.
While creating an index, SQL Server itself creates statistics on key columns of the index and if required, SQL Server 2012 creates statistics on non-key columns, too.
In short, statistics are nothing more than the description of the distribution of data residing in a column or in an index.
Query Selectivity:
Query Selectivity is represented by the number generated by:
Total number of distinct value...