1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

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
This commit is contained in:
Alvaro Herrera
2014-10-07 17:23:34 -03:00
parent c421efd213
commit df630b0dd5
38 changed files with 907 additions and 121 deletions

View File

@ -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 */