30.06.2013 Views

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1: <strong>Execution</strong> Plan Basics<br />

• changing the structure or schema of temporary tables used by the query<br />

• changes to dynamic views used by the query<br />

• changes to cursor options within the query<br />

• changes to a remote rowset, like in a distributed partitioned view<br />

• when using client-side cursors, if the FOR BROWSE options are changed.<br />

Clearing <strong>Plans</strong> from the Plan Cache<br />

Since the cache plays such an important role in how execution plans operate, you need a<br />

few tools for querying and working with the plan cache. First off, while testing, you may<br />

want to see how long a plan takes to compile, or to investigate how minor adjustments<br />

might create slightly different plans. To clear the cache, run this:<br />

DBCC FREEPROCCACHE<br />

Listing 1.2<br />

WARNING: Clearing the cache in a production environment<br />

Running Listing 1.2 in a production environment will clear the cache for all databases on the server. That<br />

can result in a significant performance hit because <strong>SQL</strong> <strong>Server</strong> must then recreate every single plan stored<br />

in the plan cache, as if the plans were never there and the queries were being run for the first time ever.<br />

While working with an individual query, it's usually better to target that query to remove<br />

just it from the plan cache. You can use DBCC FREEPROCCACHE and pass either the<br />

sql_handle or plan_handle to remove just the referenced plan. The plan_handle<br />

and sql_handle are available from various DMO objects (see the section on DMOs).<br />

28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!