WAIT_ON_SYNC_STATISTICS_REFRESH

(Republishing, or using this info in a commercial product/website, is prohibited without permission. All other uses are permitted. If in doubt, please ask.)

(Back to main page…)

Description:

Exactly as the Books Online description describes. This wait type was added so you can see how long a synchronous statistics update takes. Note that this is a preemptive wait, so the thread continues executing on the processor until the statistics update is complete.

(Books Online description: “Occurs when waiting for synchronous statistics update to complete before query compilation and execution can resume.”)

Questions/comments on this wait type? Click here to send Paul an email, especially if you have any information to add to this topic.

Added in SQL Server version:

2019

Removed in SQL Server version:

N/A

Extended Events wait_type value:

The map_key value in sys.dm_xe_map_values is 1329  in 2019 RTM. You must check the DMV to get the latest value as some map_key values have changed in later builds.

Other information:

How long a query will have to wait for a synchronous statistics update to complete before it can compile and execute, depends on things like:

  • How many tables in the query have statistics that need to be refreshed
  • How many statistics have to be refreshed on each table
  • The number of rows in each table
  • The options specified when creating the statistic (e.g. FULLSCAN)

This delay is likely to be more problematic for queries involving very large, volatile tables.

Ways to eliminate or reduce this delay:

  • Enable asynchronous statistics updates
  • Disable any automatic statistics updates and perform your own regular statistics maintenance
  • Avoid using the FULLSCAN option on statistics on large tables

Known occurrences in SQL Server (list number matches call stack list):

  1. 1-3 – various examples of this wait occurring while the actual statistics update occurs.

And many other similar call stacks.

Abbreviated call stacks (list number matches known occurrences list):

  1. SOS_Task::PopWait+0xf7
    SOS_ExternalAutoWait::~SOS_ExternalAutoWait+0x5f
    CTableMetadata::UpdateStatistics+0x501
    CTableMetadata::StatsRefresh+0x40f
    CTableMetadata::PStatManUpdateAndLoad+0x3e
    CTableMetadata::PdstrhstLoadHistogram+0xd2
    CGlobalHistogramCache::PdstrhstLoad+0x28e
    CStCollBaseTable::PdstrhstGetHistogramInternal+0x4b3
    CStCollAbstractLeaf::FCardDistinctSingleColumn+0x18f
    CStCollAbstractLeaf::CardDistinctImpl+0x587
    IStatsCollection::CardDistinct+0xbd
    CStCollFilter::CardDistinctImpl+0x101
    IStatsCollection::CardDistinct+0xbd
    CStCollJoin::CardDistinct_OneSided+0x1f9
    CStCollOuterJoin::CardDistinctImpl+0x1ea
    IStatsCollection::CardDistinct+0xbd
    CSelCalcSimpleJoinWithDistinctCounts::FCalculate+0x1b3
    CCardUtilSQL12::ProbCalculateJoin+0x2bf
    CLogOp_BaseJoin::PstcollDeriveCardinality+0x5ce
    CCardFrameworkSQL12::DeriveCardinalityProperties+0x41d
    CLogOpArg::DeriveGroupProperties+0xd93
    COpArg::DeriveNormalizedGroupProperties+0x24e
  2. SOS_Task::PopWait+0xf7
    SOS_ExternalAutoWait::~SOS_ExternalAutoWait+0x5f
    CTableMetadata::UpdateStatistics+0x501
    CTableMetadata::StatsRefresh+0x40f
    CTableMetadata::PStatManUpdateAndLoad+0x3e
    CTableMetadata::PdstrhstLoadHistogram+0xd2
    CGlobalHistogramCache::PdstrhstLoad+0x28e
    CStCollBaseTable::PdstrhstGetHistogramInternal+0x4b3
    CStCollAbstractLeaf::PdstrhstGetHistogram+0x1b
    CSelCalcColumnInInterval::PdstrhstLoad+0x33a
    CSelCalcColumnInInterval::FCalculate+0xb1
    CSelCalcCombineFilters::FCalculate+0x9d
    CCardUtilSQL12::ProbCalculateFilter+0x193
    CLogOp_Select::PstcollDeriveCardinality+0x27c
    CCardFrameworkSQL12::DeriveCardinalityProperties+0x41d
    CLogOpArg::DeriveGroupProperties+0xd93
    COpArg::DeriveNormalizedGroupProperties+0x24e
    COptExpr::DeriveGroupProperties+0x15b
  3. SOS_Task::PopWait+0xf7
    SOS_ExternalAutoWait::~SOS_ExternalAutoWait+0x5f
    CTableMetadata::UpdateStatistics+0x501
    CTableMetadata::StatsRefresh+0x40f
    CTableMetadata::PStatManUpdateAndLoad+0x3e
    CTableMetadata::PdstrhstLoadHistogram+0xd2
    CGlobalHistogramCache::PdstrhstLoad+0x28e
    CStCollBaseTable::PdstrhstGetHistogramInternal+0x4b3
    CStCollAbstractLeaf::PdstrhstGetHistogram+0x1b
    CStCollFilter::PdstrhstGetHistogram+0x16b
    CScalarStatsInfo::PdstrhstGetInputHistogramByPvr+0x9b
    CScalarStatsInfo::PdstrhstCreateHistogram+0x63
    CCardUtilSQL12::FGetHistogramsForFunctionComparisonJoin+0x1fd
    CSelCalcExpressionComparedToExpression::FCalculate+0x189
    CCardUtilSQL12::ProbCalculateJoin+0x2bf
    CLogOp_BaseJoin::PstcollDeriveCardinality+0x5ce
    CCardFrameworkSQL12::DeriveCardinalityProperties+0x41d
    CLogOpArg::DeriveGroupProperties+0xd93
    COpArg::DeriveNormalizedGroupProperties+0x24e
    COptExpr::DeriveGroupProperties+0x15b