mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +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) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.186 2005/04/14 20:03:24 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.187 2005/04/28 21:47:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1592,12 +1592,12 @@ GetTupleForTrigger(EState *estate, ResultRelInfo *relinfo,
|
||||
HTSU_Result test;
|
||||
|
||||
/*
|
||||
* mark tuple for update
|
||||
* lock tuple for update
|
||||
*/
|
||||
*newSlot = NULL;
|
||||
tuple.t_self = *tid;
|
||||
ltrmark:;
|
||||
test = heap_mark4update(relation, &tuple, &buffer, cid);
|
||||
test = heap_lock_tuple(relation, &tuple, &buffer, cid, LockTupleExclusive);
|
||||
switch (test)
|
||||
{
|
||||
case HeapTupleSelfUpdated:
|
||||
@ -1636,8 +1636,7 @@ ltrmark:;
|
||||
|
||||
default:
|
||||
ReleaseBuffer(buffer);
|
||||
elog(ERROR, "unrecognized heap_mark4update status: %u",
|
||||
test);
|
||||
elog(ERROR, "invalid heap_lock_tuple status: %d", test);
|
||||
return NULL; /* keep compiler quiet */
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user