1 /*-------------------------------------------------------------------------
4 * Definitions for extensible nodes and custom scans
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/nodes/extensible.h
12 *-------------------------------------------------------------------------
17 #include "access/parallel.h"
18 #include "commands/explain.h"
19 #include "nodes/execnodes.h"
20 #include "nodes/pathnodes.h"
21 #include "nodes/plannodes.h"
23 /* maximum length of an extensible node identifier */
24 #define EXTNODENAME_MAX_LEN 64
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.
32 typedef struct ExtensibleNode
34 pg_node_attr(custom_copy_equal
, custom_read_write
)
37 const char *extnodename
; /* identifier of ExtensibleNodeMethods */
41 * node_size is the size of an extensible node of this type in bytes.
43 * nodeCopy is a function which performs a deep copy from oldnode to newnode.
44 * It does not need to copy type or extnodename, which are copied by the
47 * nodeEqual is a function which performs a deep equality comparison between
48 * a and b and returns true or false accordingly. It does not need to compare
49 * type or extnodename, which are compared by the core system.
51 * nodeOut is a serialization function for the node type. It should use the
52 * output conventions typical for outfuncs.c. It does not need to output
53 * type or extnodename; the core system handles those.
55 * nodeRead is a deserialization function for the node type. It does not need
56 * to read type or extnodename; the core system handles those. It should fetch
57 * the next token using pg_strtok() from the current input stream, and then
58 * reconstruct the private fields according to the manner in readfuncs.c.
60 * All callbacks are mandatory.
62 typedef struct ExtensibleNodeMethods
64 const char *extnodename
;
66 void (*nodeCopy
) (struct ExtensibleNode
*newnode
,
67 const struct ExtensibleNode
*oldnode
);
68 bool (*nodeEqual
) (const struct ExtensibleNode
*a
,
69 const struct ExtensibleNode
*b
);
70 void (*nodeOut
) (struct StringInfoData
*str
,
71 const struct ExtensibleNode
*node
);
72 void (*nodeRead
) (struct ExtensibleNode
*node
);
73 } ExtensibleNodeMethods
;
75 extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods
*methods
);
76 extern const ExtensibleNodeMethods
*GetExtensibleNodeMethods(const char *extnodename
,
80 * Flags for custom paths, indicating what capabilities the resulting scan
81 * will have. The flags fields of CustomPath and CustomScan nodes are
82 * bitmasks of these flags.
84 #define CUSTOMPATH_SUPPORT_BACKWARD_SCAN 0x0001
85 #define CUSTOMPATH_SUPPORT_MARK_RESTORE 0x0002
86 #define CUSTOMPATH_SUPPORT_PROJECTION 0x0004
89 * Custom path methods. Mostly, we just need to know how to convert a
90 * CustomPath to a plan.
92 typedef struct CustomPathMethods
94 const char *CustomName
;
96 /* Convert Path to a Plan */
97 struct Plan
*(*PlanCustomPath
) (PlannerInfo
*root
,
99 struct CustomPath
*best_path
,
103 struct List
*(*ReparameterizeCustomPathByChild
) (PlannerInfo
*root
,
104 List
*custom_private
,
105 RelOptInfo
*child_rel
);
109 * Custom scan. Here again, there's not much to do: we need to be able to
110 * generate a ScanState corresponding to the scan.
112 typedef struct CustomScanMethods
114 const char *CustomName
;
116 /* Create execution state (CustomScanState) from a CustomScan plan node */
117 Node
*(*CreateCustomScanState
) (CustomScan
*cscan
);
121 * Execution-time methods for a CustomScanState. This is more complex than
122 * what we need for a custom path or scan.
124 typedef struct CustomExecMethods
126 const char *CustomName
;
128 /* Required executor methods */
129 void (*BeginCustomScan
) (CustomScanState
*node
,
132 TupleTableSlot
*(*ExecCustomScan
) (CustomScanState
*node
);
133 void (*EndCustomScan
) (CustomScanState
*node
);
134 void (*ReScanCustomScan
) (CustomScanState
*node
);
136 /* Optional methods: needed if mark/restore is supported */
137 void (*MarkPosCustomScan
) (CustomScanState
*node
);
138 void (*RestrPosCustomScan
) (CustomScanState
*node
);
140 /* Optional methods: needed if parallel execution is supported */
141 Size (*EstimateDSMCustomScan
) (CustomScanState
*node
,
142 ParallelContext
*pcxt
);
143 void (*InitializeDSMCustomScan
) (CustomScanState
*node
,
144 ParallelContext
*pcxt
,
146 void (*ReInitializeDSMCustomScan
) (CustomScanState
*node
,
147 ParallelContext
*pcxt
,
149 void (*InitializeWorkerCustomScan
) (CustomScanState
*node
,
152 void (*ShutdownCustomScan
) (CustomScanState
*node
);
154 /* Optional: print additional information in EXPLAIN */
155 void (*ExplainCustomScan
) (CustomScanState
*node
,
160 extern void RegisterCustomScanMethods(const CustomScanMethods
*methods
);
161 extern const CustomScanMethods
*GetCustomScanMethods(const char *CustomName
,
164 #endif /* EXTENSIBLE_H */