HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

What is the default sample size of statistics in SQL Server?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thesamplewhatsqlsizedefaultstatisticsserver

Problem

From MSDN:


When none of the sample options (SAMPLE, FULLSCAN, RESAMPLE) are
specified, the query optimiser samples the data and computes the
sample size by default.

How to identify default sample size of statistics?

I went through MSDN but didn't find any formula or method to identify the default sample size. Everywhere there are only formulas present to trigger the auto statistics update. Any pointers will be helpful.

Solution

How to identify default sample size of statistics?

I would quote from Old Docs article

Auto Update stats Algorithm:

So the Auto Update stats will fire for every 500 + 20% change in table
rows. Of course, we have an improved algorithm in SQL 2012 which is
SQRT(1000 * Table rows) which is much better.

When it fires it will use the default sampling rate and here is the
algorithm how it calculates the sampling rate.

-

If the table < 8MB then it updates the statistics with a


fullscan.

-

If the table > 8MB, it follows an algorithm. It reduces the


sampling rate as the number of rows in the table are increased to make
sure we are not scanning too much data. This is not a fixed value but
is under the control of optimizer. It is not a linear algorithm
either.

Example: if we have 1,000,000 rows it would use a sampling rate of 30%
but when the number of rows increase to 8,000,000 it would reduce the
sampling rate to 10%. These sampling rates are not under the DBAs
control but optimizer decides it.

To understand further I suggest you read

-
Auto Update Stats Default Sampling test By Joe Sack

-
Sample Size and Duration of Update Stats By Erin Stellato

Code Snippets

If the table < 8MB then it updates the statistics with a
If the table > 8MB, it follows an algorithm. It reduces the

Context

StackExchange Database Administrators Q#145712, answer score: 23

Revisions (0)

No revisions yet.