0

I have a procedure with two SELECTs. One statement respects the server's/database's/query hint's maxdop setting and uses parallelism, the other is being difficult and never going parallel.

The 8 core server and this db are configured for maxdop 0 (not great, and I can change it, but I'd like to leave it and figure out what's going on). Cost threshold is 5.

Auto update stats is on and stats on the table are showing as being updated earlier today. I may try updating the stats on the table manually after hours tonight.

This server and db are an AG secondary replica. The same procedure on the primary runs fast and both statements go parallel. The primary has more cores, and its maxdop is set explicitly to to 8.

Statement 1 query hints

  • No query hint -> DegreeOfParallelism = 1
  • Maxdop 0 -> DegreeOfParallelism = 1
  • Maxdop 1 -> DegreeOfParallelism = 0 (reason MaxDopSetToOne)
  • Maxdop 8 -> DegreeOfParallelism = 1
  • Maxdop 7 -> DegreeOfParallelism = 1

Statement 2 query hints

  • No query hint -> DegreeOfParallelism = 8
  • Maxdop 0 -> DegreeOfParallelism = 8
  • Maxdop 1 -> DegreeOfParallelism = 0 (reason MaxDopSetToOne)
  • Maxdop 8 -> DegreeOfParallelism = 8
  • Maxdop 7 -> DegreeOfParallelism = 7

Thanks for any help!

3
  • What does the statement 1 plan say for NonParallelPlanReason? Commented Jan 24, 2022 at 21:37
  • @ErikDarling That was only for the one which has MAXDOP 1. The others it doesn't say Commented Jan 25, 2022 at 0:36
  • @Charlieface The only test of Statement 1 that shows the NoParallelPlanReason xml node is maxdop 1, and that reason is MaxDopSetToOne.
    – Bobogator
    Commented Jan 25, 2022 at 21:54

1 Answer 1

0

it's maxdop, not mindop

Setting MAXDOP at any level only sets an upper limit on how parallel a query can go. It does not instruct a query to go parallel; a query still has to:

  • Have the estimated cost qualify it for a parallel plan
  • Not be a trivial plan
  • Not have any constructs that force it to run single-threaded (scalar UDFs, inserting into a @table variable, etc.)
  • Have the parallel plan's estimated cost be lower than the serial plan's estimated cost

enforcer

If you want to try to force a parallel plan, you'll need to

  • Use trace flag 8649 at the session or query level as a hint
  • If you're on a newer version of SQL Server, you can use the ENABLE_PARALLEL_PLAN_PREFERENCE USE hint.

It should be noted here that neither of those options is officially supported, and should probably only be used for testing and experimentation.

This would probably be the most enlightening thing for you, though, since it will show you the estimated cost of a parallel plan and if it's higher than the serial plan's estimated cost, or if there's still something locally inhibiting parallelism.

3
  • Thanks Erik! Big fan. :-)
    – Bobogator
    Commented Jan 24, 2022 at 20:36
  • (edit timed out) Don't think it's a trivial plan, since the same statement runs parallel on the primary replica. Simple select with two tables into temp table (not table variable). Serial plan's cpu cost for the statement is 93.7824 (runtime 40 seconds), using ENABLE_PARALLEL_PLAN_PREFERENCE drops it to 23.4458 (runtime 6 seconds) (primary runtime is 2 seconds...the two tables in the join have 85 million/11 rows)).
    – Bobogator
    Commented Jan 24, 2022 at 20:47
  • @GaryS thanks! Sounds like you have some more to go on now. Feel free to update the question with more details, or ask a new one if you think it's drifting too far off from the original. Commented Jan 24, 2022 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.