Where condition gives timeout
I have a query in sql server 2008 r2 db, which is executed from C# using
SqlCommand:
SELECT ob.*, ob2.*
FROM Orderbook ob
LEFT JOIN Instruments i ON ob.InstrumentId = i.id AND i.TypeId = 4
LEFT JOIN Instruments i2 ON i.UnderlyingId = i2.id
LEFT JOIN Orderbook ob2 ON ob2.InstrumentId = i2.id AND ob.Moment =
ob2.Moment
WHERE /*ob.Moment > @sinceDateTime AND*/ i.CodeId = 9 AND DATEPART(minute,
ob.Moment) = 0
ORDER BY ob.Moment
It runs ok with a commented condition in WHERE clause. But when I
uncomment it, I get a timeout from server. This confuses me - the query to
get records from the beginning of times runs ok, but when I want to get
records for today only I get timeout. Any suggestons where to look?
Orderbook table has a clustered index on Moment field and regular index on
InstrumentId. Instruments table has indexes for Id and UnderlyingId
fields. And I can run both queries ok from management studio, so can't
experiment much from there.
No comments:
Post a Comment