max() not using index

From: Ralph Graulich <maillist(at)shauny(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: max() not using index
Date: 2002-07-17 12:30:42
Message-ID: Pine.LNX.4.21.0207171424170.7918-100000@shauny.shauny.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 ...

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Gibbs 2002-07-17 12:33:03 Re: Using index with order desc
Previous Message Peter Gibbs 2002-07-17 12:22:57 Re: Using index with order desc