SQL SERVER – Using Query Hint ENABLE_PARALLEL_PLAN_PREFERENCE

I am not a big fan of using SQL Server query hints. The matter of facts, during the Comprehensive Database Performance Health Check, I always advise against using any query hints at all. Trust me there are so many different options you should experiment before you opt for query hint. Recently one of the DBA asked me how to use query hint ENABLE_PARALLEL_PLAN_PREFERENCE.

SQL SERVER - Using Query Hint ENABLE_PARALLEL_PLAN_PREFERENCE queryhint-800x119

First of all, let me rephrase the original question. Instead of asking the question of how to use query hint ENABLE_PARALLEL_PLAN_PREFERENCE, I usually get a question about how to force SQL Server to go parallel with the queries and use parallelism.

Before I continue answering the question, let me say, one should not experiment with the query hint without a proper understanding of how the entire eco-system of your server works. I never force any of my queries to use ANY query hints.

Now let us see the following query and its actual execution plan.

SELECT i.AccountsPersonID, i.BillToCustomerID
FROM Sales.Invoices i
WHERE i.BillToCustomerID = 803
ORDER BY i.ConfirmedDeliveryTime
GO

The above query uses the single processor to run the query.

SQL SERVER - Using Query Hint ENABLE_PARALLEL_PLAN_PREFERENCE queryhint1

Here is the query with ENABLE_PARALLEL_PLAN_PREFERENCE.

SELECT i.AccountsPersonID, i.BillToCustomerID
FROM Sales.Invoices i
WHERE i.BillToCustomerID = 803
ORDER BY i.ConfirmedDeliveryTime
OPTION(USE HINT('ENABLE_PARALLEL_PLAN_PREFERENCE'))
GO

If you use query hint ENABLE_PARALLEL_PLAN_PREFERENCE, the query will run in parallel on multiple CPU.

SQL SERVER - Using Query Hint ENABLE_PARALLEL_PLAN_PREFERENCE queryhint2
Query Hint

However, please note that parallel operation is not necessarily faster or better operation. There is a good chance that in the parallel plan is even more expensive than a single processor plan.

Here are relevant blog posts which you may find interesting:

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

Parallel, Query Hint, SQL CPU, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Stop Using DBCC DBREINDEX and Use ALTER INDEX
Next Post
SQL SERVER – T-SQL Script to Identify TOP 10 Parallel Running Queries

Related Posts

4 Comments. Leave new

  • What versions does this work for Pinal?

    Reply
  • Well, it is quite simple. If a query seems to run slow and I try with this hint and it returns the results in milliseconds, then it is a good hint.
    I run a set of simple SQL statements on a fairly large table to check that all data is consistent, example “select * from some_table where name is null” and it was slow so I killed it after 10 seconds. Then I reran the same SQL with this hint ENABLE_PARALLEL_PLAN_PREFERENCE and it returned result in milliseconds. I don’t need to run any elaborate analysis or some thing like that to understand that it works well in this scenario.

    Reply
  • Michael D Petri
    December 29, 2022 4:58 am

    The downside with this approach is query execution time is how you are measuring success. What happens when another query comes along that performs slow? Add the hint? What about next year after you’ve deployed dozens of queries with the hint and your server is suffering massive resource contention (CPU, Memory, IO bottlenecks), deadlocks and timeouts? When that dreadful day comes, there is no easy button but rewriting expensive queries. Start when they crop up instead of pressing the “go fast” button. Try small changes, such as instead of SELECT * from SomeTable WHERE name IS NULL, try SELECT COUNT(1) FROM SomeTable WHERE name IS NULL. If the query is slow, look into your indexing and statistic refresh frequency. Measuring performance by how fast something runs must not be the only measurement in play.

    Reply

Leave a Reply