max() not using index

Поиск
Список
Период
Сортировка
От Ralph Graulich
Тема max() not using index
Дата
Msg-id Pine.LNX.4.21.0207171424170.7918-100000@shauny.shauny.de
обсуждение исходный текст
Список pgsql-general
Hi,


I have got a table with a non-unique integer value named "dam_id" and I
need to query the max(dam_id) value. Also put an index on that column, but
postgres always does a seq scan, which takes half a minute to complete.

    Column     |              Type               |      Modifiers
---------------+---------------------------------+----------------------
 dam_id        | integer                         |
[...]
Indexes: ix_dam_dam_id

EXPLAIN SELECT MAX(dam_id) FROM dam;
NOTICE:  QUERY PLAN:

Aggregate  (cost=5774.65..5774.65 rows=1 width=4)
  ->  Seq Scan on dam  (cost=0.00..5442.92 rows=132692 width=4)

Another note: I vacuum full analyzed the table. Didn't help either.

Errrr, yes, I am porting a mySQL application to postgres, cause postgres
offers me the features I need for that app. Brought back the fun of adding
new features to my application :-)

Kind regards
... Ralph ...


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

Предыдущее
От: "Peter Gibbs"
Дата:
Сообщение: Re: Using index with order desc
Следующее
От: "Peter Gibbs"
Дата:
Сообщение: Re: Using index with order desc