Postgres not using index for range query in partitioned table
<p>I found that Postgres is not using an index for a range query on a partitioned table.</p>

<p>The parent table and its partitions have their date column indexed using btree. </p>

<p>A query like this:</p>

<pre><code>select * from parent_table where date &gt;= '2015-07-01';
</code></pre>

<p>does not use indexes.</p>

<p><code>EXPLAIN</code> result: </p>

<pre><code>Append  (cost=0.00..106557.52 rows=3263963 width=128)
-&gt;  Seq Scan on parent_table  (cost=0.00..0.00 rows=1 width=640)
    Filter: (date &gt;= '2015-07-01'::date)
-&gt;  Seq Scan on z_partition_2015_07  (cost=0.00..106546.02 rows=3263922 width=128)
    Filter: (date &gt;= '2015-07-01'::date)
-&gt;  Seq Scan on z_partition_2015_08  (cost=0.00..11.50 rows=40 width=640)
    Filter: (date &gt;= '2015-07-01'::date)
</code></pre>

<p>But a query like this:</p>

<pre><code>select * from parent_table where date = '2015-07-01'
</code></pre>

<p>uses an index.</p>

<p><code>EXPLAIN</code> result:</p>

<pre><code>    Append  (cost=0.00..30400.95 rows=107602 width=128)
-&gt;  Seq Scan on parent_table  (cost=0.00..0.00 rows=1 width=640)
    Filter: (date = '2015-07-01'::date)
-&gt;  Index Scan using z_partition_2015_07_date on z_partition_2015_07  (cost=0.43..30400.95 rows=107601 width=128)
    Index Cond: (date = '2015-07-01'::date)
</code></pre>

<p>When I run the query on a different normal table with <code>date</code> indexed, both queries use the index.</p>

<p>Anything particular that we should do on partitioned table index?</p>