pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: 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: Tue, 23 Apr 2019 16:44:50 +0900
Message-ID: <44ab32f8-bec7-86b6-658d-b4174ebbdd6f@lab.ntt.co.jp> (raw)
In-Reply-To: <5CBDB770.2060602@lab.ntt.co.jp>
References: <E1f4aif-0004qo-A6@gemulon.postgresql.org>
	<ed0b7471dce91169d871347cf003d8094ab96895.camel@cybertec.at>
	<5CBDB770.2060602@lab.ntt.co.jp>

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






view thread (22+ messages)  latest in thread

Message-ID: <44ab32f8-bec7-86b6-658d-b4174ebbdd6f@lab.ntt.co.jp>
Permalink:  ../44ab32f8-bec7-86b6-658d-b4174ebbdd6f@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/44ab32f8-bec7-86b6-658d-b4174ebbdd6f@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: Langote_Amit_f8@lab.ntt.co.jp, 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: <44ab32f8-bec7-86b6-658d-b4174ebbdd6f@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