mirror of
https://github.com/postgres/postgres.git
synced 2025-11-29 23:43:17 +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:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.104 2004/12/31 22:00:09 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.105 2005/04/28 21:47:13 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -323,11 +323,11 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
|
||||
Assert(bms_is_subset(rel->outerjoinset, outerrels));
|
||||
|
||||
/*
|
||||
* Presently the executor cannot support FOR UPDATE marking of
|
||||
* Presently the executor cannot support FOR UPDATE/SHARE marking of
|
||||
* rels appearing on the nullable side of an outer join. (It's
|
||||
* somewhat unclear what that would mean, anyway: what should we
|
||||
* mark when a result row is generated from no element of the
|
||||
* nullable relation?) So, complain if target rel is FOR UPDATE.
|
||||
* nullable relation?) So, complain if target rel is FOR UPDATE/SHARE.
|
||||
* It's sufficient to make this check once per rel, so do it only
|
||||
* if rel wasn't already known nullable.
|
||||
*/
|
||||
@@ -336,7 +336,7 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
|
||||
if (list_member_int(root->rowMarks, relno))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SELECT FOR UPDATE cannot be applied to the nullable side of an outer join")));
|
||||
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an outer join")));
|
||||
}
|
||||
|
||||
rel->outerjoinset = outerrels;
|
||||
|
||||
Reference in New Issue
Block a user