mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Implement sharable row-level locks, and use them for foreign key references
to eliminate unnecessary deadlocks. This commit adds SELECT ... FOR SHARE paralleling SELECT ... FOR UPDATE. The implementation uses a new SLRU data structure (managed much like pg_subtrans) to represent multiple- transaction-ID sets. When more than one transaction is holding a shared lock on a particular row, we create a MultiXactId representing that set of transactions and store its ID in the row's XMAX. This scheme allows an effectively unlimited number of row locks, just as we did before, while not costing any extra overhead except when a shared lock actually has to be shared. Still TODO: use the regular lock manager to control the grant order when multiple backends are waiting for a row lock. Alvaro Herrera and Tom Lane.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.99 2005/04/14 20:03:27 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.100 2005/04/28 21:47:16 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -123,6 +123,12 @@ extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
|
||||
|
||||
/* heapam.c */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LockTupleShared,
|
||||
LockTupleExclusive
|
||||
} LockTupleMode;
|
||||
|
||||
extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
|
||||
extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait);
|
||||
extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
||||
@@ -155,8 +161,8 @@ extern HTSU_Result heap_delete(Relation relation, ItemPointer tid, ItemPointer c
|
||||
CommandId cid, Snapshot crosscheck, bool wait);
|
||||
extern HTSU_Result heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
|
||||
ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait);
|
||||
extern HTSU_Result heap_mark4update(Relation relation, HeapTuple tup,
|
||||
Buffer *userbuf, CommandId cid);
|
||||
extern HTSU_Result heap_lock_tuple(Relation relation, HeapTuple tup,
|
||||
Buffer *userbuf, CommandId cid, LockTupleMode mode);
|
||||
|
||||
extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
|
||||
extern void simple_heap_delete(Relation relation, ItemPointer tid);
|
||||
|
||||
Reference in New Issue
Block a user