patternsqlMajor
Parallel Statistics Update
Viewed 0 times
statisticsparallelupdate
Problem
In SQL Server 2008 or later, is
UPDATE STATISTICS WITH FULLSCAN a single threaded operation or it can use parallelism? How about update statistics with default sampling - can it use parallelism? I don't see an option specifying MAXDOP with update stats.Solution
Parallel statistics update has been available since SQL Server 2005. It is documented in the TechNet article, "Statistics Used by the Query Optimizer in Microsoft SQL Server 2005":
Where a full scan is performed (whether explicitly requested or not) the internal query generated for the data-gathering has the general form:
Notice the
If you ever need to reduce the parallelism, the
SQL Server 2016 adds parallel sampled statistics update.
Where a full scan is performed (whether explicitly requested or not) the internal query generated for the data-gathering has the general form:
SELECT
StatMan([SC0])
FROM
(
SELECT TOP 100 PERCENT
[Column] AS [SC0]
FROM [Table] WITH (READUNCOMMITTED)
ORDER BY [SC0]
) AS _MS_UPDSTATS_TBL
OPTION (MAXDOP 16)Notice the
MAXDOP hint there (though there is no way for a user to specify the hint manually). Where sampled statistics are gathered, the internal query uses the TABLESAMPLE clause, which prevents parallelism. The engine also generates a MAXDOP 1 hint on the internal query, which is a bit redundant.If you ever need to reduce the parallelism, the
MAXDOP hint in the internal query can be overridden using Resource Governor (Enterprise only).SQL Server 2016 adds parallel sampled statistics update.
Code Snippets
SELECT
StatMan([SC0])
FROM
(
SELECT TOP 100 PERCENT
[Column] AS [SC0]
FROM [Table] WITH (READUNCOMMITTED)
ORDER BY [SC0]
) AS _MS_UPDSTATS_TBL
OPTION (MAXDOP 16)Context
StackExchange Database Administrators Q#20387, answer score: 22
Revisions (0)
No revisions yet.