Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux