Limiting the amount of CPU’s/cores a query uses

Afternoon all,

Sorry for the absence of updates recently, I’ve been getting stuck into certifications and unfortunately between studying and a full work schedule, finding time for updates has been hard to come by. Hope to get a break soon though and get back to updating regularly. Just a quick one this time, it’s based on the ‘Max Degree of Parallelism’ setting in SQL Server, which I won’t go into in detail as that’s a whole other kettle of fish. (Anyone interested in looking into that further, have a look here).

By sticking the following line at the end of your query, you can restrict the amount of cores that your query will use while running. This is useful if you need to run a big ad-hoc query on a production database, and don’t want to tie up all available resources on regular traffic. So for example on a 4 core system, setting the number to 2 will restrict your query to using 2 cores, leaving the other 2 cores completely free for other use. It doesn’t mean your query has exclusive use of the 2 cores it is accessing, but it keeps it from spilling out into the other resources. Obviously this will slow your particular query down, but it will reduce the impact on day to day business. So the query will look something like :

Select * from whatever
Where blah = blah
OPTION (MAXDOP 2)

This will restrict this particular query to 2 parallel queries, and restrict it to using 2 cores. Change the number to 1 for only one core, 3 for 3 cores etc. 
Short but sweet, and very useful if you regularly have to do lookups on production systems!
Updates will be few and far between for the next few weeks while I get these certs out of the way, but hopefully I’ll get back to normal after that. Hope all is well with everyone!
Stephen

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.