SQL Server: How to force my select query to use maximum machine core available

T.Zacks 3,986 Reputation points
2022-08-25T18:47:04.493+00:00

I like to know can we pass any hint with sql by which i can force sql server to use 4 / 8 machine core ?

if i could use 4 core to accumulate data when sql is issued then data accumulation will be faster....am i right ? looking for a example select sql with core example.

how to use parallelism with select / update or delete query. looking for a example select sql with parallelism . parallelism speed up query execution ?

Thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,606 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,546 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 47,471 Reputation points
    2022-08-25T19:42:43.897+00:00

    SQL already handles all that at the server level. You are not going to be able to make better decisions about processor resources then the DB. It'll use as few or many cores as it sees fit based upon the runtime configuration settings that the server has. Unless your DBA has changed it then SQL should use all the cores on the machine (or licensed) automatically. Refer to this article for more information. You can read the official docs here.

    You can limit the parallel options for a query using MAXDOP. However this only can be used to reduce it, not increase it. So if the server is configured to use 4 cores you can limit your query to 1-4 but cannot make it use the remaining 4 cores.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Tom Phillips 17,716 Reputation points
    2022-08-25T19:51:48.59+00:00

    You have asked several query tuning questions, without any query details or execution details.

    There is very little you can do to change the query execution, other than indexes.

    There are not simple answers to tuning a query. Every query is different. Sometimes it is just a mater of adding or changing an index to help. But without the actual query plan, it is just a guess how to tune a query. Sometimes you have a non-sargable condition, ie using a function or cast because the data types do not match. That defeats the indexes.

    Other than that, your RAM and disk IO speed have the most impact on the query. SQL Server is rarely CPU dependent. Having more CPUs generally does not improve query performance much.

    If you would post your actual execution plan, someone can help look at it.

    1 person found this answer helpful.

  2. Erland Sommarskog 100.8K Reputation points MVP
    2022-08-25T21:24:45.927+00:00

    if i could use 4 core to accumulate data when sql is issued then data accumulation will be faster....am i right ? looking for a example select sql with core example.

    Maybe. Parallelism adds overhead, so sometimes you could get too many threads. Also, important is that SQL Server is able to partition the data correctly between the threads. Sometimes this goes really bad with one core getting all the work.

    In any case, there is a MAXDOP hint to set an upper limit to the number of cores for query, but there is no MINDOP hint to increase the number.

    1 person found this answer helpful.

  3. NikoXu-msft 1,911 Reputation points
    2022-08-26T08:02:25.8+00:00

    Hi @T.Zacks

    The Maximum Degree of Parallelism (MAXDOP) configuration option controls the number of processors used to execute queries in a parallel plan. This option determines the number of threads used to perform work in parallel with the query plan operator. Depending on whether SQL Server is set on a symmetric multiprocessing (SMP) computer, a non-uniform memory access (NUMA) computer, or a hyperthreaded processor, the Maximum degree of parallelism option needs to be configured appropriately.
    The recommended configuration of MAXDOP depends on the version of SQL Server that you are using. For guidelines for specific versions, see Configure the Maximum Degree of Parallelism server configuration option and configure the appropriate policy to verify the value of maximum degree of parallelism.
    https://learn.microsoft.com/zh-cn/sql/database-engine/configure-windows/configure-the-max-degree-of-parallelism-server-configuration-option?view=sql-server-ver16#recommendations

    Best regards
    Niko

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.