Re: Sequences in transaction

Поиск
Список
Период
Сортировка
От Mike Castle
Тема Re: Sequences in transaction
Дата
Msg-id 20001204172943.B19340@thune.mrc-home.org
обсуждение исходный текст
Ответ на Re: Sequences in transaction  (Camm Maguire <camm@enhanced.com>)
Список pgsql-general
On Mon, Dec 04, 2000 at 05:56:04PM -0500, Camm Maguire wrote:
> Greetings!  I've run into this too, and it appears to me not to roll
> back either.  A pity, as it forced us to make a separate table to hold
> the last sequence value and update the table in a trigger.

This is a dangerous thing if you ever have more than one update going on.

One transaction reads the value, increments it, saves it back.  Another
transaction does the same thing.  Now you have two transactions trying to
use the same value.  Sure, one will probably fail a uniqueness constraint,
but then you have to increment again.  Meanwhile, another transaction comes
in and steals the next number, and one of the first two clashes again.  And
again.  And again.  And again.  You have NO way of guaranteeing that
starvation will never be an issue.

Solution:

Don't require that your sequence values be absolutely sequential.  They're
there to ensure uniquness and order.  Not to be used as counters.

mrc
--
       Mike Castle       Life is like a clock:  You can work constantly
  dalgoda@ix.netcom.com  and be right all the time, or not work at all
www.netcom.com/~dalgoda/ and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen

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

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: strange query plans
Следующее
От: Mike Castle
Дата:
Сообщение: Re: Why PostgreSQL is not that popular as MySQL?