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
- Changed Type Naomi NMicrosoft Community Contributor, Moderator Thursday, January 31, 2013 3:01 AM Question rather than discussion
All Replies
-
Thursday, January 31, 2013 3:02 AMModerator
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- Marked As Answer by Iric WenModerator Wednesday, February 06, 2013 8:23 AM
-
Thursday, January 31, 2013 3:16 AMI 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 AMThanks. 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

