Re: pgsql: Allow insert and update tuple routing and COPY for foreign table

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)lists(dot)postgresql(dot)org, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Allow insert and update tuple routing and COPY for foreign table
Date: 2019-04-24 13:04:47
Message-ID: bf36a0288e8f31b4f2f40952e225bf892dc1ffc5.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On Wed, 2019-04-24 at 20:54 +0900, Etsuro Fujita wrote:
> How about adding to the documentation for BeginForeignInsert a mention
> that if an FDW doesn't support COPY FROM and/or routable foreign tables,
> it must throw an error in BeginForeignInsert accordingly.

Sure, some more documentation would be good.

The documentation of ExecForeignInsert should mention something like:

ExecForeignInsert is called for INSERT statements as well
as for COPY FROM and tuples that are inserted into a foreign table
because it is a partition of a partitioned table.

In the case of a normal INSERT, BeginForeignModify will be called
before ExecForeignInsert to perform any necessary setup.
In the other cases, this setup has to happen in BeginForeignInsert.

Before PostgreSQL v11, a foreign data wrapper could be certain that
BeginForeignModify is always called before ExecForeignInsert.
This is no longer true.

> > On the other hand, if a FDW wants to support COPY in v11 and has no
> > need for BeginForeignInsert to support that, it is a simple exercise
> > for it to provide an empty BeginForeignInsert just to signal that it
> > wants to support COPY.
>
> That seems to me inconsistent with the concept of the existing APIs for
> updating foreign tables, because for an FDW that wants to support
> INSERT/UPDATE/DELETE and has no need for
> PlanForeignModify/BeginForeignModify, those APIs don't require the FDW
> to provide empty PlanForeignModify/BeginForeignModify to tell the core
> that it wants to support INSERT/UPDATE/DELETE.

That is true, but so far there hasn't been a change to the FDW API that
caused a callback to be invoked in a different fashion than it used to be.

Perhaps it would have been better to create a new callback like
ExecForeignCopy with the same signature as ExecForeignInsert so that
you can use the same callback function for both if you want.
That would also have avoided the breakage.
But, of course it is too late for that now.

Note that postgres_fdw would have been broken by that API change as well
if it hasn't been patched.

At the very least, this should have been mentioned in the list of
incompatible changes for v11.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Simon Riggs 2019-04-24 13:25:04 Re: pgsql: Allow insert and update tuple routing and COPY for foreign table
Previous Message Etsuro Fujita 2019-04-24 11:54:26 Re: pgsql: Allow insert and update tuple routing and COPY for foreign table

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2019-04-24 13:25:04 Re: pgsql: Allow insert and update tuple routing and COPY for foreign table
Previous Message Alvaro Herrera 2019-04-24 12:54:13 Re: [Patch] Check file type before calling AllocateFile() for files out of pg data directory to avoid potential issues (e.g. hang).