title: Different execution time for same query - SQL Server 2008 R2
body: <p>I run this query in SqlServer 2008 R2, it take about 6 seconds and return around 8000 records. <code>OrderItemView</code> is a view and <code>DocumentStationHistory</code> is a table.</p>
  
  <pre><code>SELECT  o.Number, dsh.DateSend AS Expr1
  FROM    OrderItemView AS o INNER JOIN
          DocumentStationHistory AS dsh ON dsh.DocumentStationHistoryId =
              (SELECT TOP (1) DocumentStationHistoryId
               FROM         DocumentStationHistory AS  dsh2
               WHERE     (o.DocumentStationId = ToStationId) AND 
               (DocumentId =   o.id)
               ORDER BY DateSend DESC)
  WHERE     (o.DocumentStationId = 10)   
  </code></pre>
  
  <p>But when I run the same query with <code>o.DocumentStationId = 8</code> where clause, it return around 200 records but take about 90 seconds!</p>
  
  <p>Is there any idea that where is the problem?</p>