From bb742407947ad1cbf19355d24282380d576e7654 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 20 Feb 2011 00:17:18 -0500 Subject: Implement an API to let foreign-data wrappers actually be functional. This commit provides the core code and documentation needed. A contrib module test case will follow shortly. Shigeru Hanada, Jan Urbanski, Heikki Linnakangas --- src/backend/optimizer/util/pathnode.c | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/backend/optimizer/util/pathnode.c') diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index d1010af662..1158f7715b 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -17,6 +17,7 @@ #include #include "catalog/pg_operator.h" +#include "foreign/fdwapi.h" #include "miscadmin.h" #include "nodes/nodeFuncs.h" #include "optimizer/clauses.h" @@ -1419,6 +1420,41 @@ create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel) return pathnode; } +/* + * create_foreignscan_path + * Creates a path corresponding to a scan of a foreign table, + * returning the pathnode. + */ +ForeignPath * +create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel) +{ + ForeignPath *pathnode = makeNode(ForeignPath); + RangeTblEntry *rte; + FdwRoutine *fdwroutine; + FdwPlan *fdwplan; + + pathnode->path.pathtype = T_ForeignScan; + pathnode->path.parent = rel; + pathnode->path.pathkeys = NIL; /* result is always unordered */ + + /* Get FDW's callback info */ + rte = planner_rt_fetch(rel->relid, root); + fdwroutine = GetFdwRoutineByRelId(rte->relid); + + /* Let the FDW do its planning */ + fdwplan = fdwroutine->PlanForeignScan(rte->relid, root, rel); + if (fdwplan == NULL || !IsA(fdwplan, FdwPlan)) + elog(ERROR, "foreign-data wrapper PlanForeignScan function for relation %u did not return an FdwPlan struct", + rte->relid); + pathnode->fdwplan = fdwplan; + + /* use costs estimated by FDW */ + pathnode->path.startup_cost = fdwplan->startup_cost; + pathnode->path.total_cost = fdwplan->total_cost; + + return pathnode; +} + /* * create_nestloop_path * Creates a pathnode corresponding to a nestloop join between two -- cgit v1.2.1