summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/prepjointree.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-04-28 21:47:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-04-28 21:47:18 +0000
commitbedb78d386a47fd66b6cda2040e0a5fb545ee371 (patch)
tree0db0af8556ff82d94423e8e21362900afb18b7b6 /src/backend/optimizer/prep/prepjointree.c
parentd902e7d63ba2dc9cf0a1b051b2911b96831ef227 (diff)
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.
Diffstat (limited to 'src/backend/optimizer/prep/prepjointree.c')
-rw-r--r--src/backend/optimizer/prep/prepjointree.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 603b8c43582..b5b658cf58a 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.26 2005/04/06 16:34:06 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.27 2005/04/28 21:47:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -276,11 +276,22 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
parse->rtable = list_concat(parse->rtable, subquery->rtable);
/*
- * Pull up any FOR UPDATE markers, too. (OffsetVarNodes
+ * Pull up any FOR UPDATE/SHARE markers, too. (OffsetVarNodes
* already adjusted the marker values, so just list_concat the
* list.)
+ *
+ * Executor can't handle multiple FOR UPDATE/SHARE flags, so
+ * complain if they are valid but different
*/
+ if (parse->rowMarks && subquery->rowMarks &&
+ parse->forUpdate != subquery->forUpdate)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot use both FOR UPDATE and FOR SHARE in one query")));
+
parse->rowMarks = list_concat(parse->rowMarks, subquery->rowMarks);
+ if (subquery->rowMarks)
+ parse->forUpdate = subquery->forUpdate;
/*
* We also have to fix the relid sets of any parent