Ellen Cyran <ellen(at)urban(dot)csuohio(dot)edu> writes:
> Is there any way to make this query faster? I have indexes on year,
> msa_code, and sic. I've also tried it with
> an index on the combined group by columns. I've made both sort_mem and
> shared_buffers bigger, but still this query
> takes 40 seconds when I select 4 msa_codes and 7 minutes when I select 40
> msa_codes.
Hm, have you vacuum analyzed lately? Those cost estimates seem awfully
low for a query that is taking 40 sec. Also, if you're using 7.2 (which
you should be ;-)) then showing EXPLAIN ANALYZE results would be more
useful than plain EXPLAIN.
regards, tom lane