optimizer question

Reinoud van Leeuwen <reinoud@xs4all.nl>

From: "Reinoud van Leeuwen" <reinoud@xs4all.nl>
To: <pgsql-hackers@postgresql.org>
Date: 2001-09-26T12:53:14Z
Lists: pgsql-hackers
Hi, 

I have a table that contains almost 8 milion rows. The primary key is a 
sequence, so the index should have a good distribution. Why does the 
optimizer refuse to use the index for getting the maximum value?
(even after a vacuum analyze of the table)

radius=# explain select max(radiuspk) from radius ;
NOTICE:  QUERY PLAN:

Aggregate  (cost=257484.70..257484.70 rows=1 width=8)
  ->  Seq Scan on radius  (cost=0.00..237616.76 rows=7947176 width=8)


Table and key info:

Did not find any relation named "radius_pk".
radius=# \d radius
                                         Table "radius"
      Attribute      |           Type           |             Modifier   
---------------------+--------------------------+---------------------------
 sessionid           | character varying(30)    | not null
 username            | character varying(30)    | not null
 nas_ip              | character varying(50)    | not null
 logfileid           | integer                  |
 login_ip_host       | character varying(50)    | not null
 framed_ip_address   | character varying(50)    |
 file_timestamp      | timestamp with time zone | not null
 corrected_timestamp | timestamp with time zone | not null
 acct_status_type    | smallint                 | not null
 bytesin             | bigint                   |
 bytesout            | bigint                   |
 handled             | boolean                  | not null default 'f'
 sessionhandled      | boolean                  | not null default 'f'
 radiuspk            | bigint                   | not null default nextval
('radiuspk_seq'::text)
Indices: pk_radius,
         radius_us

radius=# \d pk_radius
 Index "pk_radius"
 Attribute |  Type
-----------+--------
 radiuspk  | bigint
unique btree (primary key)