diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/executor/executor.h | 3 | ||||
-rw-r--r-- | src/include/executor/nodeCustom.h | 30 | ||||
-rw-r--r-- | src/include/nodes/execnodes.h | 40 | ||||
-rw-r--r-- | src/include/nodes/nodes.h | 3 | ||||
-rw-r--r-- | src/include/nodes/plannodes.h | 29 | ||||
-rw-r--r-- | src/include/nodes/relation.h | 42 | ||||
-rw-r--r-- | src/include/optimizer/pathnode.h | 9 | ||||
-rw-r--r-- | src/include/optimizer/planmain.h | 3 |
8 files changed, 158 insertions, 1 deletions
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index d167b496fce..a44b4cde0fa 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -16,6 +16,7 @@ #include "executor/execdesc.h" #include "nodes/parsenodes.h" +#include "nodes/relation.h" #include "utils/lockwaitpolicy.h" @@ -103,7 +104,7 @@ extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook; extern void ExecReScan(PlanState *node); extern void ExecMarkPos(PlanState *node); extern void ExecRestrPos(PlanState *node); -extern bool ExecSupportsMarkRestore(NodeTag plantype); +extern bool ExecSupportsMarkRestore(Path *pathnode); extern bool ExecSupportsBackwardScan(Plan *node); extern bool ExecMaterializesOutput(NodeTag plantype); diff --git a/src/include/executor/nodeCustom.h b/src/include/executor/nodeCustom.h new file mode 100644 index 00000000000..1736d48bfaf --- /dev/null +++ b/src/include/executor/nodeCustom.h @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------ + * + * nodeCustom.h + * + * prototypes for CustomScan nodes + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * ------------------------------------------------------------------------ + */ +#ifndef NODECUSTOM_H +#define NODECUSTOM_H +#include "nodes/plannodes.h" +#include "nodes/execnodes.h" + +/* + * General executor code + */ +extern CustomScanState *ExecInitCustomScan(CustomScan *custom_scan, + EState *estate, int eflags); +extern TupleTableSlot *ExecCustomScan(CustomScanState *node); +extern Node *MultiExecCustomScan(CustomScanState *node); +extern void ExecEndCustomScan(CustomScanState *node); + +extern void ExecReScanCustomScan(CustomScanState *node); +extern void ExecCustomMarkPos(CustomScanState *node); +extern void ExecCustomRestrPos(CustomScanState *node); + +#endif /* NODECUSTOM_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 39d2c10bdfe..b72e605e4fe 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -19,6 +19,7 @@ #include "executor/instrument.h" #include "nodes/params.h" #include "nodes/plannodes.h" +#include "nodes/relation.h" #include "utils/reltrigger.h" #include "utils/sortsupport.h" #include "utils/tuplestore.h" @@ -1504,6 +1505,45 @@ typedef struct ForeignScanState void *fdw_state; /* foreign-data wrapper can keep state here */ } ForeignScanState; +/* ---------------- + * CustomScanState information + * + * CustomScan nodes are used to execute custom code within executor. + * ---------------- + */ +struct CustomExecMethods; +struct ExplainState; /* to avoid to include explain.h here */ + +typedef struct CustomScanState +{ + ScanState ss; + uint32 flags; /* mask of CUSTOMPATH_* flags defined in relation.h*/ + const struct CustomExecMethods *methods; +} CustomScanState; + +typedef struct CustomExecMethods +{ + const char *CustomName; + + /* EXECUTOR methods */ + void (*BeginCustomScan)(CustomScanState *node, + EState *estate, + int eflags); + TupleTableSlot *(*ExecCustomScan)(CustomScanState *node); + void (*EndCustomScan)(CustomScanState *node); + void (*ReScanCustomScan)(CustomScanState *node); + void (*MarkPosCustomScan)(CustomScanState *node); + void (*RestrPosCustomScan)(CustomScanState *node); + + /* EXPLAIN support */ + void (*ExplainCustomScan)(CustomScanState *node, + List *ancestors, + struct ExplainState *es); + Node *(*GetSpecialCustomVar)(CustomScanState *node, + Var *varnode, + PlanState **child_ps); +} CustomExecMethods; + /* ---------------------------------------------------------------- * Join State Information * ---------------------------------------------------------------- diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index 154d943d581..bc71fea78d0 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -62,6 +62,7 @@ typedef enum NodeTag T_CteScan, T_WorkTableScan, T_ForeignScan, + T_CustomScan, T_Join, T_NestLoop, T_MergeJoin, @@ -107,6 +108,7 @@ typedef enum NodeTag T_CteScanState, T_WorkTableScanState, T_ForeignScanState, + T_CustomScanState, T_JoinState, T_NestLoopState, T_MergeJoinState, @@ -224,6 +226,7 @@ typedef enum NodeTag T_HashPath, T_TidPath, T_ForeignPath, + T_CustomPath, T_AppendPath, T_MergeAppendPath, T_ResultPath, diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index fb02390da51..9dbb91cb90d 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -15,8 +15,10 @@ #define PLANNODES_H #include "access/sdir.h" +#include "lib/stringinfo.h" #include "nodes/bitmapset.h" #include "nodes/primnodes.h" +#include "nodes/relation.h" #include "utils/lockwaitpolicy.h" @@ -483,6 +485,33 @@ typedef struct ForeignScan bool fsSystemCol; /* true if any "system column" is needed */ } ForeignScan; +/* ---------------- + * CustomScan node + * ---------------- + */ +struct CustomScanMethods; + +typedef struct CustomScan +{ + Scan scan; + uint32 flags; /* mask of CUSTOMPATH_* flags defined in relation.h */ + struct CustomScanMethods *methods; +} CustomScan; + +typedef struct CustomScanMethods +{ + const char *CustomName; + void (*SetCustomScanRef)(struct PlannerInfo *root, + CustomScan *cscan, + int rtoffset); + void (*FinalizeCustomScan)(struct PlannerInfo *root, + CustomScan *cscan, + bool (*finalize_primnode)(), + void *finalize_context); + Node *(*CreateCustomScanState)(CustomScan *cscan); + void (*TextOutCustomScan)(StringInfo str, const CustomScan *node); + CustomScan *(*CopyCustomScan)(const CustomScan *from); +} CustomScanMethods; /* * ========== diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index f1a0504c0d4..05cfbcd2aa1 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -15,6 +15,7 @@ #define RELATION_H #include "access/sdir.h" +#include "lib/stringinfo.h" #include "nodes/params.h" #include "nodes/parsenodes.h" #include "storage/block.h" @@ -884,6 +885,47 @@ typedef struct ForeignPath } ForeignPath; /* + * CustomPath represents a scan by some out-of-core extension. + * + * We provide a set of hooks here - which the provider must take care to + * set up correctly - to allow extensions to supply their own methods of + * scanning a relation. For example, a provider might provide GPU + * acceleration, a cache-based scan, or some other kind of logic we haven't + * dreamed up yet. + * + * Core code should avoid assuming that the CustomPath is only as large as + * the structure declared here; providers are expected to make it the first + * element in a larger structure. + */ + +struct CustomPathMethods; +struct Plan; /* not to include plannodes.h here */ + +#define CUSTOMPATH_SUPPORT_BACKWARD_SCAN 0x0001 +#define CUSTOMPATH_SUPPORT_MARK_RESTORE 0x0002 + +typedef struct CustomPath +{ + Path path; + uint32 flags; + const struct CustomPathMethods *methods; +} CustomPath; + +typedef struct CustomPathMethods +{ + const char *CustomName; + void (*CreateCustomScanPath)(PlannerInfo *root, + RelOptInfo *baserel, + RangeTblEntry *rte); + struct Plan *(*PlanCustomPath)(PlannerInfo *root, + RelOptInfo *rel, + CustomPath *best_path, + List *tlist, + List *clauses); + void (*TextOutCustomPath)(StringInfo str, const CustomPath *node); +} CustomPathMethods; + +/* * AppendPath represents an Append plan, ie, successive execution of * several member plans. * diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index 26b17f5f7af..2b67ae6187b 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -129,6 +129,15 @@ extern Path *reparameterize_path(PlannerInfo *root, Path *path, double loop_count); /* + * Interface definition of custom-scan providers + */ +extern void register_custom_path_provider(CustomPathMethods *cpp_methods); + +extern void create_customscan_paths(PlannerInfo *root, + RelOptInfo *baserel, + RangeTblEntry *rte); + +/* * prototypes for relnode.c */ extern void setup_simple_rel_arrays(PlannerInfo *root); diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 3fdc2cba0ed..c97c5777a07 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -86,6 +86,7 @@ extern ModifyTable *make_modifytable(PlannerInfo *root, List *withCheckOptionLists, List *returningLists, List *rowMarks, int epqParam); extern bool is_projection_capable_plan(Plan *plan); +extern Node *replace_nestloop_params(PlannerInfo *root, Node *expr); /* * prototypes for plan/initsplan.c @@ -130,6 +131,8 @@ extern bool query_is_distinct_for(Query *query, List *colnos, List *opids); */ extern Plan *set_plan_references(PlannerInfo *root, Plan *plan); extern void fix_opfuncids(Node *node); +extern Node *fix_scan_expr(PlannerInfo *root, Node *node, int rtoffset); +extern void fix_expr_common(PlannerInfo *root, Node *node); extern void set_opfuncid(OpExpr *opexpr); extern void set_sa_opfuncid(ScalarArrayOpExpr *opexpr); extern void record_plan_function_dependency(PlannerInfo *root, Oid funcid); |