aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeLockRows.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2014-10-07 17:23:34 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2014-10-07 17:23:34 -0300
commitdf630b0dd5ea2de52972d456f5978a012436115e (patch)
treebe0007351a856caa48230155f5c5bcfe5a31f86d /src/backend/executor/nodeLockRows.c
parentc421efd21330f2e5bed253b4a53d7ea5e084edf6 (diff)
downloadpostgresql-df630b0dd5ea2de52972d456f5978a012436115e.tar.gz
postgresql-df630b0dd5ea2de52972d456f5978a012436115e.zip
Implement SKIP LOCKED for row-level locks
This clause changes the behavior of SELECT locking clauses in the presence of locked rows: instead of causing a process to block waiting for the locks held by other processes (or raise an error, with NOWAIT), SKIP LOCKED makes the new reader skip over such rows. While this is not appropriate behavior for general purposes, there are some cases in which it is useful, such as queue-like tables. Catalog version bumped because this patch changes the representation of stored rules. Reviewed by Craig Ringer (based on a previous attempt at an implementation by Simon Riggs, who also provided input on the syntax used in the current patch), David Rowley, and Álvaro Herrera. Author: Thomas Munro
Diffstat (limited to 'src/backend/executor/nodeLockRows.c')
-rw-r--r--src/backend/executor/nodeLockRows.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/executor/nodeLockRows.c b/src/backend/executor/nodeLockRows.c
index 814b61efcba..990240bf0a8 100644
--- a/src/backend/executor/nodeLockRows.c
+++ b/src/backend/executor/nodeLockRows.c
@@ -133,11 +133,15 @@ lnext:
test = heap_lock_tuple(erm->relation, &tuple,
estate->es_output_cid,
- lockmode, erm->noWait, true,
+ lockmode, erm->waitPolicy, true,
&buffer, &hufd);
ReleaseBuffer(buffer);
switch (test)
{
+ case HeapTupleWouldBlock:
+ /* couldn't lock tuple in SKIP LOCKED mode */
+ goto lnext;
+
case HeapTupleSelfUpdated:
/*
@@ -170,12 +174,15 @@ lnext:
}
/* updated, so fetch and lock the updated version */
- copyTuple = EvalPlanQualFetch(estate, erm->relation, lockmode, erm->noWait,
- &hufd.ctid, hufd.xmax);
+ copyTuple = EvalPlanQualFetch(estate, erm->relation, lockmode,
+ erm->waitPolicy, &hufd.ctid, hufd.xmax);
if (copyTuple == NULL)
{
- /* Tuple was deleted, so don't return it */
+ /*
+ * Tuple was deleted; or it's locked and we're under SKIP
+ * LOCKED policy, so don't return it
+ */
goto lnext;
}
/* remember the actually locked tuple's TID */