> Would your suggested implementation allow locking on an
> arbitrary string?

Well, placing string in LOCKTAG is not good so we could
create auxilary hash table in shmem to keep such strings
and use string' address as part of LOCKTAG. New function
(LockRelationKey?) in lmgr.c would first find/place
key in that table, than construct LOCKTAG and call
LockAcquire.
Possible syntax:

LOCK TABLE relation IN {SHARE | EXCLUSIVE} MODE
	ON KEY user-string [FOR TRANSACTION | FOR SESSION];

UNLOCK (RELEASE?) TABLE relation {SHARE | EXCLUSIVE} LOCK
	ON KEY user-string;

(or just some built-in functions).

> 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 -:))

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.)

Comments?

Vadim

Mon, 20 Aug 2001 09:39:42 -0700
"Mikheev, Vadim" <vmikheev@SECTORBASE.COM>
RE: User locks code