From bedb78d386a47fd66b6cda2040e0a5fb545ee371 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 28 Apr 2005 21:47:18 +0000 Subject: 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. --- src/backend/nodes/outfuncs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/backend/nodes/outfuncs.c') diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 484551a850..2dc676b8d4 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.250 2005/04/25 01:30:13 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.251 2005/04/28 21:47:13 tgl Exp $ * * NOTES * Every node type that can appear in stored rules' parsetrees *must* @@ -1268,7 +1268,8 @@ _outSelectStmt(StringInfo str, SelectStmt *node) WRITE_NODE_FIELD(sortClause); WRITE_NODE_FIELD(limitOffset); WRITE_NODE_FIELD(limitCount); - WRITE_NODE_FIELD(forUpdate); + WRITE_NODE_FIELD(lockedRels); + WRITE_BOOL_FIELD(forUpdate); WRITE_ENUM_FIELD(op, SetOperation); WRITE_BOOL_FIELD(all); WRITE_NODE_FIELD(larg); @@ -1385,6 +1386,7 @@ _outQuery(StringInfo str, Query *node) WRITE_NODE_FIELD(rtable); WRITE_NODE_FIELD(jointree); WRITE_NODE_FIELD(rowMarks); + WRITE_BOOL_FIELD(forUpdate); WRITE_NODE_FIELD(targetList); WRITE_NODE_FIELD(groupClause); WRITE_NODE_FIELD(havingQual); -- cgit v1.2.1