From: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Oddity in handling of cached plans for FDW queries
Date: Fri, 22 Jul 2016 12:41:06 +0900
Message-ID: <d674a3f1-6b63-519c-ef3f-f3188ed6a178@lab.ntt.co.jp> (raw)
In-Reply-To: <9b21f8e3-13c7-5b9a-7f35-edddef21c181@lab.ntt.co.jp>
References: <d49c1e5b-f059-20f4-c132-e9752ee0113e@lab.ntt.co.jp>
<CAFjFpRf94+DJOr8pOLUQYgmmOxjonGPhrU4uvo_00BKCZ-fGug@mail.gmail.com>
<bbd3d81d-1596-b7a6-833d-ddfc6754c82f@lab.ntt.co.jp>
<CAFjFpRd9rx1kc-Dvm6ogeNKF8C6XxFA-QAH89T08pFHTKCOaFw@mail.gmail.com>
<6085.1468513930@sss.pgh.pa.us>
<10736.1468522173@sss.pgh.pa.us>
<122d7752-7fe4-f561-4348-34b398d46ec1@lab.ntt.co.jp>
<2270.1468550932@sss.pgh.pa.us>
<28ab7288-84f5-aab4-3ef7-cf1ca6e9a291@lab.ntt.co.jp>
<23274.1468589754@sss.pgh.pa.us>
<8993.1468617909@sss.pgh.pa.us>
<9b21f8e3-13c7-5b9a-7f35-edddef21c181@lab.ntt.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 2016/07/21 16:30, Etsuro Fujita wrote:
> One thing I'd like to discuss is GetUserMappingById/GetUserMappingId.
> Though those functions aren't used in any places, I didn't take them
> out, because I thought somebody else would need them someday. But
> considering that user mapping OIDs now aren't available in RelOptInfos,
> at least the former might be rather useless. Should we keep them in core?
I thought a bit more about this. ISTM that there isn't much value in
the latter either, because we can use GetUserMapping and get that OID
from the result, instead of using the latter, so I'd vote for removing
those functions. Attached is a patch for that.
Best regards,
Etsuro Fujita
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:remove-usermapping-helper-funcs.patch (binary/octet-stream, 5.5K) download
*** a/doc/src/sgml/fdwhandler.sgml
--- b/doc/src/sgml/fdwhandler.sgml
***************
*** 1323,1342 **** GetForeignTable(Oid relid);
<para>
<programlisting>
- UserMapping *- GetUserMappingById(Oid umid);- </programlisting>- - This function returns the <structname>UserMapping</structname> object for- the given user mapping OID. The OID of a user mapping for a foreign scan- is available in the <structname>RelOptInfo</structname>.- If there is no mapping for the OID, this function will throw an error.- A <structname>UserMapping</structname> object contains properties of the- user mapping (see <filename>foreign/foreign.h</filename> for details).- </para>- - <para>- <programlisting>
List *
GetForeignColumnOptions(Oid relid, AttrNumber attnum);
</programlisting>
--- 1323,1328 ----
*** a/src/backend/foreign/foreign.c
--- b/src/backend/foreign/foreign.c
***************
*** 31,38 ****
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);-
/*
* GetForeignDataWrapper - look up the foreign-data wrapper by OID.
--- 31,36 ----
***************
*** 161,214 **** GetForeignServerByName(const char *srvname, bool missing_ok)
return GetForeignServer(serverid);
}
- /*- * GetUserMappingById - look up the user mapping by its OID.- */- UserMapping *- GetUserMappingById(Oid umid)- {- Datum datum;- HeapTuple tp;- bool isnull;- UserMapping *um;- - tp = SearchSysCache1(USERMAPPINGOID, ObjectIdGetDatum(umid));- if (!HeapTupleIsValid(tp))- elog(ERROR, "cache lookup failed for user mapping %u", umid);- - um = (UserMapping *) palloc(sizeof(UserMapping));- um->umid = umid;- - /* Extract the umuser */- datum = SysCacheGetAttr(USERMAPPINGOID,- tp,- Anum_pg_user_mapping_umuser,- &isnull);- Assert(!isnull);- um->userid = DatumGetObjectId(datum);- - /* Extract the umserver */- datum = SysCacheGetAttr(USERMAPPINGOID,- tp,- Anum_pg_user_mapping_umserver,- &isnull);- Assert(!isnull);- um->serverid = DatumGetObjectId(datum);- - /* Extract the umoptions */- datum = SysCacheGetAttr(USERMAPPINGOID,- tp,- Anum_pg_user_mapping_umoptions,- &isnull);- if (isnull)- um->options = NIL;- else- um->options = untransformRelOptions(datum);- - ReleaseSysCache(tp);- - return um;- }
/*
* GetUserMapping - look up the user mapping.
--- 159,164 ----
***************
*** 224,230 **** GetUserMapping(Oid userid, Oid serverid)
bool isnull;
UserMapping *um;
! tp = find_user_mapping(userid, serverid);
um = (UserMapping *) palloc(sizeof(UserMapping));
um->umid = HeapTupleGetOid(tp);
--- 174,196 ----
bool isnull;
UserMapping *um;
! tp = SearchSysCache2(USERMAPPINGUSERSERVER,
! ObjectIdGetDatum(userid),
! ObjectIdGetDatum(serverid));
!
! if (!HeapTupleIsValid(tp))
! {
! /* Not found for the specific user -- try PUBLIC */
! tp = SearchSysCache2(USERMAPPINGUSERSERVER,
! ObjectIdGetDatum(InvalidOid),
! ObjectIdGetDatum(serverid));
! }
!
! if (!HeapTupleIsValid(tp))
! ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_OBJECT),
! errmsg("user mapping not found for \"%s\"",
! MappingUserName(userid))));
um = (UserMapping *) palloc(sizeof(UserMapping));
um->umid = HeapTupleGetOid(tp);
***************
*** 246,305 **** GetUserMapping(Oid userid, Oid serverid)
return um;
}
- /*- * GetUserMappingId - look up the user mapping, and return its OID- *- * If no mapping is found for the supplied user, we also look for- * PUBLIC mappings (userid == InvalidOid).- */- Oid- GetUserMappingId(Oid userid, Oid serverid)- {- HeapTuple tp;- Oid umid;- - tp = find_user_mapping(userid, serverid);- - /* Extract the Oid */- umid = HeapTupleGetOid(tp);- - ReleaseSysCache(tp);- - return umid;- }- - /*- * find_user_mapping - Guts of GetUserMapping family.- *- * If no mapping is found for the supplied user, we also look for- * PUBLIC mappings (userid == InvalidOid).- */- static HeapTuple- find_user_mapping(Oid userid, Oid serverid)- {- HeapTuple tp;- - tp = SearchSysCache2(USERMAPPINGUSERSERVER,- ObjectIdGetDatum(userid),- ObjectIdGetDatum(serverid));- - if (HeapTupleIsValid(tp))- return tp;- - /* Not found for the specific user -- try PUBLIC */- tp = SearchSysCache2(USERMAPPINGUSERSERVER,- ObjectIdGetDatum(InvalidOid),- ObjectIdGetDatum(serverid));- - if (!HeapTupleIsValid(tp))- ereport(ERROR,- (errcode(ERRCODE_UNDEFINED_OBJECT),- errmsg("user mapping not found for \"%s\"",- MappingUserName(userid))));- - return tp;- }-
/*
* GetForeignTable - look up the foreign table definition by relation oid.
--- 212,217 ----
*** a/src/include/foreign/foreign.h
--- b/src/include/foreign/foreign.h
***************
*** 72,79 **** typedef struct ForeignTable
extern ForeignServer *GetForeignServer(Oid serverid);
extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok);
extern UserMapping *GetUserMapping(Oid userid, Oid serverid);
- extern Oid GetUserMappingId(Oid userid, Oid serverid);- extern UserMapping *GetUserMappingById(Oid umid);
extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid);
extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name,
bool missing_ok);
--- 72,77 ----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: fujita.etsuro@lab.ntt.co.jp, tgl@sss.pgh.pa.us, ashutosh.bapat@enterprisedb.com
Subject: Re: Oddity in handling of cached plans for FDW queries
In-Reply-To: <d674a3f1-6b63-519c-ef3f-f3188ed6a178@lab.ntt.co.jp>
References: <d49c1e5b-f059-20f4-c132-e9752ee0113e@lab.ntt.co.jp> <CAFjFpRf94+DJOr8pOLUQYgmmOxjonGPhrU4uvo_00BKCZ-fGug@mail.gmail.com> <bbd3d81d-1596-b7a6-833d-ddfc6754c82f@lab.ntt.co.jp> <CAFjFpRd9rx1kc-Dvm6ogeNKF8C6XxFA-QAH89T08pFHTKCOaFw@mail.gmail.com> <6085.1468513930@sss.pgh.pa.us> <10736.1468522173@sss.pgh.pa.us> <122d7752-7fe4-f561-4348-34b398d46ec1@lab.ntt.co.jp> <2270.1468550932@sss.pgh.pa.us> <28ab7288-84f5-aab4-3ef7-cf1ca6e9a291@lab.ntt.co.jp> <23274.1468589754@sss.pgh.pa.us> <8993.1468617909@sss.pgh.pa.us> <9b21f8e3-13c7-5b9a-7f35-edddef21c181@lab.ntt.co.jp> <d674a3f1-6b63-519c-ef3f-f3188ed6a178@lab.ntt.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox