2011-02-20 06:17:18 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* fdwapi.h
|
|
|
|
* API for foreign-data wrappers
|
|
|
|
*
|
2015-01-06 17:43:47 +01:00
|
|
|
* Copyright (c) 2010-2015, PostgreSQL Global Development Group
|
2011-02-20 06:17:18 +01:00
|
|
|
*
|
|
|
|
* src/include/foreign/fdwapi.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef FDWAPI_H
|
|
|
|
#define FDWAPI_H
|
|
|
|
|
|
|
|
#include "nodes/execnodes.h"
|
|
|
|
#include "nodes/relation.h"
|
|
|
|
|
|
|
|
/* To avoid including explain.h here, reference ExplainState thus: */
|
|
|
|
struct ExplainState;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback function signatures --- see fdwhandler.sgml for more info.
|
|
|
|
*/
|
|
|
|
|
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.
2012-03-09 18:48:48 +01:00
|
|
|
typedef void (*GetForeignRelSize_function) (PlannerInfo *root,
|
2012-06-10 21:20:04 +02:00
|
|
|
RelOptInfo *baserel,
|
|
|
|
Oid foreigntableid);
|
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.
2012-03-09 18:48:48 +01:00
|
|
|
|
|
|
|
typedef void (*GetForeignPaths_function) (PlannerInfo *root,
|
2012-06-10 21:20:04 +02:00
|
|
|
RelOptInfo *baserel,
|
|
|
|
Oid foreigntableid);
|
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.
2012-03-09 18:48:48 +01:00
|
|
|
|
|
|
|
typedef ForeignScan *(*GetForeignPlan_function) (PlannerInfo *root,
|
2012-06-10 21:20:04 +02:00
|
|
|
RelOptInfo *baserel,
|
|
|
|
Oid foreigntableid,
|
|
|
|
ForeignPath *best_path,
|
|
|
|
List *tlist,
|
|
|
|
List *scan_clauses);
|
2011-02-20 06:17:18 +01:00
|
|
|
|
|
|
|
typedef void (*BeginForeignScan_function) (ForeignScanState *node,
|
2011-04-10 17:42:00 +02:00
|
|
|
int eflags);
|
2011-02-20 06:17:18 +01:00
|
|
|
|
2011-04-10 17:42:00 +02:00
|
|
|
typedef TupleTableSlot *(*IterateForeignScan_function) (ForeignScanState *node);
|
2011-02-20 06:17:18 +01:00
|
|
|
|
|
|
|
typedef void (*ReScanForeignScan_function) (ForeignScanState *node);
|
|
|
|
|
|
|
|
typedef void (*EndForeignScan_function) (ForeignScanState *node);
|
|
|
|
|
Code review for foreign/custom join pushdown patch.
Commit e7cb7ee14555cc9c5773e2c102efd6371f6f2005 included some design
decisions that seem pretty questionable to me, and there was quite a lot
of stuff not to like about the documentation and comments. Clean up
as follows:
* Consider foreign joins only between foreign tables on the same server,
rather than between any two foreign tables with the same underlying FDW
handler function. In most if not all cases, the FDW would simply have had
to apply the same-server restriction itself (far more expensively, both for
lack of caching and because it would be repeated for each combination of
input sub-joins), or else risk nasty bugs. Anyone who's really intent on
doing something outside this restriction can always use the
set_join_pathlist_hook.
* Rename fdw_ps_tlist/custom_ps_tlist to fdw_scan_tlist/custom_scan_tlist
to better reflect what they're for, and allow these custom scan tlists
to be used even for base relations.
* Change make_foreignscan() API to include passing the fdw_scan_tlist
value, since the FDW is required to set that. Backwards compatibility
doesn't seem like an adequate reason to expect FDWs to set it in some
ad-hoc extra step, and anyway existing FDWs can just pass NIL.
* Change the API of path-generating subroutines of add_paths_to_joinrel,
and in particular that of GetForeignJoinPaths and set_join_pathlist_hook,
so that various less-used parameters are passed in a struct rather than
as separate parameter-list entries. The objective here is to reduce the
probability that future additions to those parameter lists will result in
source-level API breaks for users of these hooks. It's possible that this
is even a small win for the core code, since most CPU architectures can't
pass more than half a dozen parameters efficiently anyway. I kept root,
joinrel, outerrel, innerrel, and jointype as separate parameters to reduce
code churn in joinpath.c --- in particular, putting jointype into the
struct would have been problematic because of the subroutines' habit of
changing their local copies of that variable.
* Avoid ad-hocery in ExecAssignScanProjectionInfo. It was probably all
right for it to know about IndexOnlyScan, but if the list is to grow
we should refactor the knowledge out to the callers.
* Restore nodeForeignscan.c's previous use of the relcache to avoid
extra GetFdwRoutine lookups for base-relation scans.
* Lots of cleanup of documentation and missed comments. Re-order some
code additions into more logical places.
2015-05-10 20:36:30 +02:00
|
|
|
typedef void (*GetForeignJoinPaths_function) (PlannerInfo *root,
|
|
|
|
RelOptInfo *joinrel,
|
|
|
|
RelOptInfo *outerrel,
|
|
|
|
RelOptInfo *innerrel,
|
|
|
|
JoinType jointype,
|
|
|
|
JoinPathExtraData *extra);
|
|
|
|
|
2013-03-10 19:14:53 +01:00
|
|
|
typedef void (*AddForeignUpdateTargets_function) (Query *parsetree,
|
|
|
|
RangeTblEntry *target_rte,
|
|
|
|
Relation target_relation);
|
|
|
|
|
|
|
|
typedef List *(*PlanForeignModify_function) (PlannerInfo *root,
|
|
|
|
ModifyTable *plan,
|
|
|
|
Index resultRelation,
|
|
|
|
int subplan_index);
|
|
|
|
|
|
|
|
typedef void (*BeginForeignModify_function) (ModifyTableState *mtstate,
|
|
|
|
ResultRelInfo *rinfo,
|
|
|
|
List *fdw_private,
|
|
|
|
int subplan_index,
|
|
|
|
int eflags);
|
|
|
|
|
|
|
|
typedef TupleTableSlot *(*ExecForeignInsert_function) (EState *estate,
|
|
|
|
ResultRelInfo *rinfo,
|
|
|
|
TupleTableSlot *slot,
|
|
|
|
TupleTableSlot *planSlot);
|
|
|
|
|
|
|
|
typedef TupleTableSlot *(*ExecForeignUpdate_function) (EState *estate,
|
|
|
|
ResultRelInfo *rinfo,
|
|
|
|
TupleTableSlot *slot,
|
|
|
|
TupleTableSlot *planSlot);
|
|
|
|
|
|
|
|
typedef TupleTableSlot *(*ExecForeignDelete_function) (EState *estate,
|
|
|
|
ResultRelInfo *rinfo,
|
|
|
|
TupleTableSlot *slot,
|
|
|
|
TupleTableSlot *planSlot);
|
|
|
|
|
|
|
|
typedef void (*EndForeignModify_function) (EState *estate,
|
|
|
|
ResultRelInfo *rinfo);
|
|
|
|
|
2013-06-12 23:52:54 +02:00
|
|
|
typedef int (*IsForeignRelUpdatable_function) (Relation rel);
|
|
|
|
|
2013-03-10 19:14:53 +01:00
|
|
|
typedef void (*ExplainForeignScan_function) (ForeignScanState *node,
|
|
|
|
struct ExplainState *es);
|
|
|
|
|
|
|
|
typedef void (*ExplainForeignModify_function) (ModifyTableState *mtstate,
|
|
|
|
ResultRelInfo *rinfo,
|
|
|
|
List *fdw_private,
|
|
|
|
int subplan_index,
|
|
|
|
struct ExplainState *es);
|
|
|
|
|
2012-04-06 21:02:35 +02:00
|
|
|
typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel,
|
2012-06-10 21:20:04 +02:00
|
|
|
HeapTuple *rows, int targrows,
|
|
|
|
double *totalrows,
|
|
|
|
double *totaldeadrows);
|
2012-04-06 21:02:35 +02:00
|
|
|
|
2012-04-06 22:04:10 +02:00
|
|
|
typedef bool (*AnalyzeForeignTable_function) (Relation relation,
|
2012-06-10 21:20:04 +02:00
|
|
|
AcquireSampleRowsFunc *func,
|
|
|
|
BlockNumber *totalpages);
|
2011-02-20 06:17:18 +01:00
|
|
|
|
2014-07-10 21:01:31 +02:00
|
|
|
typedef List *(*ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt,
|
|
|
|
Oid serverOid);
|
|
|
|
|
2011-02-20 06:17:18 +01:00
|
|
|
/*
|
|
|
|
* FdwRoutine is the struct returned by a foreign-data wrapper's handler
|
|
|
|
* function. It provides pointers to the callback functions needed by the
|
|
|
|
* planner and executor.
|
|
|
|
*
|
2012-04-06 21:02:35 +02:00
|
|
|
* More function pointers are likely to be added in the future. Therefore
|
|
|
|
* it's recommended that the handler initialize the struct with
|
|
|
|
* makeNode(FdwRoutine) so that all fields are set to NULL. This will
|
|
|
|
* ensure that no fields are accidentally left undefined.
|
2011-02-20 06:17:18 +01:00
|
|
|
*/
|
|
|
|
typedef struct FdwRoutine
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
|
2013-03-10 19:14:53 +01:00
|
|
|
/* Functions for scanning foreign tables */
|
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.
2012-03-09 18:48:48 +01:00
|
|
|
GetForeignRelSize_function GetForeignRelSize;
|
|
|
|
GetForeignPaths_function GetForeignPaths;
|
|
|
|
GetForeignPlan_function GetForeignPlan;
|
2011-02-20 06:17:18 +01:00
|
|
|
BeginForeignScan_function BeginForeignScan;
|
|
|
|
IterateForeignScan_function IterateForeignScan;
|
|
|
|
ReScanForeignScan_function ReScanForeignScan;
|
|
|
|
EndForeignScan_function EndForeignScan;
|
2012-04-06 21:02:35 +02:00
|
|
|
|
|
|
|
/*
|
2013-03-10 19:14:53 +01:00
|
|
|
* Remaining functions are optional. Set the pointer to NULL for any that
|
|
|
|
* are not provided.
|
2012-04-06 21:02:35 +02:00
|
|
|
*/
|
2013-03-10 19:14:53 +01:00
|
|
|
|
Code review for foreign/custom join pushdown patch.
Commit e7cb7ee14555cc9c5773e2c102efd6371f6f2005 included some design
decisions that seem pretty questionable to me, and there was quite a lot
of stuff not to like about the documentation and comments. Clean up
as follows:
* Consider foreign joins only between foreign tables on the same server,
rather than between any two foreign tables with the same underlying FDW
handler function. In most if not all cases, the FDW would simply have had
to apply the same-server restriction itself (far more expensively, both for
lack of caching and because it would be repeated for each combination of
input sub-joins), or else risk nasty bugs. Anyone who's really intent on
doing something outside this restriction can always use the
set_join_pathlist_hook.
* Rename fdw_ps_tlist/custom_ps_tlist to fdw_scan_tlist/custom_scan_tlist
to better reflect what they're for, and allow these custom scan tlists
to be used even for base relations.
* Change make_foreignscan() API to include passing the fdw_scan_tlist
value, since the FDW is required to set that. Backwards compatibility
doesn't seem like an adequate reason to expect FDWs to set it in some
ad-hoc extra step, and anyway existing FDWs can just pass NIL.
* Change the API of path-generating subroutines of add_paths_to_joinrel,
and in particular that of GetForeignJoinPaths and set_join_pathlist_hook,
so that various less-used parameters are passed in a struct rather than
as separate parameter-list entries. The objective here is to reduce the
probability that future additions to those parameter lists will result in
source-level API breaks for users of these hooks. It's possible that this
is even a small win for the core code, since most CPU architectures can't
pass more than half a dozen parameters efficiently anyway. I kept root,
joinrel, outerrel, innerrel, and jointype as separate parameters to reduce
code churn in joinpath.c --- in particular, putting jointype into the
struct would have been problematic because of the subroutines' habit of
changing their local copies of that variable.
* Avoid ad-hocery in ExecAssignScanProjectionInfo. It was probably all
right for it to know about IndexOnlyScan, but if the list is to grow
we should refactor the knowledge out to the callers.
* Restore nodeForeignscan.c's previous use of the relcache to avoid
extra GetFdwRoutine lookups for base-relation scans.
* Lots of cleanup of documentation and missed comments. Re-order some
code additions into more logical places.
2015-05-10 20:36:30 +02:00
|
|
|
/* Functions for remote-join planning */
|
|
|
|
GetForeignJoinPaths_function GetForeignJoinPaths;
|
|
|
|
|
2013-03-10 19:14:53 +01:00
|
|
|
/* Functions for updating foreign tables */
|
|
|
|
AddForeignUpdateTargets_function AddForeignUpdateTargets;
|
|
|
|
PlanForeignModify_function PlanForeignModify;
|
|
|
|
BeginForeignModify_function BeginForeignModify;
|
|
|
|
ExecForeignInsert_function ExecForeignInsert;
|
|
|
|
ExecForeignUpdate_function ExecForeignUpdate;
|
|
|
|
ExecForeignDelete_function ExecForeignDelete;
|
|
|
|
EndForeignModify_function EndForeignModify;
|
2013-06-12 23:52:54 +02:00
|
|
|
IsForeignRelUpdatable_function IsForeignRelUpdatable;
|
2013-03-10 19:14:53 +01:00
|
|
|
|
|
|
|
/* Support functions for EXPLAIN */
|
|
|
|
ExplainForeignScan_function ExplainForeignScan;
|
|
|
|
ExplainForeignModify_function ExplainForeignModify;
|
|
|
|
|
|
|
|
/* Support functions for ANALYZE */
|
2012-04-06 21:02:35 +02:00
|
|
|
AnalyzeForeignTable_function AnalyzeForeignTable;
|
2014-07-10 21:01:31 +02:00
|
|
|
|
|
|
|
/* Support functions for IMPORT FOREIGN SCHEMA */
|
|
|
|
ImportForeignSchema_function ImportForeignSchema;
|
2011-02-20 06:17:18 +01:00
|
|
|
} FdwRoutine;
|
|
|
|
|
|
|
|
|
|
|
|
/* Functions in foreign/foreign.c */
|
|
|
|
extern FdwRoutine *GetFdwRoutine(Oid fdwhandler);
|
Code review for foreign/custom join pushdown patch.
Commit e7cb7ee14555cc9c5773e2c102efd6371f6f2005 included some design
decisions that seem pretty questionable to me, and there was quite a lot
of stuff not to like about the documentation and comments. Clean up
as follows:
* Consider foreign joins only between foreign tables on the same server,
rather than between any two foreign tables with the same underlying FDW
handler function. In most if not all cases, the FDW would simply have had
to apply the same-server restriction itself (far more expensively, both for
lack of caching and because it would be repeated for each combination of
input sub-joins), or else risk nasty bugs. Anyone who's really intent on
doing something outside this restriction can always use the
set_join_pathlist_hook.
* Rename fdw_ps_tlist/custom_ps_tlist to fdw_scan_tlist/custom_scan_tlist
to better reflect what they're for, and allow these custom scan tlists
to be used even for base relations.
* Change make_foreignscan() API to include passing the fdw_scan_tlist
value, since the FDW is required to set that. Backwards compatibility
doesn't seem like an adequate reason to expect FDWs to set it in some
ad-hoc extra step, and anyway existing FDWs can just pass NIL.
* Change the API of path-generating subroutines of add_paths_to_joinrel,
and in particular that of GetForeignJoinPaths and set_join_pathlist_hook,
so that various less-used parameters are passed in a struct rather than
as separate parameter-list entries. The objective here is to reduce the
probability that future additions to those parameter lists will result in
source-level API breaks for users of these hooks. It's possible that this
is even a small win for the core code, since most CPU architectures can't
pass more than half a dozen parameters efficiently anyway. I kept root,
joinrel, outerrel, innerrel, and jointype as separate parameters to reduce
code churn in joinpath.c --- in particular, putting jointype into the
struct would have been problematic because of the subroutines' habit of
changing their local copies of that variable.
* Avoid ad-hocery in ExecAssignScanProjectionInfo. It was probably all
right for it to know about IndexOnlyScan, but if the list is to grow
we should refactor the knowledge out to the callers.
* Restore nodeForeignscan.c's previous use of the relcache to avoid
extra GetFdwRoutine lookups for base-relation scans.
* Lots of cleanup of documentation and missed comments. Re-order some
code additions into more logical places.
2015-05-10 20:36:30 +02:00
|
|
|
extern Oid GetForeignServerIdByRelId(Oid relid);
|
|
|
|
extern FdwRoutine *GetFdwRoutineByServerId(Oid serverid);
|
2011-02-20 06:17:18 +01:00
|
|
|
extern FdwRoutine *GetFdwRoutineByRelId(Oid relid);
|
2013-03-07 05:47:38 +01:00
|
|
|
extern FdwRoutine *GetFdwRoutineForRelation(Relation relation, bool makecopy);
|
2014-07-10 21:01:31 +02:00
|
|
|
extern bool IsImportableForeignTable(const char *tablename,
|
|
|
|
ImportForeignSchemaStmt *stmt);
|
2011-02-20 06:17:18 +01:00
|
|
|
|
|
|
|
#endif /* FDWAPI_H */
|