Re: DISTINCT vs. GROUP BY

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: DISTINCT vs. GROUP BY
Дата
Msg-id 8764sxoyd5.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: DISTINCT vs. GROUP BY  (Neil Conway <neilc@samurai.com>)
Ответы Re: DISTINCT vs. GROUP BY  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: DISTINCT vs. GROUP BY  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
Neil Conway <neilc@samurai.com> writes:

> On Mon, 2005-19-09 at 16:27 +0200, Hans-Jürgen Schönig wrote:
> > I was wondering whether it is possible to teach the planner to handle 
> > DISTINCT in a more efficient way:
> [...]
> > Isn't it possible to perform the same operation using a
> > HashAggregate? 
> 
> One problem is that DISTINCT ON is defined to return the first unique
> row (according to the query's ORDER BY) for the set of DISTINCT ON
> columns, which can't easily be done via hashing.

Uhm. Sure it can.


DISTINCT is really just special a case of GROUP BY. Even DISTINCT ON is just
GROUP BY with a kind of "first()" aggregate function. What would be really
neat would be to teach GROUP BY about first() and last() and how it can skip
over some index entries and still satisfy the query. Then make DISTINCT and
DISTINCT ON be handled through the exact same code path.

For bonus points teach it that min() and max() can sometimes be treated the
same way if the path is presenting records sorted on that column.


-- 
greg



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Does anybody use ORDER BY x USING y?
Следующее
От: "Marc G. Fournier"
Дата:
Сообщение: Re: Beta2 Wrap Up ...