Re: Slow performance on MAX(primary_key)

From: Keith Gray <keith(at)heart(dot)com(dot)au>
To: Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com>
Cc: PostgreSQL Mailing List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Slow performance on MAX(primary_key)
Date: 2002-10-15 07:47:13
Message-ID: 3DABC801.8060902@heart.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Ludwig Lim wrote:

>>I have just been comparing some large table
>>performance under 7.1 using the
>>
>> select max(primary key)from table;
>>
>
> Try using the following as alternative :
>
> SELECT primary_key
> FROM table
> ORDER BY primary_key desc
> LIMIT 1;
>
> This should work if primary_key is indexes.
>
> As of now, Max() doesn't utilizes the indices hence
> it always do a sequential scan.

Thanks Ludwig,

That does help performance, but I was using a "standard"
SQL command wrapped in a VB6 ADO ODBC program.

Is this likely to be sorted in 7.2 ?
Is anyone looking at this?

--

Keith Gray
Technical Services Manager
Heart Consulting Services

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2002-10-15 08:17:26 Re: Stored procedure returning row or resultset
Previous Message Ludwig Lim 2002-10-15 07:16:28 Re: Slow performance on MAX(primary_key)