Symptoms
Assume that you use the AlwaysOn Availability Groups feature in Microsoft SQL Server 2012, 2014, or 2016. Every time you execute a query against a secondary database, the query is recompiled. This issue occurs because the statistics are not propagated correctly from the primary server to the secondary server. If you run the profiler trace, you will find something similar with the following about StatMan which means SQL server is querying statistics:
SELECT StatMan([SC0], [SB0000]) FROM (SELECT TOP 100 PERCENT [SC0], step_direction([SC0]) over (order by NULL) AS [SB0000] FROM (SELECT [xxx] AS [SC0] FROM [dbo].[xxx] TABLESAMPLE SYSTEM (7.033584e-001 PERCENT) WITH (READUNCOMMITTED) ) AS _MS_UPDSTATS_TBL_HELPER ORDER BY [SC0], [SB0000] ) AS _MS_UPDSTATS_TBL OPTION (MAXDOP 1)
Note If you disable the Auto Update Statistics option or enable the Auto Update Statistics Asynchronously option, this issue does not occur.
Resolution
The issue was first fixed in the following cumulative update of SQL Server:
- Cumulative Update 2 SQL Server 2016 SP1
- Cumulative Update 4 for SQL Server 2016
- Cumulative update 3 for SQL Server 2014 SP2
- Cumulative Update 8 for SQL Server 2014 SP1
- Cumulative Update 5 for SQL Server 2012 Service Pack 3 (SP3)
Recommendation: Install the latest cumulative update for SQL Server
Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. We recommend that you download and install the latest cumulative updates for SQL Server:
- Latest cumulative update for SQL Server 2016
- Latest cumulative update for SQL Server 2012 SP3
- Latest cumulative update for SQL Server 2014 SP1/SP2
References
Learn about the terminology that Microsoft uses to describe software updates.