Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid the SQL Server's "rebuild statistics" when doing performance testing?

I'm doing some SQL tuning these days and find one weird sql during the test:

SELECT StatMan([SC0],[SC1], [SB0000]) 
FROM (SELECT TOP 100 PERCENT [SC0],[SC1], step_direction([SC0]) over (order by NULL) AS [SB0000]  
      FROM (SELECT [tableA] AS [SC0],[tableB] AS [SC1] 
            FROM [dbo].[url] WITH (READUNCOMMITTED,SAMPLE 3.408654e+000 PERCENT) 
           ) AS _MS_UPDSTATS_TBL_HELPER 
     ORDER BY [SC0],[SC1], [SB0000] 
    ) AS _MS_UPDSTATS_TBL  
OPTION (MAXDOP 1)

Looks this is doing some "reindex" or "rebuild" some db index according to SQL Server. But my question is how can we avoid this during the long load test besides "reindex" for each tables before the testing.

And this SQL will consume 16862ms because of my table contains enough rows. And there are many insert action in my test.

like image 730
Vance Avatar asked Mar 09 '11 14:03

Vance


People also ask

Does SQL Server update statistics automatically?

By default, each SQL Server and Azure SQL Database has enabled Automatic statistics updates.

How update statistics improves performance of a query?

Updating statistics ensures that queries compile with up-to-date statistics. Updating statistics via any process may cause query plans to recompile automatically.

What is performance issue in SQL Server?

MS SQL faces performance issues while executing queries and working within SQL environment in a regular routine. There are many issues that you must be dealing with such as poor queries, slow processing, indexes with tons of writes and reads, memory or CPU issues.


1 Answers

This seems to be from updating statistics.

Will updating statistics happen in a normal production environment? If so, shouldn't a load test, to reflect a production environment, update statistics as well?

To turn off the AUTO_UPDATE_STATISTICS option, use sp_autostats on the desired table(s) (see http://msdn.microsoft.com/en-us/library/ms188775.aspx ).

like image 184
Enull Avatar answered Nov 04 '22 01:11

Enull