pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Robert Haas <rhaas@postgresql.org>
Cc: pgsql-committers@lists.postgresql.org
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: pgsql: Allow insert and update tuple routing and COPY for foreign table
Date: Mon, 22 Apr 2019 21:45:36 +0900
Message-ID: <5CBDB770.2060602@lab.ntt.co.jp> (raw)
In-Reply-To: <ed0b7471dce91169d871347cf003d8094ab96895.camel@cybertec.at>
References: <E1f4aif-0004qo-A6@gemulon.postgresql.org>
	<ed0b7471dce91169d871347cf003d8094ab96895.camel@cybertec.at>

(2019/04/20 20:53), Laurenz Albe wrote:
> On Fri, 2018-04-06 at 23:24 +0000, Robert Haas wrote:
>> Allow insert and update tuple routing and COPY for foreign tables.
>>
>> Also enable this for postgres_fdw.
>>
>> Etsuro Fujita, based on an earlier patch by Amit Langote. The larger
>> patch series of which this is a part has been reviewed by Amit
>> Langote, David Fetter, Maksim Milyutin, Álvaro Herrera, Stephen Frost,
>> and me.  Minor documentation changes to the final version by me.
>>
>> Discussion: http://postgr.es/m/29906a26-da12-8c86-4fb9-d8f88442f2b9@lab.ntt.co.jp
>
> This commit makes life hard for foreign data wrappers that support
> data modifications.
>
> If a FDW implements ExecForeignInsert, this commit automatically assumes
> that it also supports COPY FROM.  It will call ExecForeignInsert without
> calling PlanForeignModify and BeginForeignModify, and a FDW that does not
> expect that will probably fail.

This is not 100% correct; the FDW documentation says:

     <para>
      Tuples inserted into a partitioned table by 
<command>INSERT</command> or
      <command>COPY FROM</command> are routed to partitions.  If an FDW
      supports routable foreign-table partitions, it should also provide the
      following callback functions.  These functions are also called when
      <command>COPY FROM</command> is executed on a foreign table.
     </para>

> maybe there are FDWs that support INSERT but don't want to support COPY
> for some reason.

I agree on that point.

> 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.)

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))));
}

Best regards,
Etsuro Fujita






view thread (22+ messages)  latest in thread

Message-ID: <5CBDB770.2060602@lab.ntt.co.jp>
Permalink:  ../5CBDB770.2060602@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/5CBDB770.2060602@lab.ntt.co.jp

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: fujita.etsuro@lab.ntt.co.jp, laurenz.albe@cybertec.at, rhaas@postgresql.org, pgsql-committers@lists.postgresql.org, pgsql-hackers@lists.postgresql.org
  Subject: Re: pgsql: Allow insert and update tuple routing and COPY for foreign table
  In-Reply-To: <5CBDB770.2060602@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