Re: Passing fdw_private data from PlanForeignScan to PlanForeignModify

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Passing fdw_private data from PlanForeignScan to PlanForeignModify
Date: 2013-06-13 22:12:05
Message-ID: 19844.1371161525@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bernd Helmle <mailings(at)oopsware(dot)de> writes:
> What i tried before was to access (in PlanForeignModify) the RelOptInfo
> structure through PlannerInfo->simple_rel_array, assuming the the
> resultRelation index points to the right array member. However, that didn't
> work, the fdw_private List is not the one filled by GetForeignPlan...is
> there another way to get back the RelOptInfo worked on earlier?

It should work ... *if* there was in fact a RelOptInfo worked on
earlier. There sometimes isn't. You might need to do something like
what make_modifytable() has to do to call you in the first place:

/*
* If possible, we want to get the FdwRoutine from our RelOptInfo for
* the table. But sometimes we don't have a RelOptInfo and must get
* it the hard way. (In INSERT, the target relation is not scanned,
* so it's not a baserel; and there are also corner cases for
* updatable views where the target rel isn't a baserel.)
*/
if (rti < root->simple_rel_array_size &&
root->simple_rel_array[rti] != NULL)
{
RelOptInfo *resultRel = root->simple_rel_array[rti];

fdwroutine = resultRel->fdwroutine;
}
else
{
RangeTblEntry *rte = planner_rt_fetch(rti, root);

Assert(rte->rtekind == RTE_RELATION);
if (rte->relkind == RELKIND_FOREIGN_TABLE)
fdwroutine = GetFdwRoutineByRelId(rte->relid);
else
fdwroutine = NULL;
}

if (fdwroutine != NULL &&
fdwroutine->PlanForeignModify != NULL)
fdw_private = fdwroutine->PlanForeignModify(root, node, rti, i);

[ jargon alert: "baserel" here basically means "a table the query has
to scan". ]

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2013-06-13 22:18:35 Re: single-user vs standalone in docs and messages
Previous Message Jeff Janes 2013-06-13 22:10:28 single-user vs standalone in docs and messages