RE: User locks code - Mailing list pgsql-hackers

From Lincoln Yeoh
Subject RE: User locks code
Date
Msg-id 3.0.5.32.20010821142606.01037a40@192.228.128.13
Whole thread Raw
In response to User locks code  ("Mikheev, Vadim" <vmikheev@SECTORBASE.COM>)
List pgsql-hackers
At 09:39 AM 20-08-2001 -0700, Mikheev, Vadim wrote:
>> If it does then one of the things I'd use it for is to insert
>> unique data without having to lock the table or rollback on
>> failed insert (unique index still kept as a guarantee).
>
>(Classic example how could be used SAVEPOINTs -:))

I guess so. But this could be faster.

>So, in your application you would first lock a key in excl mode
>(for duration of transaction), than try to select and insert unless
>found? (Note that this will not work with serializable isolevel.)

yep:
lock "tablename.colname.val=1"
select count(*) from tablename where colname=1
If no rows, insert, else update.
(dunno if the locks would scale to a scenario with hundreds of concurrent
inserts - how many user locks max?).

Why wouldn't it work with serializable isolevel?

Anyway, I believe that isolevel doesn't really serialise things in this
case (inserting a unique row) so it wouldn't matter to me.

Regards,
Link.



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Locale by default?
Next
From: Karel Zak
Date:
Subject: Re: encoding: ODBC, createdb