Re: Slow performance on MAX(primary_key) - Mailing list pgsql-sql

From Keith Gray
Subject Re: Slow performance on MAX(primary_key)
Date
Msg-id 3DABC801.8060902@heart.com.au
Whole thread Raw
In response to Re: Slow performance on MAX(primary_key)  (Ludwig Lim <lud_nowhere_man@yahoo.com>)
Responses Re: Slow performance on MAX(primary_key)
List 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



pgsql-sql by date:

Previous
From: Ludwig Lim
Date:
Subject: Re: Slow performance on MAX(primary_key)
Next
From: Richard Huxton
Date:
Subject: Re: Stored procedure returning row or resultset