1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-17 17:02:08 +03:00

Improve the representation of FOR UPDATE/FOR SHARE so that we can

support both FOR UPDATE and FOR SHARE in one command, as well as both
NOWAIT and normal WAIT behavior.  The more general code is actually
simpler and cleaner.
This commit is contained in:
Tom Lane
2006-04-30 18:30:40 +00:00
parent 931bfc9664
commit 986085a7f0
29 changed files with 320 additions and 245 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.122 2006/03/23 00:19:30 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.123 2006/04/30 18:30:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1001,6 +1001,8 @@ addRangeTableEntryForJoin(ParseState *pstate,
/*
* Has the specified refname been selected FOR UPDATE/FOR SHARE?
*
* Note: we pay no attention to whether it's FOR UPDATE vs FOR SHARE.
*/
static bool
isLockedRel(ParseState *pstate, char *refname)
@ -1008,9 +1010,13 @@ isLockedRel(ParseState *pstate, char *refname)
/* Outer loop to check parent query levels as well as this one */
while (pstate != NULL)
{
if (pstate->p_locking_clause)
ListCell *l;
foreach(l, pstate->p_locking_clause)
{
if (pstate->p_locking_clause->lockedRels == NIL)
LockingClause *lc = (LockingClause *) lfirst(l);
if (lc->lockedRels == NIL)
{
/* all tables used in query */
return true;
@ -1018,11 +1024,11 @@ isLockedRel(ParseState *pstate, char *refname)
else
{
/* just the named tables */
ListCell *l;
ListCell *l2;
foreach(l, pstate->p_locking_clause->lockedRels)
foreach(l2, lc->lockedRels)
{
char *rname = strVal(lfirst(l));
char *rname = strVal(lfirst(l2));
if (strcmp(refname, rname) == 0)
return true;
@ -1702,6 +1708,26 @@ get_tle_by_resno(List *tlist, AttrNumber resno)
return NULL;
}
/*
* Given a Query and rangetable index, return relation's RowMarkClause if any
*
* Returns NULL if relation is not selected FOR UPDATE/SHARE
*/
RowMarkClause *
get_rowmark(Query *qry, Index rtindex)
{
ListCell *l;
foreach(l, qry->rowMarks)
{
RowMarkClause *rc = (RowMarkClause *) lfirst(l);
if (rc->rti == rtindex)
return rc;
}
return NULL;
}
/*
* given relation and att name, return attnum of variable
*