Re: Best approach for a "gap-less" sequence

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jorge Godoy <jgodoy(at)gmail(dot)com>
Cc: Chris <dmagick(at)gmail(dot)com>, PostgreSQL General ML <pgsql-general(at)postgresql(dot)org>
Subject: Re: Best approach for a "gap-less" sequence
Date: 2006-08-14 12:16:06
Message-ID: 20060814121606.GA62971@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 14, 2006 at 09:09:51AM -0300, Jorge Godoy wrote:
> Chris <dmagick(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jorge Godoy 2006-08-14 13:23:24 Re: Best approach for a "gap-less" sequence
Previous Message Jorge Godoy 2006-08-14 12:09:51 Re: Best approach for a "gap-less" sequence