2011/3/23 Laszlo Nagy <gandalf@xxxxxxxxxxxx>: > "GroupAggregate Â(cost=5553554.25..5644888.17 rows=2283348 width=50)" > " Â-> ÂSort Â(cost=5553554.25..5559262.62 rows=2283348 width=50)" > " Â Â Â ÂSort Key: pph.hid, ppoh.merchantid, pph.hdate" > " Â Â Â Â-> ÂNested Loop Â(cost=0.00..5312401.66 rows=2283348 width=50)" > " Â Â Â Â Â Â Â-> ÂIndex Scan using idx_product_price_history_id_hdate on > product_price_history pph Â(cost=0.00..8279.80 rows=4588 width=16)" > " Â Â Â Â Â Â Â Â Â ÂIndex Cond: (id = 37632081)" > " Â Â Â Â Â Â Â-> ÂIndex Scan using pk_product_price_offer_history on > product_price_offer_history ppoh Â(cost=0.00..1149.86 rows=498 width=42)" > " Â Â Â Â Â Â Â Â Â ÂIndex Cond: (ppoh.hid = pph.hid)" > " Â Â Â Â Â Â Â Â Â ÂFilter: (ppoh.isfeatured = 1)" I suspect that, since the matched hid's probably aren't sequential, many of those ~500 product_price_offer_history rows will be far apart on disk. Please show the EXPLAIN ANALYZE output in the slow case, not just EXPLAIN. Also, PostgreSQL version? What configuration options have you changed? (http://wiki.postgresql.org/wiki/SlowQueryQuestions) Regards, Marti -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance