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 40 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().

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