Re: Change the behaviour of the SERIAL "Type"

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Dani Oderbolz <oderbolz(at)ecologic(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Change the behaviour of the SERIAL "Type"
Date: 2003-06-27 15:20:31
Message-ID: 20030627152031.GF15269@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Jun 27, 2003 at 16:35:36 +0200,
Dani Oderbolz <oderbolz(at)ecologic(dot)de> wrote:
> Well, why not just use the Sequence?
> Is there really such a performance hit when calling a trigger?

I think the big issue is concurrency. Sequences are designed so that
conncurrent uses of the sequence don't block each other. In the trigger
based methods you have to lock the value against concurrent update and
this lock will be held to the end of the transaction. This has the
potential to really hurt your performance.

I may have been misunderstanding what you are trying to do though.
If your problem was that people could update or insert values into
the serial column that might cause other transactions to unexpected
fail (when they try to use a duplicate value - assuming you use a unique
index on the column) then you could use a trigger to prevent updates
on that column and force inserts to always use nextval. If you need
to reload the database at some point, you will need to do something
to keep the triggers from interfering with the reload. This should
be fairly efficient.

I had thought you were concerned about possible gaps in the sequence.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Matthew Hixson 2003-06-27 23:09:31 need some help with a delete statement
Previous Message Bruno Wolff III 2003-06-27 15:10:25 Re: Getting all rows even if not a member of any groups