Cost of max - Mailing list pgsql-general

From Stefano Bargioni
Subject Cost of max
Date
Msg-id 3A4AFF6E.F2F45D30@usc.urbe.it
Whole thread Raw
List pgsql-general
I build a little test table with columns id serial, a text, b text. Why the cost of max(id) is made as a seq scan, as
isfor count(id)? This is a problem with very large tables. 
IMHO, select max(id) could be done using the index prova_id_key.
Your opinion? TIA. Stefano

mydb=> explain select max(id) from prova;
NOTICE:  QUERY PLAN:

Aggregate  (cost=43.00 rows=1000 width=4)
  ->  Seq Scan on prova  (cost=43.00 rows=1000 width=4)

EXPLAIN
mydb=> explain select count(id) from prova;
NOTICE:  QUERY PLAN:

Aggregate  (cost=43.00 rows=1000 width=4)
  ->  Seq Scan on prova  (cost=43.00 rows=1000 width=4)

--
Dott. Stefano Bargioni
Biblioteca della Pontificia Universita' della Santa Croce - Roma
<mailto:bargioni@usc.urbe.it>                  <http://www.usc.urbe.it>
Personal web page:    <http://www.usc.urbe.it/html/php.script?bargioni>
--- "Si apud bibliothecam hortulum habes, nihil deerit"  (Cicerone) ---



pgsql-general by date:

Previous
From: "Dan Wilson"
Date:
Subject: Re: User Privileges
Next
From: Jens Hartwig
Date:
Subject: Re: User Privileges