Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
Odd performance caused by Where Clause
Odd performance caused by Where Clause
Rate Topic
Display Mode
Topic Options
Author
Message
JblakTSql
JblakTSql
Posted Wednesday, February 13, 2013 9:47 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, February 15, 2013 5:55 AM
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?
Post #1419811
Cadavre
Cadavre
Posted Thursday, February 14, 2013 1:45 AM
SSCrazy
Group: General Forum Members
Last Login: 2 days ago @ 9:16 AM
Points: 2,236,
Visits: 6,486
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/
.
Not a DBA, just 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
LinkedIn
| Blog coming soon (for sufficiently large values of "soon"
)!
Post #1419868
Phil Parkin
Phil Parkin
Posted Thursday, February 14, 2013 9:55 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Yesterday @ 5:12 AM
Points: 4,226,
Visits: 9,458
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:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1420166
opc.three
opc.three
Posted Thursday, February 14, 2013 3:35 PM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 7:22 AM
Points: 6,693,
Visits: 11,707
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
Believe you can and you're halfway there.
--Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler
--Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them.
--Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples.
--Giordy
Post #1420328
JblakTSql
JblakTSql
Posted Thursday, February 14, 2013 10:01 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, February 15, 2013 5:55 AM
Points: 4,
Visits: 14
no, I am not able to create indexes for this data. It has duplicates in it.
Post #1420376
JblakTSql
JblakTSql
Posted Thursday, February 14, 2013 10:04 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, February 15, 2013 5:55 AM
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
Post #1420378
Phil Parkin
Phil Parkin
Posted Friday, February 15, 2013 1:16 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Yesterday @ 5:12 AM
Points: 4,226,
Visits: 9,458
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:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1420417
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.