1

Suppose I have 4 write queries and that I'm using code that looks like:

Parallel.Invoke(
 () => TheID1s = SomeQuery1(TheData1),
 () => TheID2s = SomeQuery2(TheData2),
 () => TheID3s = SomeQuery3(TheData3),
 () => TheID4s = SomeQuery4(TheData4));

Does SQL Server also work in parallel internally or does writing parallel code to process queries ends up creating a queue in the database that processes queries one at a time?

1 Answer 1

1

SQL Server processes independent queries in parallel as long as they do not happen to block each other.

Intra-query parallelism also exists but it is only useful for expensive queries that parallelize well.

Calling the database in parallel is a useful thing as long as the database server has enough resource to actually process the queries in parallel.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, thanks; I've got many queries written like that and they're slow so I was starting to wonder if having them all run in parallel wasn't actually the cause of the problem. Good thing they're not user-facing queries! Thanks for the answer.
Keep in mind that the network connection that connects your application to the database will have its limits as well. It's likely going to bottleneck before the DB does, unless the queries are both very expensive to compute and also small in their quantity of output data.
@Servy good point. This question is on the brink of being too broad. One could write a book about this. Many things to consider.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.