Re: Am I locking more than I need to?

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: Am I locking more than I need to?
Дата
Msg-id 1085178241.2274.994.camel@jeff
обсуждение исходный текст
Ответ на Re: Am I locking more than I need to?  ("Carl E. McMillin" <carlymac@earthlink.net>)
Ответы Re: Am I locking more than I need to?  ("Carl E. McMillin" <carlymac@earthlink.net>)
Re: Am I locking more than I need to?  (Mike Rylander <miker@purplefrog.com>)
Список pgsql-general
On Fri, 2004-05-21 at 14:33, Carl E. McMillin wrote:
> Scenario:
>
> SELECT ... WHERE cart_id=X FOR UPDATE
>
> IF (NOT FOUND) THEN
>   BEGIN
> --Here is where nothing is locked.
> --No way to guarantee no one else will create a record before we do.
>   INSERT ...
>   END;
> END IF;
>

Instead, I was thinking more like:

BEGIN
SELECT ... WHERE cart_id=X FOR UPDATE
IF (NOT FOUND) THEN
--Here is where nothing is locked.
--No way to guarantee no one else will create a record before we do.
  INSERT ...
ELSE
  UPDATE ...
END IF;
END;

Won't that "SELECT ... FOR UPDATE" block out a concurrent access to the
same cart until the first one finishes? Of course this assumes all
concurrent accesses also try to "SELECT ... FOR UPDATE" before
inserting.

Thanks,
Jeff Davis




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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: extreme memory use when loading in a lot of data
Следующее
От: "Carl E. McMillin"
Дата:
Сообщение: Re: Am I locking more than I need to?