HI Friends,
We know about parallelism in SQL Server i.e. SQL Server uses multiple threads for the processing of a request to make it faster. Two main important settings for the decision of going with parallelism are:
MAXDOP: Maximum degree of parallelism, This value represents, how many threads can be used for parallel processing.
The Cost threshold for parallelism: if any estimated query plan cost crossed this value, then the SQL Server optimizer will try to make that plan parallel.
Now come back to our topic, Reserved threads and Used threads in parallelism. Let’s say I have submitted a query to the SQL Server and estimated cost of this query has been crossed the value of cost threshold for parallelism. SQL Server has been decided to execute that query using parallelism. In my test system, MAXDOP is set to default. That means SQL Server can use all the processors for parallel operations, assign to it i.e. 4. I have set the value 0 for cost threshold for parallelism just to use the parallelism for every query (keep in mind this is just for demo). By default, SQL Server uses threads to perform its task and these tasks run on schedulers.
Like many other resources, SQL Server also reserved the number of threads. Let me show you the execution plan of below query on Adventure Works 2014 Database :
SELECT [SalesOrderID] ,[SalesOrderDetailID] ,[CarrierTrackingNumber] ,[OrderQty] ,[ProductID] ,[SpecialOfferID] ,[UnitPrice] ,[UnitPriceDiscount] ,[LineTotal] ,[rowguid] ,[ModifiedDate] FROM [AdventureWorks2014].[Sales].[SalesOrderDetail] ORDER BY ModifiedDate DESC
Now you can just right click on the select node and go to the properties:
In the above Properties, you can see that SQL Server uses Degree of Parallelism to 2. Also count the branch for this execution which is 1. Number of reserved threads and used threads are 2.
Keep in mind that number of reserved or used threads are not always equal to the value of MAXDOP for the query. Let me show you:
Select SOD.SalesOrderID, SOD.UnitPrice, SOD.LineTotal, SOH.TotalDue, SOH.DueDate, SOH.OrderDate from [Sales].[SalesOrderDetail] SOD inner join [Sales].[SalesOrderHeader] SOH on sod.SalesOrderID=SOH.SalesOrderID ORDER BY SOH.TotalDue DESC
Now you can just right click on the select node and go to the properties:
In the above Properties, you can see that SQL Server uses Degree of Parallelism 4. Here branch count for this execution is 2. Number of reserved threads and used threads are 8.
HAPPY LEARNING!
Regards:
Prince Kumar Rastogi
Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook
Follow Prince Rastogi on Twitter | Follow Prince Rastogi on FaceBook