title: SQL count(*) performance
body: <p>I have a SQL table BookChapters with over 20 millions rows. It has a clustered primary key (bookChapterID) and doesn't have any other keys or indexes. It takes miliseconds to run the following query</p>
  
  <pre><code>if (select count(*) from BookChapters) = 0
  ...
  </code></pre>
  
  <p>However, it takes over 10 minutes when I change it like so</p>
  
  <pre><code>if (select count(*) from BookChapters) = 1
  ...
  </code></pre>
  
  <p>or </p>
  
  <pre><code>if (select count(*) from BookChapters) &gt; 1
  ...
  </code></pre>
  
  <p>Why is that?
  How can I get <code>select count(*)</code> to execute faster?</p>