Re: Best approach for a "gap-less" sequence - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Best approach for a "gap-less" sequence
Date
Msg-id 20060814121606.GA62971@winnie.fuhr.org
Whole thread Raw
In response to Re: Best approach for a "gap-less" sequence  (Jorge Godoy <jgodoy@gmail.com>)
Responses Re: Best approach for a "gap-less" sequence  (Jorge Godoy <godoy@ieee.org>)
List pgsql-general
On Mon, Aug 14, 2006 at 09:09:51AM -0300, Jorge Godoy wrote:
> Chris <dmagick@gmail.com> writes:
> > P.S. I'm sure in older versions this query wouldn't use an index:
> > select max(id) from table;
>
> It doesn't.  You'd have to do what you did: "order by <x> desc limit 1" to
> have it using indexes...
>
> > I'm not sure about 8.0+.. hence doing an order by the id desc limit 1.
>
> I also have to test it...  But I still keep using the "order by desc" syntax

Excerpt from the 8.1 Release Notes:

  Automatically use indexes for MIN() and MAX() (Tom)

      In previous releases, the only way to use an index for MIN()
      or MAX() was to rewrite the query as SELECT col FROM tab ORDER
      BY col LIMIT 1.  Index usage now happens automatically.

--
Michael Fuhr

pgsql-general by date:

Previous
From: Jorge Godoy
Date:
Subject: Re: Best approach for a "gap-less" sequence
Next
From: Jorge Godoy
Date:
Subject: Re: Best approach for a "gap-less" sequence