SQL Server basic algorithm for automatically updating statistics

Source: Internet
Author: User

When I first came into contact with SQL Server, I thought that SQL Server would update statistics while changing data. In fact, SQL Server did not. based on performance considerations, SQL server uses the following algorithm to update statistics.

 

The basic algorithm for automatically updating statistics is:

· If the table is in tempdb
The base number of the database table is less than 6, and each of the six modifications automatically updated to the table.

· If the base number of the table is greater than 6 but less than or equal to 500, the update status is
500 modification.

· If the base number is greater than 500, when the table is updating statistics (500 + 20% tables), it is changed.

· Changing the base of a table variable does not trigger automatic update of statistics.

 

Note:: Strictly speaking, SQL Server
The base number is the number of rows in the table.

Note:: In addition to the base, the selectivity of This predicate also affects autostats.
Generate. This means that the statistics may not be updated by the afer.
Every 500
The base number is modified to <500
Or change the base number of each 20% to 500. Proportional Factor (value range from
1 to 4, 1
And 4
Generate the autostats product of the number obtained from the algorithm according to the selectivity.
Generate the actual number of modifications required.

In the form of a table, you can summarised
The above algorithms:

_________________________________________________________________________________

Table type | empty condition | threshold whenempty | threshold when not empty

_________________________________________________________________________________

Permanent | <500 rows | # ofchanges> = 500 | # of changes> = 500 + (20% of cardinality)

___________________________________________________________________________

Temporary | <6 rows | # ofchanges> = 6 | # of changes> = 500 + (20% of cardinality)

___________________________________________________________________________

Table

Variables | change in cardinality does not affectautostats generation.

___________________________________________________________________________

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.