Re: Push down more UPDATEs/DELETEs in postgres_fdw

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Push down more UPDATEs/DELETEs in postgres_fdw
Date: 2017-02-21 10:31:54
Views: Raw Message | Whole Thread | Download mbox
Lists: pgsql-hackers

On Mon, Feb 20, 2017 at 1:41 PM, Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>

> On 2017/02/13 18:24, Rushabh Lathia wrote:
>> I started reviewing the patch again. Patch applied cleanly on latest
>> source
>> as well as regression pass through with the patch. I also performed
>> few manual testing and haven't found any regression. Patch look
>> much cleaner the earlier version, and don't have any major concern as
>> such.
> Thanks for the review!
> Here are few comments:
>> 1)
>> @@ -211,6 +211,12 @@ typedef struct PgFdwDirectModifyState
>> PGresult *result; /* result for query */
>> int num_tuples; /* # of result tuples */
>> int next_tuple; /* index of next one to return */
>> + Relation resultRel; /* relcache entry for the target table
>> */
> Why we need resultRel? Can't we directly use dmstate->rel ?
> The reason why we need that is because in get_returning_data, we pass
> dmstate->rel to make_tuple_from_result_row, which requires that
> dmstate->rel be NULL when the scan tuple is described by fdw_scan_tlist.
> So in that case we set dmstate->rel to NULL and have dmstate->resultRel
> that is the relcache entry for the target relation in
> postgresBeginDirectModify.
Thanks for the explanation. We might do something here by using
fdw_scan_tlist or changing the assumption of make_tuple_from_result_row(),
and that way we can avoid two similar variable pointer in the

I am okay with currently also, but it adding a note somewhere about this
would be great. Also let keep this point open for the committer, if
committer feel this is good then lets go ahead with this.

Here are few other cosmetic changes:


+ *
+ * 'target_rel' is either zero or the rangetable index of a target
+ * In the latter case this construncts FROM clause of UPDATE or USING
+ * of DELETE by simply ignoring the target relation while deparsing the

Spell correction: - construncts


+ /*
+ * If either input is the target relation, get all the joinclauses.
+ * Otherwise extract conditions mentioning the target relation from
+ * the joinclauses.
+ */

space between joinclauses needed.


+ /*
+ * If UPDATE/DELETE on a join, create a RETURINING list used in the
+ * remote query.
+ */
+ if (fscan->scan.scanrelid == 0)
+ returningList = make_explicit_returning_list(resultRelation,
+ rel,
+ returningList);

Spell correction: RETURINING

I did above changes in the attached patch. Please have a look once and
then I feel like this patch is ready for committer.

Rushabh Lathia

Attachment Content-Type Size
postgres-fdw-more-update-pushdown-v3_cosmetic_changes.patch application/x-download 54.7 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Bernd Helmle 2017-02-21 10:47:33 Re: LWLock optimization for multicore Power machines
Previous Message Michael Banck 2017-02-21 10:17:55 [patch] reorder tablespaces in basebackup tar stream for backup_label