distinct vs group by

Поиск
Список
Период
Сортировка
От Ron Mayer
Тема distinct vs group by
Дата
Msg-id Pine.LNX.4.58.0501280229240.22244@greenie.cheapcomplexdevices.com
обсуждение исходный текст
Ответы Re: distinct vs group by  (Bruno Wolff III <bruno@wolff.to>)
Re: distinct vs group by  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
Should the expressions
  select distinct x from t
and
  select          x from t group by x
have the same effect?

It seems the optimizer sometimes chooses different plans for those
expressions.   Could the select distinct have used the slightly
faster hash aggregate?

   Thanks.



fli=# explain select distinct zip from sa_zips;
                             QUERY PLAN
--------------------------------------------------------------------
 Unique  (cost=3.65..3.98 rows=66 width=8)
   ->  Sort  (cost=3.65..3.82 rows=66 width=8)
         Sort Key: zip
         ->  Seq Scan on sa_zips  (cost=0.00..1.66 rows=66 width=8)
(4 rows)



fli=# explain select zip from sa_zips group by zip;
                          QUERY PLAN
--------------------------------------------------------------
 HashAggregate  (cost=1.82..1.82 rows=66 width=8)
   ->  Seq Scan on sa_zips  (cost=0.00..1.66 rows=66 width=8)
(2 rows)



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

Предыдущее
От: Inpreet Singh
Дата:
Сообщение: Re: Postgres database access problem
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: distinct vs group by