STATMAN queries causing you timeouts?

If you have a query executing having unexpected slowness or timeouts but at the same time you see queries referencing statman, you might be running into an issue of synchronous statistics updates.

By default SQL Server performs automatic statistics updates synchronously.  This means when the threshold for requiring a statistics update is reached statistics are updated synchronously.  SQL Server does not update statistics immediately after the threshold was reached, instead it performs this when a query touches the table.  This causes the request to wait for the statistics to be updated prior to it compiling a plan.

In SQL Server 2019 you will see your query running with the following wait type: WAIT_ON_SYNC_STATISTICS_REFRESH.  Unfortunately prior to SQL Server 2019 you’ll need to spot this by looking for any statman queries running against the tables involved in the query experiencing slowness.

Fixing the problem

You can fix this problem by enabling AUTO_UPDATE_STATISTICS_ASYNC:


Of course this means your queries might run with stale statistics, but if the performance drawback outweighs that of briefly stale statistics it is probably worth the change.