mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +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:
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.235 2005/04/14 01:38:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.236 2005/04/28 21:47:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -238,7 +238,7 @@ QueryIsReadOnly(Query *parsetree)
|
||||
if (parsetree->into != NULL)
|
||||
return false; /* SELECT INTO */
|
||||
else if (parsetree->rowMarks != NIL)
|
||||
return false; /* SELECT FOR UPDATE */
|
||||
return false; /* SELECT FOR UPDATE/SHARE */
|
||||
else
|
||||
return true;
|
||||
case CMD_UPDATE:
|
||||
@@ -1663,7 +1663,12 @@ CreateQueryTag(Query *parsetree)
|
||||
if (parsetree->into != NULL)
|
||||
tag = "SELECT INTO";
|
||||
else if (parsetree->rowMarks != NIL)
|
||||
tag = "SELECT FOR UPDATE";
|
||||
{
|
||||
if (parsetree->forUpdate)
|
||||
tag = "SELECT FOR UPDATE";
|
||||
else
|
||||
tag = "SELECT FOR SHARE";
|
||||
}
|
||||
else
|
||||
tag = "SELECT";
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user