diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-03-28 21:50:28 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-03-28 21:50:28 -0400 |
commit | 5d4171d1c70edfe3e9be1de9e66603af28e3afe1 (patch) | |
tree | e74ee89c0af8ea0662fc001ba9ce965d6a2890c8 /src/backend/foreign/foreign.c | |
parent | 868628e4fd44d75987d6c099ac63613cc5417629 (diff) | |
download | postgresql-5d4171d1c70edfe3e9be1de9e66603af28e3afe1.tar.gz postgresql-5d4171d1c70edfe3e9be1de9e66603af28e3afe1.zip |
Don't require a user mapping for FDWs to work.
Commit fbe5a3fb73102c2cfec11aaaa4a67943f4474383 accidentally changed
this behavior; put things back the way they were, and add some
regression tests.
Report by Andres Freund; patch by Ashutosh Bapat, with a bit of
kibitzing by me.
Diffstat (limited to 'src/backend/foreign/foreign.c')
-rw-r--r-- | src/backend/foreign/foreign.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/backend/foreign/foreign.c b/src/backend/foreign/foreign.c index 239849bb0b0..f1feb85c551 100644 --- a/src/backend/foreign/foreign.c +++ b/src/backend/foreign/foreign.c @@ -31,7 +31,7 @@ extern Datum pg_options_to_table(PG_FUNCTION_ARGS); extern Datum postgresql_fdw_validator(PG_FUNCTION_ARGS); -static HeapTuple find_user_mapping(Oid userid, Oid serverid); +static HeapTuple find_user_mapping(Oid userid, Oid serverid, bool missing_ok); /* * GetForeignDataWrapper - look up the foreign-data wrapper by OID. @@ -223,7 +223,7 @@ GetUserMapping(Oid userid, Oid serverid) bool isnull; UserMapping *um; - tp = find_user_mapping(userid, serverid); + tp = find_user_mapping(userid, serverid, false); um = (UserMapping *) palloc(sizeof(UserMapping)); um->umid = HeapTupleGetOid(tp); @@ -250,14 +250,23 @@ GetUserMapping(Oid userid, Oid serverid) * * If no mapping is found for the supplied user, we also look for * PUBLIC mappings (userid == InvalidOid). + * + * If missing_ok is true, the function returns InvalidOid when it does not find + * required user mapping. Otherwise, find_user_mapping() throws error if it + * does not find required user mapping. */ Oid -GetUserMappingId(Oid userid, Oid serverid) +GetUserMappingId(Oid userid, Oid serverid, bool missing_ok) { HeapTuple tp; Oid umid; - tp = find_user_mapping(userid, serverid); + tp = find_user_mapping(userid, serverid, missing_ok); + + Assert(missing_ok || tp); + + if (!tp && missing_ok) + return InvalidOid; /* Extract the Oid */ umid = HeapTupleGetOid(tp); @@ -273,9 +282,13 @@ GetUserMappingId(Oid userid, Oid serverid) * * If no mapping is found for the supplied user, we also look for * PUBLIC mappings (userid == InvalidOid). + * + * If missing_ok is true, the function returns NULL, if it does not find + * the required user mapping. Otherwise, it throws error if it does not + * find the required user mapping. */ static HeapTuple -find_user_mapping(Oid userid, Oid serverid) +find_user_mapping(Oid userid, Oid serverid, bool missing_ok) { HeapTuple tp; @@ -292,10 +305,15 @@ find_user_mapping(Oid userid, Oid serverid) ObjectIdGetDatum(serverid)); if (!HeapTupleIsValid(tp)) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("user mapping not found for \"%s\"", - MappingUserName(userid)))); + { + if (missing_ok) + return NULL; + else + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("user mapping not found for \"%s\"", + MappingUserName(userid)))); + } return tp; } |