Re: select max(id) from aTable is very slow

From: David Teran <david(dot)teran(at)cluster9(dot)com>
To: Nick Barr <nicky(at)chuckie(dot)co(dot)uk>
Cc: PgSQL Performance ML <pgsql-performance(at)postgresql(dot)org>
Subject: Re: select max(id) from aTable is very slow
Date: 2004-02-16 18:15:16
Message-ID: 125FCD10-60AC-11D8-B420-000A95A6F0DC@cluster9.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Saleem Burhani Baloch 2004-02-17 06:24:02 Slow response of PostgreSQL
Previous Message Nick Barr 2004-02-16 18:02:10 Re: select max(id) from aTable is very slow