pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ludwig Lim <lud_nowhere_man@yahoo.com>
To: Keith Gray <keith@heart.com.au>
Cc: PostgreSQL Mailing List <pgsql-sql@postgresql.org>
Subject: Re: Slow performance on MAX(primary_key)
Date: Tue, 15 Oct 2002 00:16:28 -0700 (PDT)
Message-ID: <20021015071628.57518.qmail@web80304.mail.yahoo.com> (raw)
In-Reply-To: <3DABA146.7010902@heart.com.au>


Hi Keith:

--- Keith Gray <keith@heart.com.au> 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



view thread (7+ messages)  latest in thread

Message-ID: <20021015071628.57518.qmail@web80304.mail.yahoo.com>
Permalink:  ../20021015071628.57518.qmail@web80304.mail.yahoo.com/
Also on:    postgresql.org/message-id/20021015071628.57518.qmail@web80304.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: lud_nowhere_man@yahoo.com, keith@heart.com.au
  Subject: Re: Slow performance on MAX(primary_key)
  In-Reply-To: <20021015071628.57518.qmail@web80304.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox