Skip to content

Commit 90acd5a

Browse files
tglsfdckelvich
authored andcommitted
Allow callers of create_foreignscan_path to specify nondefault PathTarget.
Although the default choice of rel->reltarget should typically be sufficient for scan or join paths, it's not at all sufficient for the purposes PathTargets were invented for; in particular not for upper-relation Paths. So break API compatibility by adding a PathTarget argument to create_foreignscan_path(). To ease updating of existing code, accept a NULL value of the argument as selecting rel->reltarget.
1 parent 1a312b4 commit 90acd5a

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

contrib/file_fdw/file_fdw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ fileGetForeignPaths(PlannerInfo *root,
524524
*/
525525
add_path(baserel, (Path *)
526526
create_foreignscan_path(root, baserel,
527+
NULL, /* default pathtarget */
527528
baserel->rows,
528529
startup_cost,
529530
total_cost,

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ postgresGetForeignPaths(PlannerInfo *root,
797797
* to estimate cost and size of this path.
798798
*/
799799
path = create_foreignscan_path(root, baserel,
800+
NULL, /* default pathtarget */
800801
fpinfo->rows,
801802
fpinfo->startup_cost,
802803
fpinfo->total_cost,
@@ -968,6 +969,7 @@ postgresGetForeignPaths(PlannerInfo *root,
968969

969970
/* Make the path */
970971
path = create_foreignscan_path(root, baserel,
972+
NULL, /* default pathtarget */
971973
rows,
972974
startup_cost,
973975
total_cost,
@@ -3569,6 +3571,7 @@ add_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel,
35693571

35703572
add_path(rel, (Path *)
35713573
create_foreignscan_path(root, rel,
3574+
NULL,
35723575
rows,
35733576
startup_cost,
35743577
total_cost,
@@ -3706,6 +3709,7 @@ postgresGetForeignJoinPaths(PlannerInfo *root,
37063709
*/
37073710
joinpath = create_foreignscan_path(root,
37083711
joinrel,
3712+
NULL, /* default pathtarget */
37093713
rows,
37103714
startup_cost,
37113715
total_cost,

src/backend/optimizer/util/pathnode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,10 +1819,13 @@ create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel,
18191819
* This function is never called from core Postgres; rather, it's expected
18201820
* to be called by the GetForeignPaths or GetForeignJoinPaths function of
18211821
* a foreign data wrapper. We make the FDW supply all fields of the path,
1822-
* since we do not have any way to calculate them in core.
1822+
* since we do not have any way to calculate them in core. However, there
1823+
* is a sane default for the pathtarget (rel->reltarget), so we let a NULL
1824+
* for "target" select that.
18231825
*/
18241826
ForeignPath *
18251827
create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel,
1828+
PathTarget *target,
18261829
double rows, Cost startup_cost, Cost total_cost,
18271830
List *pathkeys,
18281831
Relids required_outer,
@@ -1833,7 +1836,7 @@ create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel,
18331836

18341837
pathnode->path.pathtype = T_ForeignScan;
18351838
pathnode->path.parent = rel;
1836-
pathnode->path.pathtarget = rel->reltarget;
1839+
pathnode->path.pathtarget = target ? target : rel->reltarget;
18371840
pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
18381841
required_outer);
18391842
pathnode->path.parallel_aware = false;

src/include/optimizer/pathnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extern Path *create_ctescan_path(PlannerInfo *root, RelOptInfo *rel,
8787
extern Path *create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel,
8888
Relids required_outer);
8989
extern ForeignPath *create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel,
90+
PathTarget *target,
9091
double rows, Cost startup_cost, Cost total_cost,
9192
List *pathkeys,
9293
Relids required_outer,

0 commit comments

Comments
 (0)