title: sql server: Estimated number of rows is way off
body: <p>I get a bizarre execution plan behavior from SQL Server (2005).</p>
  
  <p>TableName: <strong>LOG</strong><br>
  ...contains around 1000 rows</p>
  
  <ul>
  <li>ID int</li>
  <li>Name varchar(50)</li>
  </ul>
  
  <p>Query:</p>
  
  <pre><code>SELECT * 
    FROM (SELECT ROW_NUMBER() OVER (ORDER BY ID DESC) as Row,
                 ID, Name
            FROM Log) AS LogWithRowNumbers
   WHERE Row &gt;= 1 
     AND Row &lt;= 2
  </code></pre>
  
  <p>It estimates the number of rows returned as 9 (Although it's an obvious 2 or less).<br>
  Also, removing the "and Row&lt;=2" will increase the execution time by about  * 5.  ("and Row&lt;=2" and "and Row&lt;=9999999999999" behave the same)</p>
  
  <p>I've updated statistics. But still, this behavior is strange. Adding Row&lt;99999999999 will make the query run faster? why ?</p>