title: Why does an indexed DELETE take so long?
body: <p>This DELETE (among many others) is taking very long. The table has ~1M rows, but they are properly indexed by <code>updatedAt</code> and there are only ~5k rows to delete:</p>
  
  <pre><code>SELECT COUNT(*) FROM "Users" where "_etl" = true and "updatedAt" &gt;= '2015-01-15 15:01:10.454-05'
  </code></pre>
  
  <blockquote>
    <p>5163</p>
  </blockquote>
  
  <p>Here's the EXPLAIN:</p>
  
  <pre><code>EXPLAIN DELETE FROM "Users" where "_etl" = true and "updatedAt" &gt;= '2015-01-15 15:01:10.454-05'
  
  Delete on "Users"  (cost=0.42..23581.27 rows=38909 width=6)
    -&gt;  Index Scan using user_updatedat_etl_index on "Users"  (cost=0.42..23581.27 rows=38909 width=6)
          Index Cond: ("updatedAt" &gt;= '2015-01-15 15:01:10.454-05'::timestamp with time zone)
          Filter: _etl
  </code></pre>
  
  <p>I'm not sure, but perhaps it's because the <code>Users</code> table has many foreign keys? I've already been waiting ~30 minutes for this <code>DELETE</code> to finish and can't think of a legitimate reason this should take so long.</p>