Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (2024)

Brent Ozar

Configuration Settings

14 Comments

Whenever I work with SQL Server, I’m amazed at how many ways there are to influence its behavior. For example, take the maximum degree of parallelism for a query. Just offhand, I thought of ten different ways you cantweak it:

1. At the server level withSSMS. In SSMS, right-click on the server, click Properties, Advanced, scroll down into the Parallelism section, and set MAXDOP to 1. Click OK. (Be aware that this blows your plan cache instantly.)

2. At the server level with sp_configure. Just the command level version of the above, with the same side effect:

Transact-SQL

1

2

3

4

EXEC sys.sp_configure N'max degree of parallelism', N'1'

GO

RECONFIGURE

GO

3. At the query level with hints. Use OPTION (MAXDOP 1) at the end of your query to tie its hands behind its back. Interestingly, when you view the execution plan, the SELECT operator’s NonParallelPlanReason says “MaxDOPSetToOne” – which it is, but just at the query level, not what you might have expected. Even less expected: your hint cango HIGHER (not just lower) than the server-level setting.

Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (1)

4. By setting Cost Threshold for Parallelism reallyhigh. If you play around with this lesser-known parallelism setting and raise it up in the thousands (or millions or whatever), you can effectively set MAXDOP to 1. This comes in handy when some jerk puts a high MAXDOP hint in their query: they’re only picking the max degree of parallelism IF the query goes parallel. By setting CTfP high, you’re making sure it won’t go parallel.Insert diabolical laugh here.

5. By configuring Resource Governor. This Enterprise Edition feature lets you create a workload group with a MAX_DOP hint. (Yes, it has an underscore between MAX and DOP. No, I don’t know why. Yes, this can also override the server-level setting upwards.)

6. By using parallelism-inhibiting T-SQL. Paul White has an excellent rundown of things that will effectively set your entire query (or zones of the plan) to be MAXDOP 1.

7. By using query-level trace flag 8649. In that same post, Paul shows how OPTION (QUERYTRACEON 8649) can force your query to go parallel.Look, I didn’t title this blog post “Great Ideas in Query Tuning.”

8. By using Adam Machanic’s make_parallel() function.Add this adorable little function to your queries, and SQL Server thinks it’s going to be dealing with 1,099,511,627,776 rows – when there’s really only one. Hee hee!

9. By putting scalar functions in computed columns.Erik discovered that just by having these nasty little devils in your database, you’re not just causing user queries to go single-threaded, but even index maintenance and CHECKDB operations miss out on the joy of parallelism.

Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (2)

10. By setting it at the database level in SQL Server 2016. Right-click on your database and click Properties, and in the Options pane, there’s a handful of nifty new options including Max DOP and Max DOP For Secondary.

10a. By creating a different database just for parallelism.If you fully-qualify your database objects in queries like this:

Transact-SQL

1

SELECT * FROM StackOverflow.dbo.Users;

Then you can get different MAXDOP settings simply by running your query in different databases – depending on their database-level parallelism settings. Here’s a screenshot of my database list that may help explain where I’m going with this:

Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (3)

That’s right – depending on where I run that query, it’ll get different parallelism options.

Previous PostIs NOLOCK Ever The Right Choice?Next PostFiltered Statistics Follow-up

14 Comments. Leave new

  • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (4)

    Dan

    December 21, 2016 10:47 am

    Since we aren’t necessarily talking about good options, how about using DBCC OPTIMIZER_WHATIF(CPUs, 1)?

    Reply
  • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (6)

    March 14, 2017 12:47 pm

    Nice write-up Brent! There’s a list of non-parallel plan reasons that may also force a MAXDOP=1 situation:

    http://www.sqlskills.com/blogs/joe/sql-server-2012-execution-plans-nonparallelplanreason/

    Near the bottom of the comments. It’s a little out-of-date, I know the Hekaton one changed names, and may not apply to SQL 2016.

    Reply
  • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (7)

    David Roberts

    July 31, 2017 3:28 pm

    So what is the scope of these different options? If I change it at the server level, does that trickle down to the databases level?

    Reply
    • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (8)

      Brent Ozar

      August 1, 2017 6:36 am

      David – that’s beyond the scope of the post, but it’s a great question! If you’ve got the time to run experiments to document it thoroughly, that’d be a great start for a blog post of your own. (This stuff is hard work, heh.)

      Reply
      • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (9)

        David ROberts

        August 1, 2017 10:14 am

        I’ll see what I can find out!
        You have some great stuff here.
        Thanks!

        Reply
        • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (10)

          Brent Ozar

          August 1, 2017 10:30 am

          Thanks!

          Reply
      • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (11)

        frank

        April 14, 2021 6:23 pm

        it’s 3 years later but does it trickle down? I assumed it would, server wide would be server wide?

        Reply
        • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (12)

          Brent Ozar

          April 15, 2021 5:20 am

          No.

          Reply
          • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (13)

            Frank

            April 15, 2021 1:33 pm

            Ugh, Bret! I’m facing a parallelism issue and I’m actually subscribed to your DBA training, what module should I run though so I understand whats going on here and how to set it. Microsoft engineer has us changing mdop to 8 at the server level, do we need to also set at the database level?

          • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (14)

            Brent Ozar

            April 15, 2021 2:15 pm

            The parallelism module in Mastering Server Tuning.

    • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (15)

      Greg McQuibben

      October 15, 2018 2:40 pm

      Be aware of the changes changing the MAXDOP at the server level incurs. The plan cache instances get flushed.

      Reply
  • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (16)

    Thomas Considine

    November 15, 2017 3:42 pm

    An impressive tour de force !

    Reply
  • Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (17)

    Jeff Timmons

    August 5, 2021 3:57 pm

    I found that Paul White’s article has moved to:
    https://www.sql.kiwi/2011/12/forcing-a-parallel-query-execution-plan.html

    Best regards!

    Reply

Leave a Reply

Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (18)

Hi! I’m Brent Ozar.

I make Microsoft SQL Server go faster. I love teaching, travel, cars, and laughing. I’m based out of Las Vegas. He/him.I teach SQL Server training classes, or if you haven’t got time for the pain, I’m available for consulting too.

Want to advertise here and reach my savvy readers?

Ten Ways to Set MAXDOP - Brent Ozar Unlimited® (2024)
Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 5824

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.