Revise FDW planning API, again.
Further reflection shows that a single callback isn't very workable if we
desire to let FDWs generate multiple Paths, because that forces the FDW to
do all work necessary to generate a valid Plan node for each Path. Instead
split the former PlanForeignScan API into three steps: GetForeignRelSize,
GetForeignPaths, GetForeignPlan. We had already bit the bullet of breaking
the 9.1 FDW API for 9.2, so this shouldn't cause very much additional pain,
and it's substantially more flexible for complex FDWs.
Add an fdw_private field to RelOptInfo so that the new functions can save
state there rather than possibly having to recalculate information two or
three times.
In addition, we'd not thought through what would be needed to allow an FDW
to set up subexpressions of its choice for runtime execution. We could
treat ForeignScan.fdw_private as an executable expression but that seems
likely to break existing FDWs unnecessarily (in particular, it would
restrict the set of node types allowable in fdw_private to those supported
by expression_tree_walker). Instead, invent a separate field fdw_exprs
which will receive the postprocessing appropriate for expression trees.
(One field is enough since it can be a list of expressions; also, we assume
the corresponding expression state tree(s) will be held within fdw_state,
so we don't need to add anything to ForeignScanState.)
Per review of Hanada Shigeru's pgsql_fdw patch. We may need to tweak this
further as we continue to work on that patch, but to me it feels a lot
closer to being right now.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/b14953932dfdda7d915b9e276a09df8458efeec8
Modified Files
--------------
contrib/file_fdw/file_fdw.c | 161 +++++++++++++++++-----
doc/src/sgml/fdwhandler.sgml | 230 ++++++++++++++++++++++++++-----
src/backend/nodes/copyfuncs.c | 3 +-
src/backend/nodes/outfuncs.c | 4 +-
src/backend/optimizer/path/allpaths.c | 13 +-
src/backend/optimizer/path/costsize.c | 2 +-
src/backend/optimizer/plan/createplan.c | 67 ++++++---
src/backend/optimizer/plan/setrefs.c | 2 +
src/backend/optimizer/plan/subselect.c | 2 +
src/backend/optimizer/util/pathnode.c | 2 +-
src/backend/optimizer/util/relnode.c | 4 +
src/include/foreign/fdwapi.h | 21 +++-
src/include/nodes/plannodes.h | 11 ++-
src/include/nodes/relation.h | 24 ++--
src/include/optimizer/planmain.h | 2 +
15 files changed, 436 insertions(+), 112 deletions(-)