Re: space for optimalization: DISTINCT without index

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: space for optimalization: DISTINCT without index
Дата
Msg-id 20051212214823.GA31847@wolff.to
обсуждение исходный текст
Ответ на space for optimalization: DISTINCT without index  ("Pavel Stehule" <pavel.stehule@hotmail.com>)
Ответы Re: space for optimalization: DISTINCT without index  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Mon, Dec 12, 2005 at 18:35:07 +0100, Pavel Stehule <pavel.stehule@hotmail.com> wrote:
> Hello
> 
> I did some test and I can see so DISTINCT works well on indexed columns, 
> but is slow on derived tables without indexes. If I use without distinct 
> group by I get much better times.
> 
> SELECT DISTINCT a, b FROM tab
> SELECT a,b FROM tab GROUP BY a, b.
> 
> Can You Explain it.

DISTINCT will require a sort step to remove duplicates. GROUP BY can use
either a sort or hash aggregate plan. If there are few distinct values,
the hash aggregate plan can be much faster.


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

Предыдущее
От: "Cristian Prieto"
Дата:
Сообщение: replan needed?
Следующее
От: Andrew Dunstan
Дата:
Сообщение: buildfarm off the air pro tem