Cost of max

From: Stefano Bargioni <bargioni(at)usc(dot)urbe(dot)it>
To: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Cost of max
Date: 2000-12-28 08:53:02
Message-ID: 3A4AFF6E.F2F45D30@usc.urbe.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 is for 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(at)usc(dot)urbe(dot)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) ---

Browse pgsql-general by date

  From Date Subject
Next Message Jens Hartwig 2000-12-28 09:33:46 Re: User Privileges
Previous Message Kevin Lo 2000-12-28 05:19:36 Re: Tuning Database