Re: select max(id) from aTable is very slow - Mailing list pgsql-performance

From David Teran
Subject Re: select max(id) from aTable is very slow
Date
Msg-id 125FCD10-60AC-11D8-B420-000A95A6F0DC@cluster9.com
Whole thread Raw
In response to Re: select max(id) from aTable is very slow  (Nick Barr <nicky@chuckie.co.uk>)
List pgsql-performance
Hi Nick,

>> Try using:
>>
>> SELECT id FROM theTable ORDER BY is DESC LIMIT 1;
>>
>> Using COUNT, MAX, MIN and any aggregate function on the table of that
>> size will always result in a sequential scan. There is currently no
>> way around it although there are a few work arounds. See the
>> following for more information.
>>
>> http://archives.postgresql.org/pgsql-performance/2004-01/msg00045.php
>> http://archives.postgresql.org/pgsql-performance/2004-01/msg00054.php
>> http://archives.postgresql.org/pgsql-performance/2004-01/msg00059.php
>>


thanks, that works fine! I will read the mail archive before asking
such things again ;-)

cheers David


pgsql-performance by date:

Previous
From: Nick Barr
Date:
Subject: Re: select max(id) from aTable is very slow
Next
From: "Saleem Burhani Baloch"
Date:
Subject: Slow response of PostgreSQL