Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIq7b-0007wp-8B for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Apr 2019 07:45:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIq7Z-0002ow-SU for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Apr 2019 07:45:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIq7Z-0002l9-CT; Tue, 23 Apr 2019 07:45:41 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIq7D-0006xR-I8; Tue, 23 Apr 2019 07:45:40 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x3N7j0C2003436; Tue, 23 Apr 2019 16:45:00 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 7A32EEA8204; Tue, 23 Apr 2019 16:45:00 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 6F45DEA8126; Tue, 23 Apr 2019 16:45:00 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 5EE74400C9C; Tue, 23 Apr 2019 16:45:00 +0900 (JST) Subject: Re: pgsql: Allow insert and update tuple routing and COPY for foreign table References: <5CBDB770.2060602@lab.ntt.co.jp> From: Amit Langote Message-ID: <44ab32f8-bec7-86b6-658d-b4174ebbdd6f@lab.ntt.co.jp> Date: Tue, 23 Apr 2019 16:44:50 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <5CBDB770.2060602@lab.ntt.co.jp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CC-Mail-RelayStamp: 1 To: Etsuro Fujita , Laurenz Albe Cc: Robert Haas , pgsql-committers@lists.postgresql.org, pgsql-hackers@lists.postgresql.org X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019/04/22 21:45, Etsuro Fujita wrote: > (2019/04/20 20:53), Laurenz Albe wrote: >> I propose that PostgreSQL only allows COPY FROM on a foreign table if >> the FDW >> implements BeginForeignInsert.  The attached patch implements that. > > I don't think that is a good idea, because there might be some FDWs that > want to support COPY FROM on foreign tables without providing > BeginForeignInsert.  (As for INSERT into foreign tables, we actually allow > FDWs to support it without providing PlanForeignModify, > BeginForeignModify, or EndForeignModify.) I now understand why Laurenz's patch would in fact be a regression for FDWs that do support COPY FROM and partition tuple routing without providing BeginForeignInsert, although my first reaction was the opposite, which was based on thinking (without confirming) that it's the core that would crash due to initialization step being absent, but that's not the case. The documentation [1] also says: If the BeginForeignInsert pointer is set to NULL, no action is taken for the initialization. [1] https://www.postgresql.org/docs/current/fdw-callbacks.html#FDW-CALLBACKS-UPDATE > It's permissible to throw an error in BeginForeignInsert, so what I was > thinking for FDWs that don't want to support COPY FROM and > INSERT/UPDATE/COPY FROM tuple routing was to provide BeginForeignInsert > implementing something like this: > > static void > fooBeginForeignInsert(ModifyTableState *mtstate, >                       ResultRelInfo *resultRelInfo) > { >     Relation    rel = resultRelInfo->ri_RelationDesc; > >     if (mtstate->ps.plan == NULL) >         ereport(ERROR, >                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), >                  errmsg("cannot copy to foreign table \"%s\"", >                         RelationGetRelationName(rel)))); >     else >         ereport(ERROR, >                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), >                  errmsg("cannot route tuples into foreign table \"%s\"", >                         RelationGetRelationName(rel)))); > } +1 Thanks, Amit