Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group