Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9abbed0

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 seemquite appropriate, rename the functions to relation_openrv_extended()and heap_openrv_extended(). This is also more general, if we have afuture need for additional parameters that are of interest to only afew callers.This is infrastructure for a forthcoming patch to allowget_object_address() to take a missing_ok argument as well.Patch by me, review by Noah Misch.
1 parente16954f commit9abbed0

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(constRangeVar*relation,LOCKMODElockmode)
1016+
relation_openrv_extended(constRangeVar*relation,LOCKMODElockmode,
1017+
boolmissing_ok)
10161018
{
10171019
OidrelOid;
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(constRangeVar*relation,LOCKMODElockmode)
1138+
heap_openrv_extended(constRangeVar*relation,LOCKMODElockmode,
1139+
boolmissing_ok)
11361140
{
11371141
Relationr;
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
ParseCallbackStatepcbstate;
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
externRelationrelation_open(OidrelationId,LOCKMODElockmode);
5151
externRelationtry_relation_open(OidrelationId,LOCKMODElockmode);
5252
externRelationrelation_openrv(constRangeVar*relation,LOCKMODElockmode);
53-
externRelationtry_relation_openrv(constRangeVar*relation,LOCKMODElockmode);
53+
externRelationrelation_openrv_extended(constRangeVar*relation,
54+
LOCKMODElockmode,boolmissing_ok);
5455
externvoidrelation_close(Relationrelation,LOCKMODElockmode);
5556

5657
externRelationheap_open(OidrelationId,LOCKMODElockmode);
5758
externRelationheap_openrv(constRangeVar*relation,LOCKMODElockmode);
58-
externRelationtry_heap_openrv(constRangeVar*relation,LOCKMODElockmode);
59+
externRelationheap_openrv_extended(constRangeVar*relation,
60+
LOCKMODElockmode,boolmissing_ok);
5961

6062
#defineheap_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)

[8]ページ先頭

©2009-2025 Movatter.jp