Re: Using FDW AddForeignUpdateTargets for a hidden pseudo-column

From: Aleksey Demakov <a(dot)demakov(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, Bernd Helmle <mailings(at)oopsware(dot)de>
Subject: Re: Using FDW AddForeignUpdateTargets for a hidden pseudo-column
Date: 2016-06-14 13:27:05
Message-ID: 90AA7878-46B5-4DC7-98FE-E51C0B5C9902@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

A very quick and dirty hack I did in src/backend/optimizer/plan/initsplan.c (in 9.5.3):

--- initsplan.c.orig 2016-06-14 19:08:27.000000000 +0600
+++ initsplan.c 2016-06-14 19:10:55.000000000 +0600
@@ -185,9 +185,12 @@
if (IsA(node, Var))
{
Var *var = (Var *) node;
- RelOptInfo *rel = find_base_rel(root, var->varno);
+ RelOptInfo *rel;
int attno = var->varattno;

+ if (var->varno == INDEX_VAR)
+ continue;
+ rel = find_base_rel(root, var->varno);
if (bms_is_subset(where_needed, rel->relids))
continue;
Assert(attno >= rel->min_attr && attno <= rel->max_attr);

And then in my FDW I add the tuple id column like this:

static void
MyAddForeignUpdateTargets(Query *parsetree,
RangeTblEntry *target_rte,
Relation target_relation)
{
Var *var;
TargetEntry *tle;

/* Make a Var representing the desired value */
var = makeVar(INDEX_VAR, /* instead of parsetree->resultRelation,*/
target_relation->rd_att->natts + 1,
INT8OID,
-1,
InvalidOid,
0);

/* Wrap it in a resjunk TLE with the right name ... */
tle = makeTargetEntry((Expr *) var,
list_length(parsetree->targetList) + 1,
pstrdup(MY_FDW_TUPLE_ID),
true);

/* ... and add it to the query's targetlist */
parsetree->targetList = lappend(parsetree->targetList, tle);
}

I was able to run successfully a couple of very simple tests with these. This seems to
indicate that tweaking the core to handle this case properly is doable.

The question is if this approach is conceptually correct and if so what are the other
required places to patch.

Regards,
Aleksey

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-06-14 13:40:36 Re: Using FDW AddForeignUpdateTargets for a hidden pseudo-column
Previous Message Amit Kapila 2016-06-14 12:46:15 Re: ERROR: ORDER/GROUP BY expression not found in targetlist