Re: Row locking within a SELECT statement

Поиск
Список
Период
Сортировка
От P. Christeas
Тема Re: Row locking within a SELECT statement
Дата
Msg-id 23360955.XyY9xrDyAl@xorhgos3.pefnos
обсуждение исходный текст
Ответ на Re: Row locking within a SELECT statement  (Marko Tiikkaja <marko@joh.to>)
Список pgsql-docs
Στις Τρι 16 Αυγ 2016 11:23:59 π.μ. Marko Tiikkaja έγραψε:
> On 2016-08-16 08:19, xrg@linux.gr wrote:
> > In order to avoid concurrent manipulation of rows, I do issue a
> > "SELECT .. FOR UPDATE" on the sets of rows, before UPDATEing
> > them (because UPDATEs cannot be ordered).
>
> Yeah, but FOR UPDATEs are not ordered either unless you use ORDER BY,
> which you didn't.

So, the case is that these two statements:
    SELECT id FROM alerts ORDER BY id FOR UPDATE;
and
    SELECT id FROM alerts ORDER BY id DESC FOR UPDATE;
are guarranteed to deadlock [1], right?

Well, in my opinion, this anti-pattern deserves to be documented.

Thank you for the quick response.

[1] because each of those statements will begin locking rows, one at a time,
and then reach the ones of the other statement and wait.



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

Предыдущее
От: Marko Tiikkaja
Дата:
Сообщение: Re: Row locking within a SELECT statement
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Outdated sentence in the pg_am description