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

Поиск
Список
Период
Сортировка
От Tomasz Myrta
Тема Re: "select max/count(id)" not using index
Дата
Msg-id 3FE6CF91.6070300@klaster.net
обсуждение исходный текст
Ответ на "select max/count(id)" not using index  (Ryszard Lach <siaco@autograf.pl>)
Список pgsql-performance
Dnia 2003-12-22 11:39, Użytkownik Ryszard Lach napisał:

> Hi.
>
> 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):
'select count(id)'
Yes, this is normal. Because of MVCC all rows must be checked and
Postgres doesn't cache count(*) like Mysql.

'select max(id)'
This is also normal, but try to change this query into:
select id from some_table order by id desc limit 1;

What is your Postgresql version?

Regards,
Tomasz Myrta


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

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