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 2: Graphical <strong>Execution</strong> <strong>Plans</strong> for Basic Queries<br />

This plan may be a little difficult to read on the printed page. Please execute the<br />

code on your own machine in order to see the plan clearly, and follow along with the<br />

explanations.<br />

Figure 2.34<br />

The physical structures of the tables the query accesses can affect the resulting execution<br />

plans. For example, this table has an IDENTITY column, FOREIGN KEY constraints and a<br />

spatial data column. All these objects will affect the execution plan.<br />

The physical operation of the execution plan starts off, reading right to left, with an<br />

operator that is new to us: Constant Scan. This operator introduces a constant number<br />

of rows into a query. In our case, it's building a row in order for the next two operators to<br />

have a place to add their output. The first of these is a Compute Scalar operator to call a<br />

function called getidentity. This is the point within the query plan when <strong>SQL</strong> <strong>Server</strong><br />

generates an identity value, for the data to follow. Note that this is the first operation<br />

within the plan, which helps explain why, when an INSERT fails, you get a gap in the<br />

identity values for a table.<br />

The next Scalar operation creates a series of placeholders for the rest of the data and<br />

creates the new uniqueidentifier value, and the date and time from the GETDATE<br />

function. You can tell this is what happens by looking at the Property sheet for the<br />

operator and then looking at the Defined Values property. There is an ellipsis next to that<br />

property which, when clicked, will open a window showing what is being built by the<br />

Compute Scalar operation as shown in Figure 2.35.<br />

110

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

Saved successfully!

Ooh no, something went wrong!