Re: Slow performance on MAX(primary_key)

Keith Gray <keith@heart.com.au>

From: Keith Gray <keith@heart.com.au>
To: Ludwig Lim <lud_nowhere_man@yahoo.com>
Cc: PostgreSQL Mailing List <pgsql-sql@postgresql.org>
Date: 2002-10-15T07:47:13Z
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