title: PostgreSQL: Create an index to quickly distinguish NULL from non-NULL values
body: <p>Consider a SQL query with the following <code>WHERE</code> predicate:</p>
  
  <pre><code>...
  WHERE name IS NOT NULL
  ...
  </code></pre>
  
  <p>Where <code>name</code> is a textual field in PostgreSQL.</p>
  
  <p>No other query checks any textual property of this value, just whether it is <code>NULL</code> or not. Therefore, <a href="http://www.postgresql.org/docs/9.3/static/indexes-types.html">a full btree index</a> seems like an overkill, even though <a href="http://www.postgresql.org/docs/9.3/static/indexes-types.html">it supports this distinction</a>:</p>
  
  <blockquote>
    <p>Also, an IS NULL or IS NOT NULL condition on an index column can be used with a B-tree index.</p>
  </blockquote>
  
  <p><strong>What's the right PostgreSQL index to quickly distinguish <code>NULL</code>s from non-<code>NULL</code>s?</strong></p>