Sample Header Ad - 728x90

Sampled Statistics Percentage Internal Calculation

6 votes
1 answer
315 views
When SQL Server builds *sampled* statistics, how is the sampling percentage calculated? For example, updating statistics on the *PostId* column of the *dbo.Votes* table in the Stack Overflow 2013 database:
UPDATE STATISTICS dbo.Votes
(
    _WA_Sys_00000002_0AD2A005
) 
WITH MAXDOP = 1;
SQL Server builds an internal statement:
SELECT 
    StatMan
    (
        [SC0], 
        [SB0000]
    ) 
    FROM 
    (
        SELECT TOP 100 PERCENT 
            [SC0], 
            step_direction([SC0]) over (order by NULL) AS [SB0000]  
        FROM 
        (
            SELECT [PostId] AS [SC0] 
            FROM [dbo].[Votes] 
                TABLESAMPLE SYSTEM (9.234204e-01 PERCENT) 
                WITH (READUNCOMMITTED) 
        ) AS _MS_UPDSTATS_TBL_HELPER 
        ORDER BY 
            [SC0], 
            [SB0000] 
    ) AS _MS_UPDSTATS_TBL  
OPTION (MAXDOP 1)
Where does the 9.234204e-01 PERCENT come from?
Asked by Paul White (95105 rep)
May 22, 2024, 03:24 PM