Re: select max(id) from aTable is very slow

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: select max(id) from aTable is very slow
Дата
Msg-id 40BF22A5.8060102@archonet.com
обсуждение исходный текст
Ответ на select max(id) from aTable is very slow  (David Teran <david.teran@cluster9.com>)
Список pgsql-performance
David Teran wrote:
> Hi,
>
> we have a table with about 6.000.000 rows. There is an index on a
> column with the name id which is an integer and serves as primary key.
>
> When we execute select max(id) from theTable; it takes about 10
> seconds. Explain analyze returns:

Due to the open-ended nature of PG's aggregate function system, it can't
see inside the max() function to realise it doesn't need all the values.

Fortune favours the flexible however - the simple workaround is to use
the equivalent:
   SELECT id FROM theTable ORDER BY id DESC LIMIT 1;

--
   Richard Huxton
   Archonet Ltd

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PostgreSQL on VMWare vs Windows vs CoLinux
Следующее
От: Marcus Whitney
Дата:
Сообщение: Re: Pl/Pgsql Functions running simultaneously