Microsoft KB Archive/917828

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

Article ID: 917828

Article Last Modified on 7/30/2007

-

APPLIES TO


 * Microsoft SQL Server 2005 Standard Edition
 * Microsoft SQL Server 2005 Developer Edition
 * Microsoft SQL Server 2005 Enterprise Edition
 * Microsoft SQL Server 2005 Workgroup Edition
 * Microsoft SQL Server 2005 Express Edition
 * Microsoft SQL Server 2005 Express Edition with Advanced Services

-



Bug #: 329155 (SQLBUDT)



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.



Starting with SQL Server 2005 Service Pack 2, you will notice messages such as the following in the SQL Server Errorlog when the issue occurs:

2006-10-15 06:03:29.330 spid59 SQL Server has encountered 4 occurrence(s) of cachestore flush for the 'Object Plans' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.

2006-10-15 06:03:29.420 spid59 SQL Server has encountered 4 occurrence(s) of cachestore flush for the 'SQL Plans' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.

2006-10-15 06:03:29.420 spid59 SQL Server has encountered 4 occurrence(s) of cachestore flush for the 'Bound Trees' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.

However, you can run the DBCC FREEPROCCACHE command or the DBCC FREESYSTEMCACHE command to flush the procedure cache. If the procedure cache is flushed by running one of these commands, you will notice messages that resemble the following in the SQL Server Errorlog:

2006-12-14 11:37:03.57 spid53 SQL Server has encountered 1 occurrence(s) of cachestore flush for the 'SQL Plans' cachestore (part of plan cache) due to 'DBCC FREEPROCCACHE' or 'DBCC FREESYSTEMCACHE' operations.

2006-12-14 11:37:03.57 spid53 SQL Server has encountered 1 occurrence(s) of cachestore flush for the 'Bound Trees' cachestore (part of plan cache) due to 'DBCC FREEPROCCACHE' or 'DBCC FREESYSTEMCACHE' operations.

Therefore, you can examine the SQL Server Errorlog to determine whether the issue is caused by the problem that is described in this article.



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

Performance object: SQLServer:Plan Cache

Counter: Cache Pages

Instance: _Total

The values of these counters will suddenly decrease.

Note For a named instance of SQL Server 2005, the performance object is named MSSQL$ :Plan Cache.
 * 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$ : 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:

&quot;Entire Procedure Cache Flushed&quot;

Keywords: kbsql2005engine kbexpertiseadvanced kbtshoot kbprb KB917828

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.