max() not using index - Mailing list pgsql-general

From Ralph Graulich
Subject max() not using index
Date
Msg-id Pine.LNX.4.21.0207171424170.7918-100000@shauny.shauny.de
Whole thread Raw
List 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 by date:

Previous
From: "Peter Gibbs"
Date:
Subject: Re: Using index with order desc
Next
From: "Peter Gibbs"
Date:
Subject: Re: Using index with order desc