From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | "Cristian Prieto" <cristian(at)clickdiario(dot)com> |
Cc: | <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: Any way to optimize GROUP BY queries? |
Date: | 2005-12-19 20:47:35 |
Message-ID: | 87wti0ak60.fsf@stark.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
"Cristian Prieto" <cristian(at)clickdiario(dot)com> writes:
> SELECT adv, pub, web, country, date_trunc('hour', tiempo), sum(num)
> FROM mytmp GROUP BY adv, pub, web, country, date_trunc('hour', tiempo)
>
> I've tried to create index in different columns but it seems that the group
> by clause doesn't use the index in any way.
If you had an index on < adv,pub,web,country,date_trunc('hour',tiemp) > then
it would be capable of using the index however it would choose not to unless
you forced it to. Using the index would be slower.
> Is around there any stuff to accelerate the group by kind of clauses?
Increase your work_mem (or sort_mem in older postgres versions), you can do
this for the server as a whole or just for this one session and set it back
after this one query. You can increase it up until it starts causing swapping
at which point it would be counter productive.
If increasing work_mem doesn't allow a hash aggregate or at least an in-memory
sort to handle it then putting the pgsql_tmp directory on a separate spindle
might help if you have any available.
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Stark | 2005-12-19 20:54:29 | Re: Is the optimizer choice right? |
Previous Message | Carlos Benkendorf | 2005-12-19 20:22:58 | Is the optimizer choice right? |