DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 2584903 - Last Review: June 5, 2012 - Revision: 5.0

On This Page

Microsoft distributes Microsoft SQL Server 2008 R2 SP1 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 SP1 fix release.

SYMPTOMS

Consider the following scenario:
  • A Management Data Warehouse (MDW) database has a snapshots.query_stats table that contains a large amount of data in Microsoft SQL Server 2008 or in Microsoft SQL Server 2008 R2.
  • You run the following Data Collector job to clear data from the MDW database.
    mdw_purge_data_[<MDW database name>]
In this scenario, it takes a long time for the Data Collector job to clear data.

Notes
  • The Data Collector job calls the core.sp_purge_data stored procedure to clear data.
  • For more information about this issue in SQL Server 2008 R2, visit the following Microsoft website:
    General information about this issue in SQL Server 2008 R2 (http://connect.microsoft.com/SQLServer/feedback/details/657148/management-data-warehouse-mdw-purge-job-proc-performance)

CAUSE

This issue occurs because the mdw_purge_data job takes a long time to perform a batch-oriented clear operation if the snapshots.query_stats table contains a large amount of data.

RESOLUTION

Service pack information

SQL Server 2008

To resolve this issue in SQL Server 2008, follow these steps:
  1. Obtain the latest service pack for SQL Server 2008.

    For more information, click the following article number to view the article in the Microsoft Knowledge Base:
    968382  (http://support.microsoft.com/kb/968382/ ) How to obtain the latest service pack for SQL Server 2008
  2. For an existing MDW database, you must update it by running the Configure Management Data Warehouse Wizard after you install the latest service pack for SQL Server 2008.


SQL Server 2008 R2

To resolve this issue in SQL Server 2008 R2, follow these steps:
  1. Obtain the latest service pack for SQL Server 2008 R2.

    For more information, click the following article number to view the article in the Microsoft Knowledge Base:
    2527041  (http://support.microsoft.com/kb/2527041/ ) How to obtain the latest service pack for SQL Server 2008 R2
  2. For an existing MDW database, you must update it by running the Configure Management Data Warehouse Wizard after you install the latest service pack for SQL Server 2008 R2
  3. Update the sp_purge_orphaned_notable_query_text stored procedure as follows:

    Existing procedure

    -- Deleting TOP N orphaned rows in query plan table by joining info from temp table variable
    -- This is done to speed up delete query. 
    DELETE TOP (@delete_batch_size) snapshots.notable_query_plan 
    FROM snapshots.notable_query_plan AS qp , #tmp_notable_query_plan AS tmp
    WHERE tmp.[sql_handle] = qp.[sql_handle]
    Updated procedure

    -- Deleting TOP N orphaned rows in query text table by joining info from temp table
    -- This is done to speed up delete query. 
    DELETE TOP (@delete_batch_size) snapshots.notable_query_text 
    FROM snapshots.notable_query_text AS qt, #tmp_notable_query_text AS tmp
    WHERE tmp.[sql_handle] = qt.[sql_handle]
    Note These changes are required to correct the text of the sp_purge_orphaned_notable_query_text stored procedure because the delete statement incorrectly references the snapshots.notable_query_plan table after you apply SQL Server 2008 R2 Service Pack 1.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

The complete script to update the data collector stored procedure can also be found in the following blog:
http://blogs.msdn.com/b/sqlagent/archive/2011/04/12/data-collector-s-sp-purge-data-may-run-for-hours-if-there-are-many-orphaned-plans-to-purge.aspx (http://blogs.msdn.com/b/sqlagent/archive/2011/04/12/data-collector-s-sp-purge-data-may-run-for-hours-if-there-are-many-orphaned-plans-to-purge.aspx)



APPLIES TO
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 R2 Datacenter
  • Microsoft SQL Server 2008 R2 Developer
  • Microsoft SQL Server 2008 R2 Enterprise
  • Microsoft SQL Server 2008 R2 Standard
Keywords: 
kbqfe kbexpertiseadvanced kbsurveynew kbfix KB2584903
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support