From 101fd9349eddb7e9ed84a239145d5230a9bc7336 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 14 Mar 2016 20:04:44 -0400 Subject: Add a GetForeignUpperPaths callback function for FDWs. This is basically like the just-added create_upper_paths_hook, but control is funneled only to the FDW responsible for all the baserels of the current query; so providing such a callback is much less likely to add useless overhead than using the hook function is. The documentation is a bit sketchy. We'll likely want to improve it, and/or adjust the call conventions, when we get some experience with actually using this callback. Hopefully somebody will find time to experiment with it before 9.6 feature freeze. --- doc/src/sgml/fdwhandler.sgml | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml index bbc9c03721e..15ddc1977ad 100644 --- a/doc/src/sgml/fdwhandler.sgml +++ b/doc/src/sgml/fdwhandler.sgml @@ -176,7 +176,8 @@ GetForeignPlan (PlannerInfo *root, access path. This is called at the end of query planning. The parameters are as for GetForeignRelSize, plus the selected ForeignPath (previously produced by - GetForeignPaths or GetForeignJoinPaths), + GetForeignPaths, GetForeignJoinPaths, + or GetForeignUpperPaths), the target list to be emitted by the plan node, the restriction clauses to be enforced by the plan node, and the outer subplan of the ForeignScan, @@ -344,6 +345,38 @@ GetForeignJoinPaths (PlannerInfo *root, + + FDW Routines For Planning Post-Scan/Join Processing + + + If an FDW supports performing remote post-scan/join processing, such as + remote aggregation, it should provide this callback function: + + + + +void +GetForeignUpperPaths (PlannerInfo *root, + RelOptInfo *scan_join_rel); + + Create possible access paths for upper relation processing, + which is the planner's term for all post-scan/join query processing, such + as aggregation, window functions, sorting, and table updates. This + optional function is called during query planning. Currently, it is + called only if all base relation(s) involved in the query belong to the + same FDW. This function should generate ForeignPath + path(s) for the steps that the FDW knows how to perform remotely, and + call add_path to add these paths to the appropriate upper + relation. As with GetForeignJoinPaths, it is not necessary + that this function succeed in creating any paths, since paths involving + local processing are always possible. + + + + See for additional information. + + + FDW Routines For Updating Foreign Tables @@ -1160,7 +1193,8 @@ GetForeignServerByName(const char *name, bool missing_ok); The FDW callback functions GetForeignRelSize, GetForeignPaths, GetForeignPlan, - PlanForeignModify, and GetForeignJoinPaths + PlanForeignModify, GetForeignJoinPaths, + and GetForeignUpperPaths must fit into the workings of the PostgreSQL planner. Here are some notes about what they must do. @@ -1322,7 +1356,7 @@ GetForeignServerByName(const char *name, bool missing_ok); An FDW might additionally support direct execution of some plan actions that are above the level of scans and joins, such as grouping or aggregation. To offer such options, the FDW should generate paths - (probably ForeignPaths or CustomPaths) and insert them into the + and insert them into the appropriate upper relation. For example, a path representing remote aggregation should be inserted into the relation obtained from fetch_upper_rel(root, UPPERREL_GROUP_AGG, @@ -1332,6 +1366,9 @@ GetForeignServerByName(const char *name, bool missing_ok); else there will be an error at plan time). If the remote-aggregation path wins, which it usually would, it will be converted into a plan in the usual way, by calling GetForeignPlan. + Usually the most convenient place to generate such paths is in + the GetForeignUpperPaths callback function, although + it can be done earlier if that seems appropriate. -- cgit v1.2.3