Re: Index not being used in MAX function (7.2.3)
От
Ernest E Vogelsinger
Тема
Re: Index not being used in MAX function (7.2.3)
Дата
Msg-id
5.1.1.6.2.20030610234755.03b44698@mail.vogelsinger.at
Ответ на
Index not being used in MAX function (7.2.3) (Paulo Jan)
Список
Дерево обсуждения
Re: Index not being used in MAX function (7.2.3) "Dann Corbit" <DCorbit@connx.com>
At 18:39 10.06.2003, Paulo Jan said:
--------------------[snip]--------------------
>Hi all:
>
> I have here a table belonging to a message board (Phorum 3.3), and
>there's an index in it that is not being used for reasons that I don't
>understand. The table is:
>
> ...
>
> select max(id) from todocinetv;
--------------------[snip]--------------------
Your question has already been answered, but:
I suspect that you're doing this to retrieve the row ID of a newly inserted
row. This may not be foolproof since others could already have inserted
rows in between your insertion and this ID lookup.
Assuming that you're using a sequence to provide the primary key (which you
should) you may safely query its current value:
SELECT currval('todocinetv_id_seq') as "newid"
This is guaranteed to return the last value **for your connection** only,
regardless if the sequence has actually been incremented by others or not.
And it's lightning fast.
Just my 2c :)
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
В списке pgsql-general по дате отправления
От: Forest Wilkinson
Дата: