Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 44927475ADD for ; Tue, 15 Oct 2002 03:49:42 -0400 (EDT) Received: from gateway.heart.com.au (202-44-184-121.nexnet.net.au [202.44.184.121]) by postgresql.org (Postfix) with ESMTP id C9325475EEB for ; Tue, 15 Oct 2002 03:49:35 -0400 (EDT) Received: from tardis.heart.com.au (IDENT:root@tardis.heart.com.au [192.168.0.42]) by gateway.heart.com.au (8.11.6/8.11.2) with ESMTP id g9F8QNI28023; Tue, 15 Oct 2002 18:26:23 +1000 Received: from heart.com.au ([192.168.0.53]) by tardis.heart.com.au (8.9.3/8.8.7) with ESMTP id RAA05612; Tue, 15 Oct 2002 17:49:20 +1000 Message-ID: <3DABC801.8060902@heart.com.au> Date: Tue, 15 Oct 2002 17:47:13 +1000 From: Keith Gray User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3 X-Accept-Language: en-us MIME-Version: 1.0 To: Ludwig Lim Cc: PostgreSQL Mailing List Subject: Re: Slow performance on MAX(primary_key) References: <20021015071628.57518.qmail@web80304.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/153 X-Sequence-Number: 9870 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