Re: Slow query to get last created row using CURRVAL

Поиск
Список
Период
Сортировка
От Marti Raudsepp
Тема Re: Slow query to get last created row using CURRVAL
Дата
Msg-id AANLkTi=0Vc44yQwhx2mR2XKBUqBuoj-nPK8--Jwdx2Cg@mail.gmail.com
обсуждение исходный текст
Ответ на Slow query to get last created row using CURRVAL  (Mathieu De Zutter <mathieu@dezutter.org>)
Ответы Re: Slow query to get last created row using CURRVAL  (Mathieu De Zutter <mathieu@dezutter.org>)
Список pgsql-performance
On Sat, Dec 4, 2010 at 13:56, Mathieu De Zutter <mathieu@dezutter.org> wrote:
> I have no idea why in some cases the index scan is not considered.
> Does anyone have an idea?

I guess that it's because the currval() function is volatile -- its
value has to be tested for again each row.

Try this instead:
SELECT user_id FROM log_event WHERE id = (SELECT CURRVAL('log_event_id_seq'));

This will assure that there's only one call to currval().

Regards,
Marti

В списке pgsql-performance по дате отправления:

Предыдущее
От: Mathieu De Zutter
Дата:
Сообщение: Slow query to get last created row using CURRVAL
Следующее
От: Mathieu De Zutter
Дата:
Сообщение: Re: Slow query to get last created row using CURRVAL