title: Why is Postgres not using my index on a simple ORDER BY LIMIT 1?
body: <p>I have a large table (about 11,000,000 rows) and I need to find the first item given a sorting condition.</p>
  <p>Note that column <code>Date</code> does <strong>NOT</strong> accept nulls</p>
  <p>Why isn't Postgres using the index:</p>
  <pre><code>CREATE INDEX track_ix_date
    ON &quot;Track&quot;
    USING btree
    (&quot;Date&quot; DESC NULLS LAST);
  </code></pre>
  <p>On this simple query:</p>
  <pre><code>select * from &quot;Track&quot; order by &quot;Date&quot; desc limit 1
  </code></pre>
  <p>But it does use it on this other query:</p>
  <pre><code>select * from &quot;Track&quot; order by &quot;Date&quot; desc nulls last limit 1
  </code></pre>
  <p>The second query is in fact much more faster that the first query.</p>
  <p>I have read the <a href="https://www.postgresql.org/docs/current/static/indexes-ordering.html" rel="noreferrer">indexes and ORDER BY</a> documentation and says that in the special case of an <code>ORDER BY</code> with a <code>LIMIT</code> clause is much more efficient to use the index instead of scanning the table, because the sorting would need to scan the full table just to get a single item</p>
  <p>Shouldn't Postgres detect that <code>nulls last / first</code> doesn't matter since the column doesn't accept nulls and just use the fastest method?</p>