Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Procedure and View - Strange Response Times

Author  Topic 

Mess
Starting Member

2 Posts

Posted - 2009-07-31 : 20:27:45
I am getting very strange results when I go to get data from my DB.

The query below goes against a table and a view. It returns about 500 records in under 1 second. This is great.

SELECT Reply.ReplyID, Stars
FROM Reply LEFT OUTER JOIN vwStars ON (Reply.MemberID=vwStars.MemberID)
WHERE ThreadID = 1531

When I change the last line to:

WHERE ThreadID = 1918

The query works. It returns about 200 matching records, but it takes over 10 seconds to complete.

Now here comes the really odd part:

If I change the last line to:

WHERE ThreadID = 1918 or ThreadID = 1531

The query still works and returns about 700 records in under 1 second. So why, when I only look for certain ThreadIDs, is the response time so slow? How is this even possible?

Thanks in advance for any help or guidance,

Chris

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-31 : 21:04:10
is threadid indexed? is it unique? look at the execution plan on both queries. specifically, you're looking for table scans or index scans on large tables.

also set statistics io on and check # reads each query
Go to Top of Page
   

- Advertisement -