Does Parallel Threads Process Equal Rows? – Interview Question of the Week #211

Question: Does Parallel Threads Process Equal Rows?

Answer: No. (Well usually no). I received the same question during the Comprehensive Database Performance Health Check. Here is the simple proof running the following query:

Does Parallel Threads Process Equal Rows? - Interview Question of the Week #211 parallelthreads

SELECT [SalesOrderID]
,[SalesOrderDetailID]
,[CarrierTrackingNumber]
,[OrderQty]
,[ProductID]
,[SpecialOfferID]
,[UnitPrice]
,[UnitPriceDiscount]
,[LineTotal]
,[rowguid]
,[ModifiedDate]
FROM [AdventureWorks2014].[Sales].[SalesOrderDetail]
ORDER BY [UnitPriceDiscount]

When you run the above query, make sure you enable the actual execution plan (CTRL+M), it will give following execution plan. The execution plan will open a property bar on the right side.

Does Parallel Threads Process Equal Rows? - Interview Question of the Week #211 parallel

You can see that there is a Clustered Index Scan operator. Click on the operator and right-click over it and select Properties. Over here expand the row Actual Number of Rows. Under this tab, there are multiple rows marked with Thread 0, Thread 1, Thread 2 and so on. On the right side of the Threads, you can see the rows on the side which are not equal at all.

Many think that when the operators which can go parallel divides the total number of rows in the equal number of the rows, which is not correct as we have seen in this example.

I hope this answer Does Parallel Threads Process Equal Rows question. Let me know if you already knew this information or is it new information for you as well.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Execution Plan, Parallel, SQL Scripts, SQL Server, SQL Statistics
Previous Post
What is Trusted Constraint in SQL Server? – Interview Question of the Week #210
Next Post
What is Consolidation of Index? – Interview Question of the Week #212

Related Posts

1 Comment. Leave new

Leave a Reply