Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Odd performance caused by Where Clause


Odd performance caused by Where Clause

Author
Message
JblakTSql
JblakTSql
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 14
So I have this odd issue that I can't figure out how to solve. I have a poorly written view which runs slowly but works (returns data in ~ 8 sec). Select * from view1 returns:

Action Name Server
add item1 server1
add item2 server1
update item3 server2


I know i am violating a common rule but have a good reason where I am nesting this view inside of another view which filters the results to an action. In this case my view is called view2 with code Select * from view1 where action = 'update'. This runs in ~ 7 secs.

Now here is the problem. When I run the following: Select * From View2, it returns data in roughly ~7 sec. When I run Select * from View2 Where Server = 'Server2', returns data in roughly ~ 7sec, but when I run Select * from View2 where Server = 'Server1', this returns no rows (which is correct) but take over 1 min to return. Any idea why this would happen or how to troubleshoot this?
Cadavre
Cadavre
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2596 Visits: 8437
JblakTSql (2/13/2013)
So I have this odd issue that I can't figure out how to solve. I have a poorly written view which runs slowly but works (returns data in ~ 8 sec). Select * from view1 returns:

Action Name Server
add item1 server1
add item2 server1
update item3 server2


I know i am violating a common rule but have a good reason where I am nesting this view inside of another view which filters the results to an action. In this case my view is called view2 with code Select * from view1 where action = 'update'. This runs in ~ 7 secs.

Now here is the problem. When I run the following: Select * From View2, it returns data in roughly ~7 sec. When I run Select * from View2 Where Server = 'Server2', returns data in roughly ~ 7sec, but when I run Select * from View2 where Server = 'Server1', this returns no rows (which is correct) but take over 1 min to return. Any idea why this would happen or how to troubleshoot this?


It's unlikely that I'll have time to help today, but if you want others to help then it might be a good idea to follow the advise in this link --> http://www.sqlservercentral.com/articles/SQLServerCentral/66909/.


Forever trying to learn

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better, quicker answers on SQL Server performance related questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



If you litter your database queries with nolock query hints, are you aware of the side effects?
Try reading a few of these links...

(*) Missing rows with nolock
(*) Allocation order scans with nolock
(*) Consistency issues with nolock
(*) Transient Corruption Errors in SQL Server error log caused by nolock
(*) Dirty reads, read errors, reading rows twice and missing rows with nolock


Craig Wilkinson - Software Engineer
LinkedIn
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8383 Visits: 19503
Do you have an index on the 'server' column?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8259 Visits: 14368
Any idea why this would happen or how to troubleshoot this?

No way to tell from here. Please post the Actual Execution Plans for all three queries.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
JblakTSql
JblakTSql
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 14
no, I am not able to create indexes for this data. It has duplicates in it.
JblakTSql
JblakTSql
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 14
opc.three (2/14/2013)
Any idea why this would happen or how to troubleshoot this?

No way to tell from here. Please post the Actual Execution Plans for all three queries.


I'll pull that and post it. Regardless, i was trying to understand why this would happen. I can tell you that the execution plan for the filter that works looks the same as the filter that doesn't work. The difference is in cost for the filter and nested loops
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8383 Visits: 19503
JblakTSql (2/14/2013)
no, I am not able to create indexes for this data. It has duplicates in it.


Yes you are. Indexes do not have to contain unique values.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search