* Given a RangeVar describing an existing relation,
* select the proper namespace and look up the relation OID.
*
- * If the schema or relation is not found, return InvalidOid if missing_ok
- * = true, otherwise raise an error.
+ * If the schema or relation is not found, return InvalidOid if flags contains
+ * RVR_MISSING_OK, otherwise raise an error.
*
- * If nowait = true, throw an error if we'd have to wait for a lock.
+ * If flags contains RVR_NOWAIT, throw an error if we'd have to wait for a
+ * lock.
*
* Callback allows caller to check permissions or acquire additional locks
* prior to grabbing the relation lock.
*/
Oid
RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
- bool missing_ok, bool nowait,
+ uint32 flags,
RangeVarGetRelidCallback callback, void *callback_arg)
{
uint64 inval_count;
Oid relId;
Oid oldRelId = InvalidOid;
bool retry = false;
+ bool missing_ok = (flags & RVR_MISSING_OK) != 0;
/*
* We check the catalog name and then ignore it.
*/
if (!OidIsValid(relId))
AcceptInvalidationMessages();
- else if (!nowait)
+ else if (!(flags & RVR_NOWAIT))
LockRelationOid(relId, lockmode);
else if (!ConditionalLockRelationOid(relId, lockmode))
{
oldRelId = relId;
}
- if (!OidIsValid(relId) && !missing_ok)
+ if (!OidIsValid(relId))
{
+ int elevel = missing_ok ? DEBUG1 : ERROR;
+
if (relation->schemaname)
- ereport(ERROR,
+ ereport(elevel,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s.%s\" does not exist",
relation->schemaname, relation->relname)));
else
- ereport(ERROR,
+ ereport(elevel,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
relation->relname)));
/* Find, lock, and check permissions on the table */
tableOid = RangeVarGetRelidExtended(stmt->relation,
AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackOwnsTable, NULL);
rel = heap_open(tableOid, NoLock);
* used here must match the index lock obtained in reindex_index().
*/
indOid = RangeVarGetRelidExtended(indexRelation, AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackForReindexIndex,
(void *) &heapOid);
Oid heapOid;
/* The lock level used here should match reindex_relation(). */
- heapOid = RangeVarGetRelidExtended(relation, ShareLock, false, false,
+ heapOid = RangeVarGetRelidExtended(relation, ShareLock, 0,
RangeVarCallbackOwnsTable, NULL);
if (!reindex_relation(heapOid,
bool recurse = rv->inh;
Oid reloid;
- reloid = RangeVarGetRelidExtended(rv, lockstmt->mode, false,
- lockstmt->nowait,
+ reloid = RangeVarGetRelidExtended(rv, lockstmt->mode,
+ lockstmt->nowait ? RVR_NOWAIT : 0,
RangeVarCallbackForLockTable,
(void *) &lockstmt->mode);
* Get a lock until end of transaction.
*/
matviewOid = RangeVarGetRelidExtended(stmt->relation,
- lockmode, false, false,
+ lockmode, 0,
RangeVarCallbackOwnsTable, NULL);
matviewRel = heap_open(matviewOid, NoLock);
/* Get id of table. Also handles permissions checks. */
table_id = RangeVarGetRelidExtended(stmt->table, AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackForPolicy,
(void *) stmt);
/* Get id of table. Also handles permissions checks. */
table_id = RangeVarGetRelidExtended(stmt->table, AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackForPolicy,
(void *) stmt);
/* Get id of table. Also handles permissions checks. */
table_id = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackForPolicy,
(void *) stmt);
/* Open and lock sequence, and check for ownership along the way. */
relid = RangeVarGetRelidExtended(stmt->sequence,
ShareRowExclusiveLock,
- stmt->missing_ok,
- false,
+ stmt->missing_ok ? RVR_MISSING_OK : 0,
RangeVarCallbackOwnsRelation,
NULL);
if (relid == InvalidOid)
state.heapOid = InvalidOid;
state.partParentOid = InvalidOid;
state.concurrent = drop->concurrent;
- relOid = RangeVarGetRelidExtended(rel, lockmode, true,
- false,
+ relOid = RangeVarGetRelidExtended(rel, lockmode, RVR_MISSING_OK,
RangeVarCallbackForDropRelation,
(void *) &state);
/* lock level taken here should match renameatt_internal */
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
- stmt->missing_ok, false,
+ stmt->missing_ok ? RVR_MISSING_OK : 0,
RangeVarCallbackForRenameAttribute,
NULL);
{
/* lock level taken here should match rename_constraint_internal */
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
- stmt->missing_ok, false,
+ stmt->missing_ok ? RVR_MISSING_OK : 0,
RangeVarCallbackForRenameAttribute,
NULL);
if (!OidIsValid(relid))
* escalation.
*/
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
- stmt->missing_ok, false,
+ stmt->missing_ok ? RVR_MISSING_OK : 0,
RangeVarCallbackForAlterRelation,
(void *) stmt);
Oid
AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
{
- return RangeVarGetRelidExtended(stmt->relation, lockmode, stmt->missing_ok, false,
+ return RangeVarGetRelidExtended(stmt->relation, lockmode,
+ stmt->missing_ok ? RVR_MISSING_OK : 0,
RangeVarCallbackForAlterRelation,
(void *) stmt);
}
ObjectAddress myself;
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
- stmt->missing_ok, false,
+ stmt->missing_ok ? RVR_MISSING_OK : 0,
RangeVarCallbackForAlterRelation,
(void *) stmt);
state.parentTblOid = parentIdx->rd_index->indrelid;
state.lockedParentTbl = false;
partIdxId =
- RangeVarGetRelidExtended(name, AccessExclusiveLock, false, false,
+ RangeVarGetRelidExtended(name, AccessExclusiveLock, 0,
RangeVarCallbackForAttachIndex,
(void *) &state);
/* Not there? */
* release until end of transaction).
*/
relid = RangeVarGetRelidExtended(stmt->relation, AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackForRenameTrigger,
NULL);
* release until end of transaction).
*/
relid = RangeVarGetRelidExtended(relation, AccessExclusiveLock,
- false, false,
+ 0,
RangeVarCallbackForRenameRule,
NULL);
: ShareLock;
relid =
RangeVarGetRelidExtended(stmt->relation, lockmode,
- false, false,
+ 0,
RangeVarCallbackOwnsRelation,
NULL);
bool addTemp; /* implicitly prepend temp schema? */
} OverrideSearchPath;
+/*
+ * Option flag bits for RangeVarGetRelidExtended().
+ */
+typedef enum RVROption
+{
+ RVR_MISSING_OK = 1 << 0, /* don't error if relation doesn't exist */
+ RVR_NOWAIT = 1 << 1 /* error if relation cannot be locked */
+} RVROption;
+
typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId,
Oid oldRelId, void *callback_arg);
#define RangeVarGetRelid(relation, lockmode, missing_ok) \
- RangeVarGetRelidExtended(relation, lockmode, missing_ok, false, NULL, NULL)
+ RangeVarGetRelidExtended(relation, lockmode, \
+ (missing_ok) ? RVR_MISSING_OK : 0, NULL, NULL)
extern Oid RangeVarGetRelidExtended(const RangeVar *relation,
- LOCKMODE lockmode, bool missing_ok, bool nowait,
+ LOCKMODE lockmode, uint32 flags,
RangeVarGetRelidCallback callback,
void *callback_arg);
extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation);