SELECT clause

  • Do multiple SELECT queries on the same table but different condition in WHERE clause block or affect each other in any way?

  • They do not block each other, but they compete for the same resources of course (mainly IO I guess).

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks for the reply.

    All I want to know is whether it will affect the query execution time?

  • gstarsaini (8/7/2014)


    Thanks for the reply.

    All I want to know is whether it will affect the query execution time?

    It might. Depends on the queries and how often they are executed.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • gstarsaini (8/7/2014)


    Do multiple SELECT queries on the same table but different condition in WHERE clause block or affect each other in any way?

    They definitely could. The WHERE conditions determine which row(s) match. But the lock(s) are on the underlying row(s)|page(s) themselves. Therefore, blocking could occur no matter the WHERE conditions are. Indeed, a SELECT without a WHERE clause could block other queries at certain times as well.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • Readers don't block readers. Readers can block writers and the other way around. Even on that case, it would depend on the locks acquired based on the queries and the indexes available in the table.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks for the reply.

    This means there is no effect on the queries?

  • gstarsaini (8/7/2014)


    Thanks for the reply.

    This means there is no effect on the queries?

    Each reply posted to your question implies "maybe", "probably" or "definitely". The average of these isn't "definitely not"!

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thanks again.

    Avoid sarcasm. Don't insist on the last word.

  • ChrisM@Work (8/7/2014)


    gstarsaini (8/7/2014)


    Thanks for the reply.

    This means there is no effect on the queries?

    Each reply posted to your question implies "maybe", "probably" or "definitely". The average of these isn't "definitely not"!

    No, definitely could. Hint(s) in a SELECT can cause them to take higher-level locks. The SELECT could be part of an UPDATE statement.

    Yes, pure SELECT-only should never cause blocking with another pure SELECT-only.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • ScottPletcher (8/7/2014)


    ChrisM@Work (8/7/2014)


    gstarsaini (8/7/2014)


    Thanks for the reply.

    This means there is no effect on the queries?

    Each reply posted to your question implies "maybe", "probably" or "definitely". The average of these isn't "definitely not"!

    No, definitely could. Hint(s) in a SELECT can cause them to take higher-level locks. The SELECT could be part of an UPDATE statement.

    Yes, pure SELECT-only should never cause blocking with another pure SELECT-only.

    But will most likely affect performance (even if only slightly), which is part of OP's question.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • ChrisM@Work (8/7/2014)


    ScottPletcher (8/7/2014)


    ChrisM@Work (8/7/2014)


    gstarsaini (8/7/2014)


    Thanks for the reply.

    This means there is no effect on the queries?

    Each reply posted to your question implies "maybe", "probably" or "definitely". The average of these isn't "definitely not"!

    No, definitely could. Hint(s) in a SELECT can cause them to take higher-level locks. The SELECT could be part of an UPDATE statement.

    Yes, pure SELECT-only should never cause blocking with another pure SELECT-only.

    But will most likely affect performance (even if only slightly), which is part of OP's question.

    Quite true as well.

    Which is why I don't quite understand the "definitely not!" 🙂

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • ScottPletcher (8/7/2014)


    Which is why I don't quite understand the "definitely not!" 🙂

    You may have missed the word before that phrase.

    "The average of those isn't 'definitely not'"

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (8/7/2014)


    ScottPletcher (8/7/2014)


    Which is why I don't quite understand the "definitely not!" 🙂

    You may have missed the word before that phrase.

    "The average of those isn't 'definitely not'"

    Yep, sure did :blush:

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • Thanks you.This will help.

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply