• Library
  • Sample DBs
  • RU
  • About
Home » query plan » SQL Server 2017: How to Get a Parallel Plan

SQL Server 2017: How to Get a Parallel Plan

Posted on May 11, 2017 by Dmitry Pilugin Posted in query plan, SQL Server 2017
download as a pdf file PDF

SQL Server chooses parallel plans based on the costing (there are also some other factors that should be met for the plan that it can go parallel). Sometimes serial plan is slightly cheaper than a parallel, so it is assumed to be faster and picked by the optimizer, however, because the costing model is just a model it is not always true (for a number of reasons, enlisted in Paul’s article below) and parallel plan runs much faster.

There was one way to force parallel plan prior to SQL Server 2017, described by Paul White (b|t) in his post Forcing a Parallel Query Execution Plan. This method uses the undocumented trace flag 8649.

Let’s look at the example. I use sample MS database AdventureworksDW2016CTP3.

use [AdventureworksDW2016CTP3];
go
set showplan_xml on;
go
select
	fis.SalesAmount,
	dd.CalendarYear
from 
	dbo.FactInternetSales fis
	join dbo.DimDate dd on dd.DateKey = fis.OrderDateKey;

select
	fis.SalesAmount,
	dd.CalendarYear
from 
	dbo.FactInternetSales fis
	join dbo.DimDate dd on dd.DateKey = fis.OrderDateKey
option(querytraceon 8649);
go
set showplan_xml off;
go

The plans are:

You see that by default the plan is seral (first plan), if we apply the trace flag 8649 the plan goes parallel (second plan).

SQL Server 2017

In the new version of SQL Server which is now branded as SQL Server 2017 there is one more way to force parallel plan, that involves using the undocumented hint ENABLE_PARALLEL_PLAN_PREFERENCE.

Unfortunately, I have no information will it be documented some time or not, but I hope it will be.

Let’s look at the example:

set showplan_xml on;
go
select
	fis.SalesAmount,
	dd.CalendarYear
from 
	dbo.FactInternetSales fis
	join dbo.DimDate dd on dd.DateKey = fis.OrderDateKey
option(use hint('ENABLE_PARALLEL_PLAN_PREFERENCE'));
go
set showplan_xml off;
go

You may see that a query plan with this hint also goes parallel.

That’s all for that post. Thank you for reading!

download as a pdf file PDF
ENABLE_PARALLEL_PLAN_PREFERENCE parallelism use hint
« SQL Server 2017: Statistics to Compile a Query Plan
SQL Server 2017: Adaptive Join Internals »

Recent Posts

  • SQL Server 2017: Adaptive Join Internals
  • SQL Server 2017: How to Get a Parallel Plan
  • SQL Server 2017: Statistics to Compile a Query Plan
  • SQL Server 2017: Sort, Spill, Memory and Adaptive Memory Grant Feedback
  • SQL Server vNext: Interleaved Execution for mTVF

Archives

  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • July 2016
  • February 2016
  • December 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • May 2014

Tags

adaptive query processing allocation order scan Ascending Key bailout bitmap bug cardinality columnstore estimation process hash join model mtvf nolock partitioning plan construction Post Optimization Rewrite PQTEConvert query optimizer query_trace_column_values rules sniffing spill sql server 2017 statistics TF 2312 TF 2329 TF 2340 TF 2363 TF 2389 TF 2390 TF 2486 TF 7357 TF 7359 TF 8628 TF 8744 TF 9115 TF 9481 TF 9482 TF 9483 TF 9488 TF 9489 top uncommited version vnext
© Dmitry Pilugin (SomewhereSomehow), 2014 - 2017