3131extern Datum pg_options_to_table (PG_FUNCTION_ARGS );
3232extern Datum postgresql_fdw_validator (PG_FUNCTION_ARGS );
3333
34- static HeapTuple find_user_mapping (Oid userid , Oid serverid );
35-
3634
3735/*
3836 * GetForeignDataWrapper - look up the foreign-data wrapper by OID.
@@ -161,54 +159,6 @@ GetForeignServerByName(const char *srvname, bool missing_ok)
161159 return GetForeignServer (serverid );
162160}
163161
164- /*
165- * GetUserMappingById - look up the user mapping by its OID.
166- */
167- UserMapping *
168- GetUserMappingById (Oid umid )
169- {
170- Datum datum ;
171- HeapTuple tp ;
172- bool isnull ;
173- UserMapping * um ;
174-
175- tp = SearchSysCache1 (USERMAPPINGOID , ObjectIdGetDatum (umid ));
176- if (!HeapTupleIsValid (tp ))
177- elog (ERROR , "cache lookup failed for user mapping %u" , umid );
178-
179- um = (UserMapping * ) palloc (sizeof (UserMapping ));
180- um -> umid = umid ;
181-
182- /* Extract the umuser */
183- datum = SysCacheGetAttr (USERMAPPINGOID ,
184- tp ,
185- Anum_pg_user_mapping_umuser ,
186- & isnull );
187- Assert (!isnull );
188- um -> userid = DatumGetObjectId (datum );
189-
190- /* Extract the umserver */
191- datum = SysCacheGetAttr (USERMAPPINGOID ,
192- tp ,
193- Anum_pg_user_mapping_umserver ,
194- & isnull );
195- Assert (!isnull );
196- um -> serverid = DatumGetObjectId (datum );
197-
198- /* Extract the umoptions */
199- datum = SysCacheGetAttr (USERMAPPINGOID ,
200- tp ,
201- Anum_pg_user_mapping_umoptions ,
202- & isnull );
203- if (isnull )
204- um -> options = NIL ;
205- else
206- um -> options = untransformRelOptions (datum );
207-
208- ReleaseSysCache (tp );
209-
210- return um ;
211- }
212162
213163/*
214164 * GetUserMapping - look up the user mapping.
@@ -224,7 +174,23 @@ GetUserMapping(Oid userid, Oid serverid)
224174 bool isnull ;
225175 UserMapping * um ;
226176
227- tp = find_user_mapping (userid , serverid );
177+ tp = SearchSysCache2 (USERMAPPINGUSERSERVER ,
178+ ObjectIdGetDatum (userid ),
179+ ObjectIdGetDatum (serverid ));
180+
181+ if (!HeapTupleIsValid (tp ))
182+ {
183+ /* Not found for the specific user -- try PUBLIC */
184+ tp = SearchSysCache2 (USERMAPPINGUSERSERVER ,
185+ ObjectIdGetDatum (InvalidOid ),
186+ ObjectIdGetDatum (serverid ));
187+ }
188+
189+ if (!HeapTupleIsValid (tp ))
190+ ereport (ERROR ,
191+ (errcode (ERRCODE_UNDEFINED_OBJECT ),
192+ errmsg ("user mapping not found for \"%s\"" ,
193+ MappingUserName (userid ))));
228194
229195 um = (UserMapping * ) palloc (sizeof (UserMapping ));
230196 um -> umid = HeapTupleGetOid (tp );
@@ -246,60 +212,6 @@ GetUserMapping(Oid userid, Oid serverid)
246212 return um ;
247213}
248214
249- /*
250- * GetUserMappingId - look up the user mapping, and return its OID
251- *
252- * If no mapping is found for the supplied user, we also look for
253- * PUBLIC mappings (userid == InvalidOid).
254- */
255- Oid
256- GetUserMappingId (Oid userid , Oid serverid )
257- {
258- HeapTuple tp ;
259- Oid umid ;
260-
261- tp = find_user_mapping (userid , serverid );
262-
263- /* Extract the Oid */
264- umid = HeapTupleGetOid (tp );
265-
266- ReleaseSysCache (tp );
267-
268- return umid ;
269- }
270-
271- /*
272- * find_user_mapping - Guts of GetUserMapping family.
273- *
274- * If no mapping is found for the supplied user, we also look for
275- * PUBLIC mappings (userid == InvalidOid).
276- */
277- static HeapTuple
278- find_user_mapping (Oid userid , Oid serverid )
279- {
280- HeapTuple tp ;
281-
282- tp = SearchSysCache2 (USERMAPPINGUSERSERVER ,
283- ObjectIdGetDatum (userid ),
284- ObjectIdGetDatum (serverid ));
285-
286- if (HeapTupleIsValid (tp ))
287- return tp ;
288-
289- /* Not found for the specific user -- try PUBLIC */
290- tp = SearchSysCache2 (USERMAPPINGUSERSERVER ,
291- ObjectIdGetDatum (InvalidOid ),
292- ObjectIdGetDatum (serverid ));
293-
294- if (!HeapTupleIsValid (tp ))
295- ereport (ERROR ,
296- (errcode (ERRCODE_UNDEFINED_OBJECT ),
297- errmsg ("user mapping not found for \"%s\"" ,
298- MappingUserName (userid ))));
299-
300- return tp ;
301- }
302-
303215
304216/*
305217 * GetForeignTable - look up the foreign table definition by relation oid.
0 commit comments