The impact of SQL Server statistics on queries

Source: Internet
Author: User
Tags dba

The optimizer chooses which execution plan is selected based on the extinction and is related to the row count statistics, which are automatically generated by default in the process of optimization.

Once the column is marked for statistical information, the query optimizer looks for the statistics for that column, and if there is a statistic, the next step is to check

To make sure it's new enough. Rebuild statistics if they expire. (This shows that statistics are column-based).

--------------------------------------------------------------------------------------------------------------- -----------------

The option to automatically create statistics in the database is turned on by default:

ALTER DATABASE .... set Auto_create_statistics {on | off};

ALTER DATABASE .... set Auto_update_statistics {on | off};

If automatic creation of the system is disabled, the query outputs a warning. In this mode the DBA ensures that the statistics object is up-to-date.

Actions can be prompted to control the behavior of the statistics object.

Create Index ... with (Statistics_norecompute = ON)

Create statistics .... with (NoRecompute)

Although these options are generally turned on, the ability to create or update statistics is disabled in the following scenarios.

1. The DBA explicitly decides to update statistics instead of Automatic Updates, and the database has a Maintenance window, in which case the DBA believes that the change in statistics will

Optimizer chooses a slower plan

2, the data table is too large, automatic update hair time is too long.

3. There are many unique values in the database tables, and the sampling frequency used to generate the statistics is not sufficient to obtain all the statistics required to generate a good execution plan.

A DBA can use a maintenance window to increase the sampling frequency (the default frequency varies according to the size of the table) to manually update statistics.

4. The database defines a short query timeout and does not want automatic statistics to cause the query time to be significantly longer, as this may cause a query to time out.

The impact of SQL Server statistics on queries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.