Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5603D475AFF for ; Tue, 15 Oct 2002 03:16:28 -0400 (EDT) Received: from web80304.mail.yahoo.com (web80304.mail.yahoo.com [66.218.79.20]) by postgresql.org (Postfix) with SMTP id 26142475ADE for ; Tue, 15 Oct 2002 03:16:27 -0400 (EDT) Message-ID: <20021015071628.57518.qmail@web80304.mail.yahoo.com> Received: from [203.87.150.116] by web80304.mail.yahoo.com via HTTP; Tue, 15 Oct 2002 00:16:28 PDT Date: Tue, 15 Oct 2002 00:16:28 -0700 (PDT) From: Ludwig Lim Subject: Re: Slow performance on MAX(primary_key) To: Keith Gray Cc: PostgreSQL Mailing List In-Reply-To: <3DABA146.7010902@heart.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/152 X-Sequence-Number: 9869 Hi Keith: --- Keith Gray wrote: > Help, > > I have just been comparing some large table > performance > under 7.1 using the > > select max(primary key)from table; > > We are using this for various functions including > sequence. > 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. Hope that helps, regards, ludwig. __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com