programming4us
programming4us
DATABASE

SQL Server 2008 : Managing Query Performance - Forcing a Specific Execution Plan

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Plan forcing was introduced in SQL Server 2005 to provide a way for you to supply an entire execution plan that SQL Server will use to execute a query. Plan forcing is useful when the query optimizer will not produce an optimal execution plan for a query, even though you know a better execution plan is available. If you have a query that performed better prior to an upgrade, you may be able to capture the old execution plan and force the optimizer to use it. You can supply the execution plan in XML format following a query by supplying the USE PLAN option, as shown in Listing 1.
Example 1. Syntax Used to Specify an Execution Plan by Supplying the USE PLAN Query Hint
SELECT *
FROM Table1
JOIN Table2
ON Table1.Column = Table2.Column
OPTION (USE PLAN 'N
<ShowPlanXML xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
...
</ShowPlanXML>')


In order to supply the execution plan, you must first capture it in XML format. There are a few ways you can capture the XML execution plan to supply the query.

  • You can use the SHOWPLAN_XML SET statement to return the XML execution plan instead of running the query, as shown in the following code:

    SET SHOWPLAN_XML ON
    GO

    SELECT * FROM Table
    SET SHOWPLAN_XML OFF
    GO

  • You can use the STATISTICS XML SET statement to return the XML execution plan following the query result set, as shown in the following code:

    SET STATISTICS XML ON
    GO

    SELECT * FROM Table
    SET STATISTICS XML OFF
    GO

  • You can use the query_plan column in the sys.dm_exec_query_plan Dynamic Management Function, as shown in the following query:

    SELECT est.text, eqp.query_plan
    FROM sys.dm_exec_cached_plans ecp
    CROSS APPLY sys.dm_exec_query_plan(ecp.plan_handle) eqp
    CROSS APPLY sys.dm_exec_sql_text(ecp.plan_handle) est

  • You can use the Showplan XML, Showplan XML Statistics Profile, and Showplan XML For Query Compile event classes in SQL Server Profiler.

  • You can use the Display Estimated Execution Plan and Include Actual Execution Plan options in SQL Server Management Studio; right-click the execution plan, and select Show Execution Plan XML from the context menu.

If the XML execution plan is invalid in any way, the query will fail. Certain underlying database schema changes may cause the execution plan to become invalid. Therefore, it is extremely important to test any queries that have the USE PLAN query hint after making database changes. Just as with any option you use to override the query optimizer, you should apply the USE PLAN query hint with extreme caution, and then only after you have exhausted your other options, such as creating proper indexes and updating statistics. Since the USE PLAN query hint forces a query to utilize a specified execution plan, the query optimizer will no longer be able to dynamically adjust to changes within the database.

Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us