Re: MAX/MIN optimization via rewrite (plus query rewrites

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: MAX/MIN optimization via rewrite (plus query rewrites
Дата
Msg-id 87fz3gg64e.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: MAX/MIN optimization via rewrite (plus query rewrites  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-hackers
Bruno Wolff III <bruno@wolff.to> writes:

> I don't think you should be rewriting queries as much as providing
> alternate plans and letting the rest of the optimizer decided which
> plan to use. If you just rewrite a query you might lock yourself into
> using a poor plan.

Moreover, none of these rewritten queries would work properly for

select min(foo) from tab group by bar

This should still be aware it can use an index on <bar,foo> and get much
better performance. Well it can't know, but it should be able to. All it
should really need to know is that min() only needs a particular subset of the
dataset -- namely the first record, as long as the records are provided in a
particular order.

Also, the same code ought to be able to handle

select first(foo) from tab group by bar

Which is exactly equivalent to the min() case except that no particular
ordering is required.

-- 
greg



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

Предыдущее
От: Mark Kirkwood
Дата:
Сообщение: Re: MAX/MIN optimization via rewrite (plus query rewrites
Следующее
От: Patrick B Kelly
Дата:
Сообщение: Re: multiline CSV fields