PostgreSQL query performance bottlenecks
Another postgresql performance gotcha:<p>Find all the coupons that are expired (90 day expiration):<p><pre><code>    SELECT * FROM coupon
    WHERE created_at + INTERVAL '90 DAY' < now()
</code></pre>
This will not use the index on the "created_at" column and will be slow.<p>You should rewrite the inequality to:<p><pre><code>    SELECT * FROM coupon
    WHERE created_at < now() - INTERVAL '90 DAY'
</code></pre>
and now the query will be much faster. There are a lot of cases in postgres where simple equivalent algebraic manipulations can completely change the query plan