Re: "select max/count(id)" not using index

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: "select max/count(id)" not using index
Дата
Msg-id 3FE6CDF2.10608@familyhealth.com.au
обсуждение исходный текст
Ответ на "select max/count(id)" not using index  (Ryszard Lach <siaco@autograf.pl>)
Список pgsql-performance
> I have a table with 24k records and btree index on column 'id'. Is this
> normal, that 'select max(id)' or 'select count(id)' causes a sequential
> scan? It takes over 24 seconds (on a pretty fast machine):
>
> => explain ANALYZE select max(id) from ogloszenia;

Yes, it is.  It is a known issue with Postgres's extensible operator
architecture.

The work around is to have an index on the id column and do this instead:

SELECT id FROM ogloszenia ORDER BY id DESC LIMIT 1;

Which will be really fast.

Chris


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

Предыдущее
От: Ryszard Lach
Дата:
Сообщение: "select max/count(id)" not using index
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: "select max/count(id)" not using index