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

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Best approach for a "gap-less" sequence
Дата
Msg-id 20060814121606.GA62971@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: Best approach for a "gap-less" sequence  (Jorge Godoy <jgodoy@gmail.com>)
Ответы Re: Best approach for a "gap-less" sequence  (Jorge Godoy <godoy@ieee.org>)
Список 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 по дате отправления:

Предыдущее
От: Jorge Godoy
Дата:
Сообщение: Re: Best approach for a "gap-less" sequence
Следующее
От: Jorge Godoy
Дата:
Сообщение: Re: Best approach for a "gap-less" sequence