Skip to content

Commit 9abbed0

Browse files
committed
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.
1 parent e16954f commit 9abbed0

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

src/backend/access/heap/heapam.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,15 +1004,17 @@ relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
10041004
}
10051005

10061006
/* ----------------
1007-
* try_relation_openrv - open any relation specified by a RangeVar
1007+
* relation_openrv_extended - open any relation specified by a RangeVar
10081008
*
1009-
* Same as relation_openrv, but return NULL instead of failing for
1010-
* relation-not-found. (Note that some other causes, such as
1011-
* permissions problems, will still result in an ereport.)
1009+
* Same as relation_openrv, but with an additional missing_ok argument
1010+
* allowing a NULL return rather than an error if the relation is not
1011+
* found. (Note that some other causes, such as permissions problems,
1012+
* will still result in an ereport.)
10121013
* ----------------
10131014
*/
10141015
Relation
1015-
try_relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
1016+
relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
1017+
bool missing_ok)
10161018
{
10171019
Oid relOid;
10181020

@@ -1032,7 +1034,7 @@ try_relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
10321034
AcceptInvalidationMessages();
10331035

10341036
/* Look up the appropriate relation using namespace search */
1035-
relOid = RangeVarGetRelid(relation, true);
1037+
relOid = RangeVarGetRelid(relation, missing_ok);
10361038

10371039
/* Return NULL on not-found */
10381040
if (!OidIsValid(relOid))
@@ -1125,18 +1127,20 @@ heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
11251127
}
11261128

11271129
/* ----------------
1128-
* try_heap_openrv - open a heap relation specified
1130+
* heap_openrv_extended - open a heap relation specified
11291131
* by a RangeVar node
11301132
*
1131-
* As above, but return NULL instead of failing for relation-not-found.
1133+
* As above, but optionally return NULL instead of failing for
1134+
* relation-not-found.
11321135
* ----------------
11331136
*/
11341137
Relation
1135-
try_heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
1138+
heap_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
1139+
bool missing_ok)
11361140
{
11371141
Relation r;
11381142

1139-
r = try_relation_openrv(relation, lockmode);
1143+
r = relation_openrv_extended(relation, lockmode, missing_ok);
11401144

11411145
if (r)
11421146
{

src/backend/parser/parse_relation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
826826
ParseCallbackState pcbstate;
827827

828828
setup_parser_errposition_callback(&pcbstate, pstate, relation->location);
829-
rel = try_heap_openrv(relation, lockmode);
829+
rel = heap_openrv_extended(relation, lockmode, true);
830830
if (rel == NULL)
831831
{
832832
if (relation->schemaname)

src/include/access/heapam.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ typedef enum
5050
extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
5151
extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
5252
extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
53-
extern Relation try_relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
53+
extern Relation relation_openrv_extended(const RangeVar *relation,
54+
LOCKMODE lockmode, bool missing_ok);
5455
extern void relation_close(Relation relation, LOCKMODE lockmode);
5556

5657
extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
5758
extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
58-
extern Relation try_heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
59+
extern Relation heap_openrv_extended(const RangeVar *relation,
60+
LOCKMODE lockmode, bool missing_ok);
5961

6062
#define heap_close(r,l) relation_close(r,l)
6163

src/pl/tcl/pltcl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
493493
* This is for backwards compatibility. To ensure that the table
494494
* is trustworthy, we require it to be owned by a superuser.
495495
************************************************************/
496-
pmrel = try_relation_openrv(makeRangeVar(NULL, "pltcl_modules", -1),
497-
AccessShareLock);
496+
pmrel = relation_openrv_extended(makeRangeVar(NULL, "pltcl_modules", -1),
497+
AccessShareLock, true);
498498
if (pmrel == NULL)
499499
return;
500500
/* must be table or view, else ignore */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy