*/
        add_path(baserel, (Path *)
                         create_foreignscan_path(root, baserel,
+                                                                        NULL,          /* default pathtarget */
                                                                         baserel->rows,
                                                                         startup_cost,
                                                                         total_cost,
 
         * to estimate cost and size of this path.
         */
        path = create_foreignscan_path(root, baserel,
+                                                                  NULL,                /* default pathtarget */
                                                                   fpinfo->rows,
                                                                   fpinfo->startup_cost,
                                                                   fpinfo->total_cost,
 
                /* Make the path */
                path = create_foreignscan_path(root, baserel,
+                                                                          NULL,        /* default pathtarget */
                                                                           rows,
                                                                           startup_cost,
                                                                           total_cost,
 
                add_path(rel, (Path *)
                                 create_foreignscan_path(root, rel,
+                                                                                NULL,
                                                                                 rows,
                                                                                 startup_cost,
                                                                                 total_cost,
         */
        joinpath = create_foreignscan_path(root,
                                                                           joinrel,
+                                                                          NULL,        /* default pathtarget */
                                                                           rows,
                                                                           startup_cost,
                                                                           total_cost,
 
  * This function is never called from core Postgres; rather, it's expected
  * to be called by the GetForeignPaths or GetForeignJoinPaths function of
  * a foreign data wrapper.  We make the FDW supply all fields of the path,
- * since we do not have any way to calculate them in core.
+ * since we do not have any way to calculate them in core.  However, there
+ * is a sane default for the pathtarget (rel->reltarget), so we let a NULL
+ * for "target" select that.
  */
 ForeignPath *
 create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel,
+                                               PathTarget *target,
                                                double rows, Cost startup_cost, Cost total_cost,
                                                List *pathkeys,
                                                Relids required_outer,
 
        pathnode->path.pathtype = T_ForeignScan;
        pathnode->path.parent = rel;
-       pathnode->path.pathtarget = rel->reltarget;
+       pathnode->path.pathtarget = target ? target : rel->reltarget;
        pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
                                                                                                                  required_outer);
        pathnode->path.parallel_aware = false;
 
 extern Path *create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel,
                                                  Relids required_outer);
 extern ForeignPath *create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel,
+                                               PathTarget *target,
                                                double rows, Cost startup_cost, Cost total_cost,
                                                List *pathkeys,
                                                Relids required_outer,