Re: Any way to optimize GROUP BY queries?

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: Any way to optimize GROUP BY queries?
Дата
Msg-id 87wti0ak60.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Any way to optimize GROUP BY queries?  ("Cristian Prieto" <cristian@clickdiario.com>)
Ответы Re: Any way to optimize GROUP BY queries?  ("Jim C. Nasby" <jnasby@pervasive.com>)
Список pgsql-performance
"Cristian Prieto" <cristian@clickdiario.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

В списке pgsql-performance по дате отправления:

Предыдущее
От: Carlos Benkendorf
Дата:
Сообщение: Is the optimizer choice right?
Следующее
От: Greg Stark
Дата:
Сообщение: Re: Is the optimizer choice right?