PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
extensible.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * extensible.h
4  * Definitions for extensible nodes and custom scans
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/nodes/extensible.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef EXTENSIBLE_H
15 #define EXTENSIBLE_H
16 
17 #include "access/parallel.h"
18 #include "commands/explain.h"
19 #include "nodes/execnodes.h"
20 #include "nodes/plannodes.h"
21 #include "nodes/relation.h"
22 
23 /* maximum length of an extensible node identifier */
24 #define EXTNODENAME_MAX_LEN 64
25 
26 /*
27  * An extensible node is a new type of node defined by an extension. The
28  * type is always T_ExtensibleNode, while the extnodename identifies the
29  * specific type of node. extnodename can be looked up to find the
30  * ExtensibleNodeMethods for this node type.
31  */
32 typedef struct ExtensibleNode
33 {
35  const char *extnodename; /* identifier of ExtensibleNodeMethods */
37 
38 /*
39  * node_size is the size of an extensible node of this type in bytes.
40  *
41  * nodeCopy is a function which performs a deep copy from oldnode to newnode.
42  * It does not need to copy type or extnodename, which are copied by the
43  * core system.
44  *
45  * nodeEqual is a function which performs a deep equality comparison between
46  * a and b and returns true or false accordingly. It does not need to compare
47  * type or extnodename, which are compared by the core system.
48  *
49  * nodeOut is a serialization function for the node type. It should use the
50  * output conventions typical for outfuncs.c. It does not need to output
51  * type or extnodename; the core system handles those.
52  *
53  * nodeRead is a deserialization function for the node type. It does not need
54  * to read type or extnodename; the core system handles those. It should fetch
55  * the next token using pg_strtok() from the current input stream, and then
56  * reconstruct the private fields according to the manner in readfuncs.c.
57  *
58  * All callbacks are mandatory.
59  */
60 typedef struct ExtensibleNodeMethods
61 {
62  const char *extnodename;
64  void (*nodeCopy) (struct ExtensibleNode *newnode,
65  const struct ExtensibleNode *oldnode);
66  bool (*nodeEqual) (const struct ExtensibleNode *a,
67  const struct ExtensibleNode *b);
68  void (*nodeOut) (struct StringInfoData *str,
69  const struct ExtensibleNode *node);
70  void (*nodeRead) (struct ExtensibleNode *node);
72 
73 extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods *method);
74 extern const ExtensibleNodeMethods *GetExtensibleNodeMethods(const char *name,
75  bool missing_ok);
76 
77 /*
78  * Flags for custom paths, indicating what capabilities the resulting scan
79  * will have.
80  */
81 #define CUSTOMPATH_SUPPORT_BACKWARD_SCAN 0x0001
82 #define CUSTOMPATH_SUPPORT_MARK_RESTORE 0x0002
83 
84 /*
85  * Custom path methods. Mostly, we just need to know how to convert a
86  * CustomPath to a plan.
87  */
88 typedef struct CustomPathMethods
89 {
90  const char *CustomName;
91 
92  /* Convert Path to a Plan */
93  struct Plan *(*PlanCustomPath) (PlannerInfo *root,
94  RelOptInfo *rel,
95  struct CustomPath *best_path,
96  List *tlist,
97  List *clauses,
98  List *custom_plans);
100 
101 /*
102  * Custom scan. Here again, there's not much to do: we need to be able to
103  * generate a ScanState corresponding to the scan.
104  */
105 typedef struct CustomScanMethods
106 {
107  const char *CustomName;
108 
109  /* Create execution state (CustomScanState) from a CustomScan plan node */
110  Node *(*CreateCustomScanState) (CustomScan *cscan);
112 
113 /*
114  * Execution-time methods for a CustomScanState. This is more complex than
115  * what we need for a custom path or scan.
116  */
117 typedef struct CustomExecMethods
118 {
119  const char *CustomName;
120 
121  /* Required executor methods */
123  EState *estate,
124  int eflags);
125  TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);
128 
129  /* Optional methods: needed if mark/restore is supported */
132 
133  /* Optional methods: needed if parallel execution is supported */
135  ParallelContext *pcxt);
137  ParallelContext *pcxt,
138  void *coordinate);
140  shm_toc *toc,
141  void *coordinate);
143 
144  /* Optional: print additional information in EXPLAIN */
146  List *ancestors,
147  ExplainState *es);
149 
150 extern void RegisterCustomScanMethods(const CustomScanMethods *methods);
151 extern const CustomScanMethods *GetCustomScanMethods(const char *CustomName,
152  bool missing_ok);
153 
154 #endif /* EXTENSIBLE_H */
void(* nodeCopy)(struct ExtensibleNode *newnode, const struct ExtensibleNode *oldnode)
Definition: extensible.h:64
NodeTag type
Definition: extensible.h:34
bool(* nodeEqual)(const struct ExtensibleNode *a, const struct ExtensibleNode *b)
Definition: extensible.h:66
void(* ShutdownCustomScan)(CustomScanState *node)
Definition: extensible.h:142
const char * extnodename
Definition: extensible.h:62
void RegisterCustomScanMethods(const CustomScanMethods *methods)
Definition: extensible.c:88
void(* ExplainCustomScan)(CustomScanState *node, List *ancestors, ExplainState *es)
Definition: extensible.h:145
Definition: nodes.h:509
void(* ReScanCustomScan)(CustomScanState *node)
Definition: extensible.h:127
NodeTag
Definition: nodes.h:26
Size(* EstimateDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt)
Definition: extensible.h:134
char bool
Definition: c.h:202
void(* MarkPosCustomScan)(CustomScanState *node)
Definition: extensible.h:130
void(* EndCustomScan)(CustomScanState *node)
Definition: extensible.h:126
void(* BeginCustomScan)(CustomScanState *node, EState *estate, int eflags)
Definition: extensible.h:122
void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods *method)
Definition: extensible.c:76
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *name, bool missing_ok)
Definition: extensible.c:125
struct ExtensibleNodeMethods ExtensibleNodeMethods
const char * CustomName
Definition: extensible.h:107
struct CustomPathMethods CustomPathMethods
void(* nodeRead)(struct ExtensibleNode *node)
Definition: extensible.h:70
struct ExtensibleNode ExtensibleNode
struct CustomExecMethods CustomExecMethods
void(* nodeOut)(struct StringInfoData *str, const struct ExtensibleNode *node)
Definition: extensible.h:68
const char * extnodename
Definition: extensible.h:35
const char * CustomName
Definition: extensible.h:119
const CustomScanMethods * GetCustomScanMethods(const char *CustomName, bool missing_ok)
Definition: extensible.c:137
const char * CustomName
Definition: extensible.h:90
size_t Size
Definition: c.h:356
const char * name
Definition: encode.c:521
void(* InitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:136
void(* RestrPosCustomScan)(CustomScanState *node)
Definition: extensible.h:131
struct CustomScanMethods CustomScanMethods
Definition: pg_list.h:45
void(* InitializeWorkerCustomScan)(CustomScanState *node, shm_toc *toc, void *coordinate)
Definition: extensible.h:139