| От | Tom Lane |
|---|---|
| Тема | Re: distinct vs group by |
| Дата | |
| Msg-id | 25772.1107036847@sss.pgh.pa.us обсуждение |
| Ответ на | distinct vs group by (Ron Mayer <rm_pg@cheapcomplexdevices.com>) |
| Список | pgsql-novice |
Ron Mayer <rm_pg@cheapcomplexdevices.com> writes:
> Should the expressions
> select distinct x from t
> and
> select x from t group by x
> have the same effect?
Offhand I think they are theoretically equivalent.
> It seems the optimizer sometimes chooses different plans for those
> expressions. Could the select distinct have used the slightly
> faster hash aggregate?
This is partly historical (the DISTINCT code hasn't been rewritten in a
long time) and partly intentional --- you can choose one phrasing or the
other to control what plan you get.
regards, tom lane
В списке pgsql-novice по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера