Re: Change the behaviour of the SERIAL "Type" - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: Change the behaviour of the SERIAL "Type"
Date
Msg-id 20030627152031.GF15269@wolff.to
Whole thread Raw
In response to Re: Change the behaviour of the SERIAL "Type"  (Dani Oderbolz <oderbolz@ecologic.de>)
List pgsql-sql
On Fri, Jun 27, 2003 at 16:35:36 +0200, Dani Oderbolz <oderbolz@ecologic.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.


pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Getting all rows even if not a member of any groups
Next
From:
Date:
Subject: Re: Postgres - Delphi Application