2011-02-20 06:17:18 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* fdwapi.h
|
|
|
|
* API for foreign-data wrappers
|
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Copyright (c) 2010-2016, PostgreSQL Global Development Group
|
2011-02-20 06:17:18 +01:00
|
|
|
*
|
|
|
|
* src/include/foreign/fdwapi.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef FDWAPI_H
|
|
|
|
#define FDWAPI_H
|
|
|
|
|
2016-02-03 18:46:18 +01:00
|
|
|
#include "access/parallel.h"
|
2011-02-20 06:17:18 +01:00
|
|
|
#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,
|
Allow foreign and custom joins to handle EvalPlanQual rechecks.
Commit e7cb7ee14555cc9c5773e2c102efd6371f6f2005 provided basic
infrastructure for allowing a foreign data wrapper or custom scan
provider to replace a join of one or more tables with a scan.
However, this infrastructure failed to take into account the need
for possible EvalPlanQual rechecks, and ExecScanFetch would fail
an assertion (or just overwrite memory) if such a check was attempted
for a plan containing a pushed-down join. To fix, adjust the EPQ
machinery to skip some processing steps when scanrelid == 0, making
those the responsibility of scan's recheck method, which also has
the responsibility in this case of correctly populating the relevant
slot.
To allow foreign scans to gain control in the right place to make
use of this new facility, add a new, optional RecheckForeignScan
method. Also, allow a foreign scan to have a child plan, which can
be used to correctly populate the slot (or perhaps for something
else, but this is the only use currently envisioned).
KaiGai Kohei, reviewed by Robert Haas, Etsuro Fujita, and Kyotaro
Horiguchi.
2015-12-08 18:31:03 +01:00
|
|
|
List *scan_clauses,
|
|
|
|
Plan *outer_plan);
|
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
|
|
|
|
Allow foreign and custom joins to handle EvalPlanQual rechecks.
Commit e7cb7ee14555cc9c5773e2c102efd6371f6f2005 provided basic
infrastructure for allowing a foreign data wrapper or custom scan
provider to replace a join of one or more tables with a scan.
However, this infrastructure failed to take into account the need
for possible EvalPlanQual rechecks, and ExecScanFetch would fail
an assertion (or just overwrite memory) if such a check was attempted
for a plan containing a pushed-down join. To fix, adjust the EPQ
machinery to skip some processing steps when scanrelid == 0, making
those the responsibility of scan's recheck method, which also has
the responsibility in this case of correctly populating the relevant
slot.
To allow foreign scans to gain control in the right place to make
use of this new facility, add a new, optional RecheckForeignScan
method. Also, allow a foreign scan to have a child plan, which can
be used to correctly populate the slot (or perhaps for something
else, but this is the only use currently envisioned).
KaiGai Kohei, reviewed by Robert Haas, Etsuro Fujita, and Kyotaro
Horiguchi.
2015-12-08 18:31:03 +01:00
|
|
|
typedef bool (*RecheckForeignScan_function) (ForeignScanState *node,
|
|
|
|
TupleTableSlot *slot);
|
|
|
|
|
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);
|
|
|
|
|
2016-03-15 01:04:44 +01:00
|
|
|
typedef void (*GetForeignUpperPaths_function) (PlannerInfo *root,
|
2016-07-01 19:12:34 +02:00
|
|
|
UpperRelationKind stage,
|
|
|
|
RelOptInfo *input_rel,
|
|
|
|
RelOptInfo *output_rel);
|
2016-03-15 01:04:44 +01:00
|
|
|
|
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);
|
|
|
|
|
2016-03-18 18:48:58 +01:00
|
|
|
typedef bool (*PlanDirectModify_function) (PlannerInfo *root,
|
2016-06-10 00:02:36 +02:00
|
|
|
ModifyTable *plan,
|
|
|
|
Index resultRelation,
|
|
|
|
int subplan_index);
|
2016-03-18 18:48:58 +01:00
|
|
|
|
|
|
|
typedef void (*BeginDirectModify_function) (ForeignScanState *node,
|
2016-06-10 00:02:36 +02:00
|
|
|
int eflags);
|
2016-03-18 18:48:58 +01:00
|
|
|
|
|
|
|
typedef TupleTableSlot *(*IterateDirectModify_function) (ForeignScanState *node);
|
|
|
|
|
|
|
|
typedef void (*EndDirectModify_function) (ForeignScanState *node);
|
|
|
|
|
Add support for doing late row locking in FDWs.
Previously, FDWs could only do "early row locking", that is lock a row as
soon as it's fetched, even though local restriction/join conditions might
discard the row later. This patch adds callbacks that allow FDWs to do
late locking in the same way that it's done for regular tables.
To make use of this feature, an FDW must support the "ctid" column as a
unique row identifier. Currently, since ctid has to be of type TID,
the feature is of limited use, though in principle it could be used by
postgres_fdw. We may eventually allow FDWs to specify another data type
for ctid, which would make it possible for more FDWs to use this feature.
This commit does not modify postgres_fdw to use late locking. We've
tested some prototype code for that, but it's not in committable shape,
and besides it's quite unclear whether it actually makes sense to do late
locking against a remote server. The extra round trips required are likely
to outweigh any benefit from improved concurrency.
Etsuro Fujita, reviewed by Ashutosh Bapat, and hacked up a lot by me
2015-05-12 20:10:10 +02:00
|
|
|
typedef RowMarkType (*GetForeignRowMarkType_function) (RangeTblEntry *rte,
|
|
|
|
LockClauseStrength strength);
|
|
|
|
|
|
|
|
typedef HeapTuple (*RefetchForeignRow_function) (EState *estate,
|
|
|
|
ExecRowMark *erm,
|
|
|
|
Datum rowid,
|
|
|
|
bool *updated);
|
|
|
|
|
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);
|
|
|
|
|
2016-03-18 18:48:58 +01:00
|
|
|
typedef void (*ExplainDirectModify_function) (ForeignScanState *node,
|
|
|
|
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);
|
|
|
|
|
2016-02-03 18:46:18 +01:00
|
|
|
typedef Size (*EstimateDSMForeignScan_function) (ForeignScanState *node,
|
2016-06-10 00:02:36 +02:00
|
|
|
ParallelContext *pcxt);
|
2016-02-03 18:46:18 +01:00
|
|
|
typedef void (*InitializeDSMForeignScan_function) (ForeignScanState *node,
|
2016-06-10 00:02:36 +02:00
|
|
|
ParallelContext *pcxt,
|
|
|
|
void *coordinate);
|
2016-02-03 18:46:18 +01:00
|
|
|
typedef void (*InitializeWorkerForeignScan_function) (ForeignScanState *node,
|
2016-06-10 00:02:36 +02:00
|
|
|
shm_toc *toc,
|
|
|
|
void *coordinate);
|
2016-02-26 11:44:46 +01:00
|
|
|
typedef bool (*IsForeignScanParallelSafe_function) (PlannerInfo *root,
|
|
|
|
RelOptInfo *rel,
|
|
|
|
RangeTblEntry *rte);
|
|
|
|
|
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;
|
|
|
|
|
2016-03-15 01:04:44 +01:00
|
|
|
/* Functions for remote upper-relation (post scan/join) planning */
|
|
|
|
GetForeignUpperPaths_function GetForeignUpperPaths;
|
|
|
|
|
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;
|
2016-03-18 18:48:58 +01:00
|
|
|
PlanDirectModify_function PlanDirectModify;
|
|
|
|
BeginDirectModify_function BeginDirectModify;
|
|
|
|
IterateDirectModify_function IterateDirectModify;
|
|
|
|
EndDirectModify_function EndDirectModify;
|
2013-03-10 19:14:53 +01:00
|
|
|
|
Add support for doing late row locking in FDWs.
Previously, FDWs could only do "early row locking", that is lock a row as
soon as it's fetched, even though local restriction/join conditions might
discard the row later. This patch adds callbacks that allow FDWs to do
late locking in the same way that it's done for regular tables.
To make use of this feature, an FDW must support the "ctid" column as a
unique row identifier. Currently, since ctid has to be of type TID,
the feature is of limited use, though in principle it could be used by
postgres_fdw. We may eventually allow FDWs to specify another data type
for ctid, which would make it possible for more FDWs to use this feature.
This commit does not modify postgres_fdw to use late locking. We've
tested some prototype code for that, but it's not in committable shape,
and besides it's quite unclear whether it actually makes sense to do late
locking against a remote server. The extra round trips required are likely
to outweigh any benefit from improved concurrency.
Etsuro Fujita, reviewed by Ashutosh Bapat, and hacked up a lot by me
2015-05-12 20:10:10 +02:00
|
|
|
/* Functions for SELECT FOR UPDATE/SHARE row locking */
|
|
|
|
GetForeignRowMarkType_function GetForeignRowMarkType;
|
|
|
|
RefetchForeignRow_function RefetchForeignRow;
|
Allow foreign and custom joins to handle EvalPlanQual rechecks.
Commit e7cb7ee14555cc9c5773e2c102efd6371f6f2005 provided basic
infrastructure for allowing a foreign data wrapper or custom scan
provider to replace a join of one or more tables with a scan.
However, this infrastructure failed to take into account the need
for possible EvalPlanQual rechecks, and ExecScanFetch would fail
an assertion (or just overwrite memory) if such a check was attempted
for a plan containing a pushed-down join. To fix, adjust the EPQ
machinery to skip some processing steps when scanrelid == 0, making
those the responsibility of scan's recheck method, which also has
the responsibility in this case of correctly populating the relevant
slot.
To allow foreign scans to gain control in the right place to make
use of this new facility, add a new, optional RecheckForeignScan
method. Also, allow a foreign scan to have a child plan, which can
be used to correctly populate the slot (or perhaps for something
else, but this is the only use currently envisioned).
KaiGai Kohei, reviewed by Robert Haas, Etsuro Fujita, and Kyotaro
Horiguchi.
2015-12-08 18:31:03 +01:00
|
|
|
RecheckForeignScan_function RecheckForeignScan;
|
Add support for doing late row locking in FDWs.
Previously, FDWs could only do "early row locking", that is lock a row as
soon as it's fetched, even though local restriction/join conditions might
discard the row later. This patch adds callbacks that allow FDWs to do
late locking in the same way that it's done for regular tables.
To make use of this feature, an FDW must support the "ctid" column as a
unique row identifier. Currently, since ctid has to be of type TID,
the feature is of limited use, though in principle it could be used by
postgres_fdw. We may eventually allow FDWs to specify another data type
for ctid, which would make it possible for more FDWs to use this feature.
This commit does not modify postgres_fdw to use late locking. We've
tested some prototype code for that, but it's not in committable shape,
and besides it's quite unclear whether it actually makes sense to do late
locking against a remote server. The extra round trips required are likely
to outweigh any benefit from improved concurrency.
Etsuro Fujita, reviewed by Ashutosh Bapat, and hacked up a lot by me
2015-05-12 20:10:10 +02:00
|
|
|
|
2013-03-10 19:14:53 +01:00
|
|
|
/* Support functions for EXPLAIN */
|
|
|
|
ExplainForeignScan_function ExplainForeignScan;
|
|
|
|
ExplainForeignModify_function ExplainForeignModify;
|
2016-03-18 18:48:58 +01:00
|
|
|
ExplainDirectModify_function ExplainDirectModify;
|
2013-03-10 19:14:53 +01:00
|
|
|
|
|
|
|
/* 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;
|
2016-02-03 18:46:18 +01:00
|
|
|
|
|
|
|
/* Support functions for parallelism under Gather node */
|
2016-02-26 11:44:46 +01:00
|
|
|
IsForeignScanParallelSafe_function IsForeignScanParallelSafe;
|
2016-02-03 18:46:18 +01:00
|
|
|
EstimateDSMForeignScan_function EstimateDSMForeignScan;
|
|
|
|
InitializeDSMForeignScan_function InitializeDSMForeignScan;
|
|
|
|
InitializeWorkerForeignScan_function InitializeWorkerForeignScan;
|
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);
|
2016-02-04 23:05:09 +01:00
|
|
|
extern Path *GetExistingLocalJoinPath(RelOptInfo *joinrel);
|
2011-02-20 06:17:18 +01:00
|
|
|
|
|
|
|
#endif /* FDWAPI_H */
|