Re: How to create "auto-increment" field WITHOUT a sequence object?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to create "auto-increment" field WITHOUT a sequence object?
Date: 2011-07-01 08:34:36
Message-ID: 4E0D869C.6030205@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/07/2011 4:21 PM, Chris Travers wrote:

> means a possibility of deadlocks and performance issues. These issues
> are inherent in gapless numbering because you can't get a gapless
> sequence when things roll back without such locks.

Actually, another approach that allows parallel transactions is (at
least theoretically) possible. You can hand out IDs as transactions
request them, and if a transaction rolls back you can abort it *and*
*all* *transactions* *given* *higher* *IDs*, then re-issue the lot. I
guess that could be useful if transaction failure was extremely unlikely
and you needed to have lots of work in flight at once.

In practice I don't think it'd be very useful to do this, because
transactions would still have to commit in the order they obtained IDs
in, so a slow or blocked transaction would still stall the system just
like it does with lock-based gapless numbering. Also, once a later
transaction had obtained an ID prior transactions couldn't obtain any
more IDs.

I'm not sure this is possible in Pg without modifying the server,
either. It'd be kind of interesting in a useless-toy-project kind of way.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ronan Dunklau 2011-07-01 08:37:44 Anonymous record type and inner types.
Previous Message Dmitriy Igrishin 2011-07-01 08:28:47 Re: How to create "auto-increment" field WITHOUT a sequence object?