[SQL] Slow GROUP BY query

2008-01-29 Thread Stuart Brooks
I have a very simple table set: Transactions: transaction_key PRIMARY KEY client TEXT time TIMESTAMP LineItems transaction_key INT amount INT A query to print the contents of transactions with a sum of the line item amounts provides a very suboptimal result. The problem seems to be the GROUP

Re: [SQL] slow group by query

2002-11-19 Thread Ellen Cyran
That's a whole lot faster. The query on 40 msa_codes that took 7 minutes, now only takes 10 seconds. Thanks a lot. At 11:54 AM 11/19/2002 -0500, Tom Lane wrote: Ellen Cyran <[EMAIL PROTECTED]> writes: > Here is the explain analyze: > Group (cost=637.18..696.52 rows=593 width=22) (actual time

Re: [SQL] slow group by query

2002-11-19 Thread Tom Lane
Ellen Cyran <[EMAIL PROTECTED]> writes: > Here is the explain analyze: > Group (cost=637.18..696.52 rows=593 width=22) (actual time=982.67..67581.85 >rows=435 loops=1) >-> Sort (cost=637.18..637.18 rows=5934 width=22) (actual time=833.27..844.78 >rows=6571 loops=1) Well, we don't have to

Re: [SQL] slow group by query

2002-11-19 Thread Ellen Cyran
I had to modify your query somewhat, but the one below that is pretty much the same took about 12 seconds so once I run it on five years it will take just as long. Thanks for the suggestion though. select distinct on (b.msa_code, b.sic, b.own, b.ind_div) b.msa_code, b.sic, b.own, b.ind_div, y19

Re: [SQL] slow group by query

2002-11-19 Thread Ellen Cyran
I have vacuum analyzed recently. I do it after a large number of inserts and after indexing. This database is in the development stages so there is a lot of data loading at this time. We are also using 7.2.3. Here is the explain analyze: Group (cost=637.18..696.52 rows=593 width=22) (actual

Re: [SQL] slow group by query

2002-11-19 Thread Tom Lane
Ellen Cyran <[EMAIL PROTECTED]> 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 w

Re: [SQL] slow group by query

2002-11-19 Thread Stephan Szabo
On Mon, 18 Nov 2002, Ellen Cyran wrote: > 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 wh

[SQL] slow group by query

2002-11-19 Thread Ellen Cyran
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 sele