Re: max(field) vs select field .. order by desc limit 1

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: max(field) vs select field .. order by desc limit 1
Дата
Msg-id 7676.983915889@sss.pgh.pa.us
обсуждение исходный текст
Ответ на max(field) vs select field .. order by desc limit 1  (Lincoln Yeoh <lyeoh@pop.jaring.my>)
Список pgsql-general
Lincoln Yeoh <lyeoh@pop.jaring.my> writes:
> Which would be better to do, max() or select .. order by limit 1?

If there's an index that the ORDER BY can key on, the second will be
much better.  If there's not, I'd go with the max(); you don't really
want a complete sort operation.

> Is 7.1 much better than 7.0.3 in doing the "limit 1"? I see that their
> EXPLAINs are different - 7.1 has a limit cost.

Should be about the same.  The appearance of a Limit plan node in 7.1
is an implementation change that was necessary to support LIMIT clauses
in subqueries, but it shouldn't make any noticeable performance
difference for top-level limits.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PHP and PostgresSQL beta
Следующее
От: Neil Conway
Дата:
Сообщение: Re: DELETE and efficiency