diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/README | 5 | ||||
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 16 | ||||
-rw-r--r-- | src/backend/optimizer/util/pathnode.c | 14 | ||||
-rw-r--r-- | src/include/foreign/fdwapi.h | 6 |
4 files changed, 27 insertions, 14 deletions
diff --git a/src/backend/optimizer/README b/src/backend/optimizer/README index 7ecf8c8f0cc..0d973d77e0b 100644 --- a/src/backend/optimizer/README +++ b/src/backend/optimizer/README @@ -916,7 +916,10 @@ remote aggregation into the UPPERREL_GROUP_AGG upperrel, if it notices that the query represents an aggregation that could be done entirely on the foreign server. That Path will then compete with Paths representing local aggregation on a regular scan of the foreign table, once the core -planner reaches the point of considering aggregation. +planner reaches the point of considering aggregation. (In practice, +it will usually be more convenient for FDWs to detect such cases in a +GetForeignUpperPaths callback; but that still represents injecting a +Path before the core code has touched the corresponding upperrel.) Parallel Query and Partial Paths diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index d11f44e64d5..fc0a2d8de35 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -1752,13 +1752,17 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, root->upper_targets[UPPERREL_GROUP_AGG] = grouping_target; /* - * Let extensions, particularly CustomScan providers, consider - * injecting extension Paths into the query's upperrels, where they - * will compete with the Paths we create below. We pass the final - * scan/join rel because that's not so easily findable from the - * PlannerInfo struct; anything else the hook wants to know should be - * obtainable via "root". + * Let extensions, particularly FDWs and CustomScan providers, + * consider injecting extension Paths into the query's upperrels, + * where they will compete with the Paths we create below. We pass + * the final scan/join rel because that's not so easily findable from + * the PlannerInfo struct; anything else the hooks want to know should + * be obtainable via "root". */ + if (current_rel->fdwroutine && + current_rel->fdwroutine->GetForeignUpperPaths) + current_rel->fdwroutine->GetForeignUpperPaths(root, current_rel); + if (create_upper_paths_hook) (*create_upper_paths_hook) (root, current_rel); diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index 675e47cdd01..b8ea3168a84 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -1813,15 +1813,15 @@ create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel, /* * create_foreignscan_path - * Creates a path corresponding to a scan of a foreign table or - * a foreign join, returning the pathnode. + * Creates a path corresponding to a scan of a foreign table, foreign join, + * or foreign upper-relation processing, returning the pathnode. * * 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. However, there - * is a sane default for the pathtarget (rel->reltarget), so we let a NULL - * for "target" select that. + * to be called by the GetForeignPaths, GetForeignJoinPaths, or + * GetForeignUpperPaths 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. However, there is a usually-sane default for the pathtarget + * (rel->reltarget), so we let a NULL for "target" select that. */ ForeignPath * create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, diff --git a/src/include/foreign/fdwapi.h b/src/include/foreign/fdwapi.h index ae3c230d667..71643602823 100644 --- a/src/include/foreign/fdwapi.h +++ b/src/include/foreign/fdwapi.h @@ -59,6 +59,9 @@ typedef void (*GetForeignJoinPaths_function) (PlannerInfo *root, JoinType jointype, JoinPathExtraData *extra); +typedef void (*GetForeignUpperPaths_function) (PlannerInfo *root, + RelOptInfo *scan_join_rel); + typedef void (*AddForeignUpdateTargets_function) (Query *parsetree, RangeTblEntry *target_rte, Relation target_relation); @@ -166,6 +169,9 @@ typedef struct FdwRoutine /* Functions for remote-join planning */ GetForeignJoinPaths_function GetForeignJoinPaths; + /* Functions for remote upper-relation (post scan/join) planning */ + GetForeignUpperPaths_function GetForeignUpperPaths; + /* Functions for updating foreign tables */ AddForeignUpdateTargets_function AddForeignUpdateTargets; PlanForeignModify_function PlanForeignModify; |