title: SQL Server "<>" operator is very slow compared to "=" on table with a few million rows
body: <p>I have two tables. Forms has ~77000 rows. Logs has ~2.7 million rows.</p>
  
  <p>The following query returns "30198" in less than a second:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT COUNT(DISTINCT logs.DOCID) FROM logs, forms WHERE logs.DOCID = forms.DOCID;
  </code></pre>
  
  <p>And this query has been running for ~15 minutes so far, and still hasn't finished:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT COUNT(DISTINCT logs.DOCID) FROM logs, forms WHERE logs.DOCID &lt;&gt; forms.DOCID;
  </code></pre>
  
  <p>Why is the "not equal" query <strong>so</strong> much slower?</p>