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 8: Advanced Topics<br />

The data passes on to a Parallelism operator, which is the Repartition Streams operator.<br />

This operator is responsible for balancing the streams, trying to make sure that a roughly<br />

equal amount of work is performed by each stream. As you can see in Figure 8.7, the rows<br />

that were retrieved by the streams running in the Clustered Index Scan were retrieved<br />

at different rates by the various streams. This gets rebalanced by the Repartition Streams<br />

operator. It's also possible for this operator to reduce the number of rows, but that's<br />

not the case here. You can see this rebalancing in the operator ToolTip on display in<br />

Figure 8.8.<br />

Look at the top of Figure 8.8, at the Actual Number of Rows property. Note how the<br />

threads have been better balanced out with a roughly even distribution of rows among<br />

them. The idea here is to make each thread do an equal amount of work so that no thread<br />

is waiting too long on the others. You begin to see where the added overhead of parallelism<br />

comes to play. You have to be dealing with quite large volumes of data for this to be<br />

beneficial. The amount of work that it takes to split the streams, balance the streams, and<br />

then bring them all back together can be quite costly. If only a few rows are involved, then<br />

that cost can far outweigh the benefits of putting multiple CPUs to work on the query.<br />

The next several operators after the Repartition Streams operator in Figure 8.5 are<br />

quite common and we covered them in previous chapters. Each one, in this instance,<br />

is operating as a Parallel operator as designated by the yellow icon. Each of these<br />

operators shows how it's processing the data through a set of streams in its output l<br />

isting. The next interesting operator is the final one, right before the Select operator,<br />

the Parallelism Gather Streams operator. This operator is self-explanatory. It pulls the<br />

streams back together in order to present the data gathered by the process as a single<br />

dataset to the query or operator calling it. The output from this operator is now a single<br />

thread of information.<br />

303

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

Saved successfully!

Ooh no, something went wrong!