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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Substituting the username will enable the user to view execution plans for that database.<br />

Additionally, in order to run the queries against the DMOs, either VIEW SERVER STATE<br />

or VIEW DATABASE STATE, depending on the DMO in question, will be required.<br />

Working with graphical execution plans<br />

In order to focus on the basics of capturing estimated and actual execution plans, the first<br />

query will be one of the simplest possible queries, and we'll build from there. Open up<br />

Management Studio and in a query window, type the following:<br />

SELECT *<br />

FROM dbo.DatabaseLog;<br />

Listing 1.4<br />

Getting the estimated plan<br />

We'll start by viewing the graphical estimated execution plan that the query optimizer<br />

generated, so there's no need to run the query yet.<br />

We can find out what the optimizer estimates to be the least costly plan in one of<br />

following ways:<br />

• Click on the Display Estimated <strong>Execution</strong> Plan icon on the tool bar.<br />

• Right-click the query window and select the same option from the menu.<br />

• Click on the Query option in the menu bar and select the same choice.<br />

• Hit CTRL+L on the keyboard.<br />

32

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

Saved successfully!

Ooh no, something went wrong!