Re: [HACKERS] Add support for tuple routing to foreign partitions

From: Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Maksim Milyutin <milyutinma(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Subject: Re: [HACKERS] Add support for tuple routing to foreign partitions
Date: 2018-02-21 11:54:33
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

(2018/02/02 19:33), Etsuro Fujita wrote:
> (2018/01/25 23:33), Stephen Frost wrote:
>> I'm afraid a good bit of this patch is now failing to apply. I don't
>> have much else to say except to echo the performance concern that Amit
>> Langote raised about expanding the inheritence tree twice.
> To address that concern, I'm thinking to redesign the patch so that it
> wouldn't expand the tree at planning time anymore. I don't have any
> clear solution for that yet, but what I have in mind now is to add new
> FDW APIs to the executor, instead, so that the FDW could 1) create stuff
> such as a query for remote INSERT as PlanForeignModify and 2)
> initialize/end the remote INSERT operation as BeginForeignModify and
> EndForeignModify, somewhere in the executor.

New FDW APIs I would like to propose for that are:

BeginForeignRouting(ModifyTableState *mtstate,
ResultRelInfo *resultRelInfo,
int partition_index);

Prepare for a tuple-routing operation on a foreign table. This is
called from ExecSetupPartitionTupleRouting and ExecInitPartitionInfo.

TupleTableSlot *
ExecForeignRouting(EState *estate,
ResultRelInfo *resultRelInfo,
TupleTableSlot *slot);

Route one tuple to the foreign table. This is called from ExecInsert.

EndForeignRouting(EState *estate,
ResultRelInfo *resultRelInfo);

End the operation and release resources. This is called from

Attached are WIP patches for that:

Patch postgres-fdw-refactoring-WIP.patch: refactoring patch for
postgres_fdw.c to reduce duplicate code.

Patch foreign-routing-fdwapi-WIP.patch: main patch to add new FDW APIs,
which is created on top of patch postgres-fdw-refactoring-WIP.patch and
the lazy-initialization-of-partition-info patch [1].

By this change we don't need to expand the inheritance tree at planning
time, so no need to worry about the performance concern. Maybe I'm
missing something, though. Early feedback would be greatly appreciated.

Best regards,
Etsuro Fujita


Attachment Content-Type Size
foreign-routing-fdwapi-WIP.patch text/x-diff 23.5 KB
postgres-fdw-refactoring-WIP.patch text/x-diff 18.2 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2018-02-21 11:58:31 Re: [HACKERS] Runtime Partition Pruning
Previous Message Laurenz Albe 2018-02-21 11:18:15 Re: NEXT VALUE FOR sequence