10

I just ran a T-SQL query through DTA and one of the recommendations is to CREATE STATISTICS on one of the columns that is part of many of the queries in the SQL code file.

My question is, how exactly do statistics aid in performance?

2 Answers 2

7

statistics is used when query execution plan created.

Statistics for query optimization are objects that contain statistical information about the distribution of values in one or more columns of a table or indexed view. The query optimizer uses these statistics to estimate the cardinality, or number of rows, in the query result. These cardinality estimates enable the query optimizer to create a high-quality query plan. For example, the query optimizer could use cardinality estimates to choose the index seek operator instead of the more resource-intensive index scan operator, and in doing so improve query performance.

See http://msdn.microsoft.com/en-us/library/ms190397.aspx for more details.

3
  • 1
    great link and description. Is it always beneficial to have statistics created on tables that are queried often? Aug 16, 2011 at 1:46
  • yes, we must be sure that statistics for most-readable tables are always adequate. If your table is write-intensive, it is possible that you need to update statistics, for example, every night.
    – Alex_L
    Aug 16, 2011 at 1:52
  • 2
    @Surfer513 - be careful: creating statistics can have a detrimental effect. The better information you are giving the planner may make it choose a different execution path and because this is a game of probabilities, it is possible that this path will be slower (even if it is likely to be faster in general). In other words, on a production database, test before you implement. Aug 16, 2011 at 12:03
7

If DTA recommended a single column statistic, you must have auto create stats turned off? Auto create will build stats on any column used in a predicate, automatically, so generally its a good idea to leave it switched on. Check the status of auto update for this database, which again should usually be on.

One of the best uses of DTA is for identifying missing multi-column statistics, which auto create won't build. But for single column, auto create should be taking care of them for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.