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

Appearance settings

Commit 8fb569e

Browse filesBrowse files
committed
Introduce new extended routines for FDW and foreign server lookups
The cache lookup routines for foreign-data wrappers and foreign servers are extended with an extra argument to handle a set of flags. The only value which can be used now is to indicate if a missing object should result in an error or not, and are designed to be extensible on need. Those new routines are added into the existing set of user-visible FDW APIs and documented in consequence. They will be used for future patches to improve the SQL interface for object addresses. Author: Michael Paquier Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/CAB7nPqSZxrSmdHK-rny7z8mi=EAFXJ5J-0RbzDw6aus=wB5azQ@mail.gmail.com
1 parent 09568ec commit 8fb569e
Copy full SHA for 8fb569e

File tree

3 files changed

+78
-2
lines changed
Filter options

3 files changed

+78
-2
lines changed

‎doc/src/sgml/fdwhandler.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/fdwhandler.sgml
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,23 @@ ReparameterizeForeignPathByChild(PlannerInfo *root, List *fdw_private,
14081408
<para>
14091409
<programlisting>
14101410
ForeignDataWrapper *
1411+
GetForeignDataWrapperExtended(Oid fdwid, bits16 flags);
1412+
</programlisting>
1413+
1414+
This function returns a <structname>ForeignDataWrapper</structname>
1415+
object for the foreign-data wrapper with the given OID. A
1416+
<structname>ForeignDataWrapper</structname> object contains properties
1417+
of the FDW (see <filename>foreign/foreign.h</filename> for details).
1418+
<structfield>flags</structfield> is a bitwise-or'd bit mask indicating
1419+
an extra set of options. It can take the value
1420+
<literal>FDW_MISSING_OK</literal>, in which case a <literal>NULL</literal>
1421+
result is returned to the caller instead of an error for an undefined
1422+
object.
1423+
</para>
1424+
1425+
<para>
1426+
<programlisting>
1427+
ForeignDataWrapper *
14111428
GetForeignDataWrapper(Oid fdwid);
14121429
</programlisting>
14131430

@@ -1420,6 +1437,23 @@ GetForeignDataWrapper(Oid fdwid);
14201437
<para>
14211438
<programlisting>
14221439
ForeignServer *
1440+
GetForeignServerExtended(Oid serverid, bits16 flags);
1441+
</programlisting>
1442+
1443+
This function returns a <structname>ForeignServer</structname> object
1444+
for the foreign server with the given OID. A
1445+
<structname>ForeignServer</structname> object contains properties
1446+
of the server (see <filename>foreign/foreign.h</filename> for details).
1447+
<structfield>flags</structfield> is a bitwise-or'd bit mask indicating
1448+
an extra set of options. It can take the value
1449+
<literal>FSV_MISSING_OK</literal>, in which case a <literal>NULL</literal>
1450+
result is returned to the caller instead of an error for an undefined
1451+
object.
1452+
</para>
1453+
1454+
<para>
1455+
<programlisting>
1456+
ForeignServer *
14231457
GetForeignServer(Oid serverid);
14241458
</programlisting>
14251459

‎src/backend/foreign/foreign.c

Copy file name to clipboardExpand all lines: src/backend/foreign/foreign.c
+34-2Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
*/
3434
ForeignDataWrapper *
3535
GetForeignDataWrapper(Oid fdwid)
36+
{
37+
return GetForeignDataWrapperExtended(fdwid, 0);
38+
}
39+
40+
41+
/*
42+
* GetForeignDataWrapperExtended - look up the foreign-data wrapper
43+
* by OID. If flags uses FDW_MISSING_OK, return NULL if the object cannot
44+
* be found instead of raising an error.
45+
*/
46+
ForeignDataWrapper *
47+
GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
3648
{
3749
Form_pg_foreign_data_wrapper fdwform;
3850
ForeignDataWrapper *fdw;
@@ -43,7 +55,11 @@ GetForeignDataWrapper(Oid fdwid)
4355
tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwid));
4456

4557
if (!HeapTupleIsValid(tp))
46-
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
58+
{
59+
if ((flags & FDW_MISSING_OK) == 0)
60+
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
61+
return NULL;
62+
}
4763

4864
fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
4965

@@ -91,6 +107,18 @@ GetForeignDataWrapperByName(const char *fdwname, bool missing_ok)
91107
*/
92108
ForeignServer *
93109
GetForeignServer(Oid serverid)
110+
{
111+
return GetForeignServerExtended(serverid, 0);
112+
}
113+
114+
115+
/*
116+
* GetForeignServerExtended - look up the foreign server definition. If
117+
* flags uses FSV_MISSING_OK, return NULL if the object cannot be found
118+
* instead of raising an error.
119+
*/
120+
ForeignServer *
121+
GetForeignServerExtended(Oid serverid, bits16 flags)
94122
{
95123
Form_pg_foreign_server serverform;
96124
ForeignServer *server;
@@ -101,7 +129,11 @@ GetForeignServer(Oid serverid)
101129
tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(serverid));
102130

103131
if (!HeapTupleIsValid(tp))
104-
elog(ERROR, "cache lookup failed for foreign server %u", serverid);
132+
{
133+
if ((flags & FSV_MISSING_OK) == 0)
134+
elog(ERROR, "cache lookup failed for foreign server %u", serverid);
135+
return NULL;
136+
}
105137

106138
serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
107139

‎src/include/foreign/foreign.h

Copy file name to clipboardExpand all lines: src/include/foreign/foreign.h
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,21 @@ typedef struct ForeignTable
6868
List *options; /* ftoptions as DefElem list */
6969
} ForeignTable;
7070

71+
/* Flags for GetForeignServerExtended */
72+
#define FSV_MISSING_OK 0x01
73+
74+
/* Flags for GetForeignDataWrapperExtended */
75+
#define FDW_MISSING_OK 0x01
76+
7177

7278
extern ForeignServer *GetForeignServer(Oid serverid);
79+
extern ForeignServer *GetForeignServerExtended(Oid serverid,
80+
bits16 flags);
7381
extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok);
7482
extern UserMapping *GetUserMapping(Oid userid, Oid serverid);
7583
extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid);
84+
extern ForeignDataWrapper *GetForeignDataWrapperExtended(Oid fdwid,
85+
bits16 flags);
7686
extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name,
7787
bool missing_ok);
7888
extern ForeignTable *GetForeignTable(Oid relid);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.