Query executing differently with different values?

คำตอบ Query executing differently with different values?

  • Thursday, January 31, 2013 3:00 AM
     
     

    I am running an exactly same query with different values in the WHERE clause. For example:

    Select Col1 From TblA Where ColB = 2

    Select Col1 From TblA Where ColB = 4

    The query is taking much longer to run with COlB = 4. They both return almost same row counts. The CPU and the IO are same too. 

    I can't figure what the issue could be? 

    KK

All Replies

  • Thursday, January 31, 2013 3:02 AM
    Moderator
     
     Answered
    Do you have index on ColB column are can you UPDATE statistics for this table?

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

  • Thursday, January 31, 2013 3:16 AM
     
     
    I don't have an index on the column. I will try updating the statistics. 
  • Thursday, January 31, 2013 4:08 AM
     
     

    Do you have a filtered index on ColB that is helping where the value is 2 and not when it's 4? Also, ensure that the actual query isn't making use of scalar functions and it really is as simple as demonstrated above.

  • Thursday, January 31, 2013 4:13 AM
     
     
    Thanks. Updating the statistics helped.
  • Thursday, January 31, 2013 4:50 AM
     
     

    first you create index on colB, update the statistics and

    then use below link which talks about how see exact execution times of a query 

    How to check actual performance of SQL Query


    Mark this post as answer if this resolves your issue.


    Everything about SQL Server | Experience inside SQL Server -Mohammad Nizamuddin