Kt100.gifwww.grumpyolddba.co.uk

 

Microsoft kb article 917828

 

http://support.microsoft.com/kb/917828

 

You may experience a decrease in query performance after you perform certain database maintenance operations or regular transaction operations in SQL Server 2005

 

KB 917828

Last Review : July 30, 2007

 

SYMPTOMS

In Microsoft SQL Server 2005, you may experience a decrease in query performance after you perform certain database maintenance operations or regular transaction operations. For example, you may notice a sudden decrease in query performance after you restore a database backup.

 

CAUSE

This issue occurs because certain database maintenance operations or regular transaction operations clear the whole procedure cache.

 

STATUS

This behavior is by design.

 

MORE INFORMATION

The whole procedure cache is cleared when certain database level operations are performed in the following scenarios:

 

A database has the AUTO_CLOSE database option set to ON. When no user connection references or uses the database, the background task tries to close and shut down the database automatically.

You run several queries against a database that has default options. Then, the database is dropped.

A database snapshot for a source database is dropped.

Note Database snapshots are only available in Microsoft SQL Server 2005 Enterprise Edition.

You change the database state to OFFLINE or ONLINE.

You successfully rebuild the transaction log for a database.

You restore a database backup.

You run the DBCC CHECKDB statement.

Note This is true only in versions of SQL Server 2005 that are earlier than SQL Server 2005 SP2. After you install SQL Server 2005 SP2 or later versions, the whole procedure cache is not flushed when you run the DBCC CHECKDB statement.

You detach a database.

You specify one of the following options when you run the ALTER DATABASE statement:

OFFLINE

ONLINE

MODIFY FILEGROUP DEFAULT

MODIFY_NAME

MODIFY FILEGROUP READ_WRITE

COLLATE

MODIFY FILEGROUP READ_ONLY

READ_ONLY

READ_WRITE

If you experience this issue, you notice changes in the following values when you use Performance Monitor to collect data from SQL Server 2005 performance counters:

 

Performance object: Process
Counter: %Processor Time
Instance: sqlservr

The value of this counter will increase because of increased CPU activity. Essentially, the whole procedure cache is cleared if this issue occurs. Therefore, subsequent requests must generate new plans to be cached. This behavior will slightly increase CPU activity

Performance object: SQLServer:Plan Cache
Counter: Cache Object Counts
Instance: _Total

The values of this counter will suddenly decrease

Performance object: SQLServer:Plan Cache
Counter: Cache Pages
Instance: _Total

The values of this counter will suddenly decrease

Performance object: SQLServer:SQL Statistics
Counter: SQLCompilations/sec

The value of this counter will significantly increase after this incident

Note For a named instance of SQL Server 2005, the performance object is named MSSQL$InstanceName: SQL Statistics.

 

 

If you capture a SQL Profiler Trace by using the SP:CacheRemove event, you notice that this event is generated together with the following TextData column value when this issue occurs:

"Entire Procedure Cache Flushed"