mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Allow callers to pass a missing_ok flag when opening a relation.
Since the names try_relation_openrv() and try_heap_openrv() don't seem quite appropriate, rename the functions to relation_openrv_extended() and heap_openrv_extended(). This is also more general, if we have a future need for additional parameters that are of interest to only a few callers. This is infrastructure for a forthcoming patch to allow get_object_address() to take a missing_ok argument as well. Patch by me, review by Noah Misch.
This commit is contained in:
@ -1004,15 +1004,17 @@ relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* try_relation_openrv - open any relation specified by a RangeVar
|
* relation_openrv_extended - open any relation specified by a RangeVar
|
||||||
*
|
*
|
||||||
* Same as relation_openrv, but return NULL instead of failing for
|
* Same as relation_openrv, but with an additional missing_ok argument
|
||||||
* relation-not-found. (Note that some other causes, such as
|
* allowing a NULL return rather than an error if the relation is not
|
||||||
* permissions problems, will still result in an ereport.)
|
* found. (Note that some other causes, such as permissions problems,
|
||||||
|
* will still result in an ereport.)
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
Relation
|
Relation
|
||||||
try_relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
|
relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
|
||||||
|
bool missing_ok)
|
||||||
{
|
{
|
||||||
Oid relOid;
|
Oid relOid;
|
||||||
|
|
||||||
@ -1032,7 +1034,7 @@ try_relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
|
|||||||
AcceptInvalidationMessages();
|
AcceptInvalidationMessages();
|
||||||
|
|
||||||
/* Look up the appropriate relation using namespace search */
|
/* Look up the appropriate relation using namespace search */
|
||||||
relOid = RangeVarGetRelid(relation, true);
|
relOid = RangeVarGetRelid(relation, missing_ok);
|
||||||
|
|
||||||
/* Return NULL on not-found */
|
/* Return NULL on not-found */
|
||||||
if (!OidIsValid(relOid))
|
if (!OidIsValid(relOid))
|
||||||
@ -1125,18 +1127,20 @@ heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* try_heap_openrv - open a heap relation specified
|
* heap_openrv_extended - open a heap relation specified
|
||||||
* by a RangeVar node
|
* by a RangeVar node
|
||||||
*
|
*
|
||||||
* As above, but return NULL instead of failing for relation-not-found.
|
* As above, but optionally return NULL instead of failing for
|
||||||
|
* relation-not-found.
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
Relation
|
Relation
|
||||||
try_heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
|
heap_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
|
||||||
|
bool missing_ok)
|
||||||
{
|
{
|
||||||
Relation r;
|
Relation r;
|
||||||
|
|
||||||
r = try_relation_openrv(relation, lockmode);
|
r = relation_openrv_extended(relation, lockmode, missing_ok);
|
||||||
|
|
||||||
if (r)
|
if (r)
|
||||||
{
|
{
|
||||||
|
@ -826,7 +826,7 @@ parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
|
|||||||
ParseCallbackState pcbstate;
|
ParseCallbackState pcbstate;
|
||||||
|
|
||||||
setup_parser_errposition_callback(&pcbstate, pstate, relation->location);
|
setup_parser_errposition_callback(&pcbstate, pstate, relation->location);
|
||||||
rel = try_heap_openrv(relation, lockmode);
|
rel = heap_openrv_extended(relation, lockmode, true);
|
||||||
if (rel == NULL)
|
if (rel == NULL)
|
||||||
{
|
{
|
||||||
if (relation->schemaname)
|
if (relation->schemaname)
|
||||||
|
@ -50,12 +50,14 @@ typedef enum
|
|||||||
extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
|
extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
|
||||||
extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
|
extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
|
||||||
extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
||||||
extern Relation try_relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
extern Relation relation_openrv_extended(const RangeVar *relation,
|
||||||
|
LOCKMODE lockmode, bool missing_ok);
|
||||||
extern void relation_close(Relation relation, LOCKMODE lockmode);
|
extern void relation_close(Relation relation, LOCKMODE lockmode);
|
||||||
|
|
||||||
extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
|
extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
|
||||||
extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
||||||
extern Relation try_heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
extern Relation heap_openrv_extended(const RangeVar *relation,
|
||||||
|
LOCKMODE lockmode, bool missing_ok);
|
||||||
|
|
||||||
#define heap_close(r,l) relation_close(r,l)
|
#define heap_close(r,l) relation_close(r,l)
|
||||||
|
|
||||||
|
@ -493,8 +493,8 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
|
|||||||
* This is for backwards compatibility. To ensure that the table
|
* This is for backwards compatibility. To ensure that the table
|
||||||
* is trustworthy, we require it to be owned by a superuser.
|
* is trustworthy, we require it to be owned by a superuser.
|
||||||
************************************************************/
|
************************************************************/
|
||||||
pmrel = try_relation_openrv(makeRangeVar(NULL, "pltcl_modules", -1),
|
pmrel = relation_openrv_extended(makeRangeVar(NULL, "pltcl_modules", -1),
|
||||||
AccessShareLock);
|
AccessShareLock, true);
|
||||||
if (pmrel == NULL)
|
if (pmrel == NULL)
|
||||||
return;
|
return;
|
||||||
/* must be table or view, else ignore */
|
/* must be table or view, else ignore */
|
||||||
|
Reference in New Issue
Block a user