PostgreSQL Source Code  git master
lockcmds.h File Reference
#include "nodes/parsenodes.h"
Include dependency graph for lockcmds.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void LockTableCommand (LockStmt *lockstmt)
 

Function Documentation

◆ LockTableCommand()

void LockTableCommand ( LockStmt lockstmt)

Definition at line 41 of file lockcmds.c.

References get_rel_relkind(), GetUserId(), RangeVar::inh, lfirst, LockTableRecurse(), LockViewRecurse(), LockStmt::mode, NIL, LockStmt::nowait, PreventCommandDuringRecovery(), RangeVarCallbackForLockTable(), RangeVarGetRelidExtended(), LockStmt::relations, RowExclusiveLock, and RVR_NOWAIT.

Referenced by standard_ProcessUtility().

42 {
43  ListCell *p;
44 
45  /*---------
46  * During recovery we only accept these variations:
47  * LOCK TABLE foo IN ACCESS SHARE MODE
48  * LOCK TABLE foo IN ROW SHARE MODE
49  * LOCK TABLE foo IN ROW EXCLUSIVE MODE
50  * This test must match the restrictions defined in LockAcquireExtended()
51  *---------
52  */
53  if (lockstmt->mode > RowExclusiveLock)
54  PreventCommandDuringRecovery("LOCK TABLE");
55 
56  /*
57  * Iterate over the list and process the named relations one at a time
58  */
59  foreach(p, lockstmt->relations)
60  {
61  RangeVar *rv = (RangeVar *) lfirst(p);
62  bool recurse = rv->inh;
63  Oid reloid;
64 
65  reloid = RangeVarGetRelidExtended(rv, lockstmt->mode,
66  lockstmt->nowait ? RVR_NOWAIT : 0,
68  (void *) &lockstmt->mode);
69 
70  if (get_rel_relkind(reloid) == RELKIND_VIEW)
71  LockViewRecurse(reloid, lockstmt->mode, lockstmt->nowait, NIL);
72  else if (recurse)
73  LockTableRecurse(reloid, lockstmt->mode, lockstmt->nowait, GetUserId());
74  }
75 }
#define NIL
Definition: pg_list.h:65
bool nowait
Definition: parsenodes.h:3296
Oid GetUserId(void)
Definition: miscinit.c:380
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1805
static void LockViewRecurse(Oid reloid, LOCKMODE lockmode, bool nowait, List *ancestor_views)
Definition: lockcmds.c:270
unsigned int Oid
Definition: postgres_ext.h:31
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:275
static void LockTableRecurse(Oid reloid, LOCKMODE lockmode, bool nowait, Oid userid)
Definition: lockcmds.c:127
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:228
bool inh
Definition: primnodes.h:69
List * relations
Definition: parsenodes.h:3294
#define lfirst(lc)
Definition: pg_list.h:190
static void RangeVarCallbackForLockTable(const RangeVar *rv, Oid relid, Oid oldrelid, void *arg)
Definition: lockcmds.c:82