SQL Server & Parallel Queries
iKosmik
Crafted for the love ♥ of SQL Server
How does SQL Server choose a
Parallel Query Plan to run you query?
iKosmik
… Based on how many cores
your machine has
More cores is a reason to celebrate! This means there is greater chance that SQL Server will consider the Parallel Query Plan to execute your query!
iKosmik
… Are there enough number of threads for the parallel run?
That’s self-explanatory. SQL Server looks at the current load on the database and if it can allocate enough number of threads to make this parallelism happen.
iKosmik
… What query processing
are you doing in there?
SQL Server is real smart here! It looks at what kind of processing / computation are you really doing in your query. If it’s a CPU hungry query, say, something like creating/rebuilding an india, or maybe sorting, then it decides to run it in parallel.
iKosmik
… are there enough rows for processing?
If there are “not” enough rows to be processed, then SQL Server may drop the parallelism idea.
iKosmik
… Is the distribution stats up-to-date?
SQL Server looks for an up-to-date distribution statistics in order to consider running a query with a parallel plan.
iKosmik
when does SQL Server choose a
Parallel Query Plan to run you query?
iKosmik
… Depends on the Cost Threshold for Parallelism
setting
So SQL Server compares the cost of running the query using its Serial Query Plan with the Cost Threshold for Parallelism value set in your database.
If
Cost of Serial Plan > Cost Threshold for Parallelism
there is a great chance that SQL Server will run your query in using the highest degree of parallelism possible!
iKosmik
When is it a sure NO NO?
Got a dynamic cursor?
You got a dynamic cursor in there?
Oh no! You lose the chance to run parallel! Sorry!
iKosmik
Happy DBA’ing!
See you soon with another interesting crucial SQL Server concept!
Until then …
iKosmik
http://www.sqlserverapp.com/