32
32
</para>
33
33
34
34
<sect1 id="custom-scan-path">
35
- <title>Implementing Custom Paths</title>
35
+ <title>Creating Custom Scan Paths</title>
36
36
37
37
<para>
38
- A custom scan provider will typically add paths by setting the following
39
- hook, which is called after the core code has generated what it believes
40
- to be the complete and correct set of access paths for the relation.
38
+ A custom scan provider will typically add paths for a base relation by
39
+ setting the following hook, which is called after the core code has
40
+ generated what it believes to be the complete and correct set of access
41
+ paths for the relation.
41
42
<programlisting>
42
43
typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
43
44
RelOptInfo *rel,
@@ -74,37 +75,36 @@ typedef struct CustomPath
74
75
can support mark and restore. Both capabilities are optional.
75
76
<structfield>custom_private</> can be used to store the custom path's
76
77
private data. Private data should be stored in a form that can be handled
77
- by <literal>nodeToString</>, so that debugging routines which attempt to
78
+ by <literal>nodeToString</>, so that debugging routines that attempt to
78
79
print the custom path will work as designed. <structfield>methods</> must
79
80
point to a (usually statically allocated) object implementing the required
80
81
custom path methods, of which there are currently only two, as further
81
82
detailed below.
82
83
</para>
83
84
84
85
<para>
85
- A custom scan provider can also add join paths; in this case, the scan
86
- must produce the same output as would normally be produced by the join
87
- it replaces. To do this, the join provider should set the following hook.
88
- This hook may be invoked repeatedly for the same pair of relations, with
89
- different combinations of inner and outer relations; it is the
90
- responsibility of the hook to minimize duplicated work.
86
+ A custom scan provider can also provide join paths. Just as for base
87
+ relations, such a path must produce the same output as would normally be
88
+ produced by the join it replaces. To do this, the join provider should
89
+ set the following hook, and then within the hook function,
90
+ create <structname>CustomPath</> path(s) for the join relation.
91
91
<programlisting>
92
92
typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root,
93
93
RelOptInfo *joinrel,
94
94
RelOptInfo *outerrel,
95
95
RelOptInfo *innerrel,
96
- List *restrictlist,
97
96
JoinType jointype,
98
- SpecialJoinInfo *sjinfo,
99
- SemiAntiJoinFactors *semifactors,
100
- Relids param_source_rels,
101
- Relids extra_lateral_rels);
97
+ JoinPathExtraData *extra);
102
98
extern PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook;
103
99
</programlisting>
100
+
101
+ This hook will be invoked repeatedly for the same join relation, with
102
+ different combinations of inner and outer relations; it is the
103
+ responsibility of the hook to minimize duplicated work.
104
104
</para>
105
105
106
106
<sect2 id="custom-scan-path-callbacks">
107
- <title>Custom Path Callbacks</title>
107
+ <title>Custom Scan Path Callbacks</title>
108
108
109
109
<para>
110
110
<programlisting>
@@ -125,7 +125,7 @@ void (*TextOutCustomPath) (StringInfo str,
125
125
const CustomPath *node);
126
126
</programlisting>
127
127
Generate additional output when <function>nodeToString</> is invoked on
128
- this custom path. This callback is optional. Since
128
+ this custom path. This callback is optional. Since
129
129
<function>nodeToString</> will automatically dump all fields in the
130
130
structure that it can see, including <structfield>custom_private</>, this
131
131
is only useful if the <structname>CustomPath</> is actually embedded in a
@@ -135,7 +135,7 @@ void (*TextOutCustomPath) (StringInfo str,
135
135
</sect1>
136
136
137
137
<sect1 id="custom-scan-plan">
138
- <title>Implementing Custom Plans</title>
138
+ <title>Creating Custom Scan Plans</title>
139
139
140
140
<para>
141
141
A custom scan is represented in a finished plan tree using the following
@@ -146,9 +146,9 @@ typedef struct CustomScan
146
146
Scan scan;
147
147
uint32 flags;
148
148
List *custom_exprs;
149
- List *custom_ps_tlist;
150
149
List *custom_private;
151
- List *custom_relids;
150
+ List *custom_scan_tlist;
151
+ Bitmapset *custom_relids;
152
152
const CustomScanMethods *methods;
153
153
} CustomScan;
154
154
</programlisting>
@@ -158,49 +158,57 @@ typedef struct CustomScan
158
158
<structfield>scan</> must be initialized as for any other scan, including
159
159
estimated costs, target lists, qualifications, and so on.
160
160
<structfield>flags</> is a bitmask with the same meaning as in
161
- <structname>CustomPath</>. <structfield>custom_exprs</> should be used to
161
+ <structname>CustomPath</>.
162
+ <structfield>custom_exprs</> should be used to
162
163
store expression trees that will need to be fixed up by
163
164
<filename>setrefs.c</> and <filename>subselect.c</>, while
164
- <literal>custom_private</> should be used to store other private data that
165
- is only used by the custom scan provider itself. Plan trees must be able
166
- to be duplicated using <function>copyObject</>, so all the data stored
167
- within these two fields must consist of nodes that function can handle.
168
- <literal>custom_relids</> is set by the core code to the set of relations
169
- which this scan node must handle; except when this scan is replacing a
170
- join, it will have only one member.
165
+ <structfield>custom_private</> should be used to store other private data
166
+ that is only used by the custom scan provider itself.
167
+ <structfield>custom_scan_tlist</> can be NIL when scanning a base
168
+ relation, indicating that the custom scan returns scan tuples that match
169
+ the base relation's rowtype. Otherwise it is a targetlist describing
170
+ the actual scan tuples. <structfield>custom_scan_tlist</> must be
171
+ provided for joins, and could be provided for scans if the custom scan
172
+ provider can compute some non-Var expressions.
173
+ <structfield>custom_relids</> is set by the core code to the set of
174
+ relations (rangetable indexes) that this scan node handles; except when
175
+ this scan is replacing a join, it will have only one member.
171
176
<structfield>methods</> must point to a (usually statically allocated)
172
177
object implementing the required custom scan methods, which are further
173
178
detailed below.
174
179
</para>
175
180
176
181
<para>
177
182
When a <structname>CustomScan</> scans a single relation,
178
- <structfield>scan.scanrelid</> should be the range table index of the table
179
- to be scanned, and <structfield>custom_ps_tlist</> should be
180
- <literal>NULL</>. When it replaces a join, <structfield>scan.scanrelid</>
181
- should be zero, and <structfield>custom_ps_tlist</> should be a list of
182
- <structname>TargetEntry</> nodes. This is necessary because, when a join
183
- is replaced, the target list cannot be constructed from the table
184
- definition. At execution time, this list will be used to initialize the
185
- tuple descriptor of the <structname>TupleTableSlot</>. It will also be
186
- used by <command>EXPLAIN</>, when deparsing.
183
+ <structfield>scan.scanrelid</> must be the range table index of the table
184
+ to be scanned. When it replaces a join, <structfield>scan.scanrelid</>
185
+ should be zero.
186
+ </para>
187
+
188
+ <para>
189
+ Plan trees must be able to be duplicated using <function>copyObject</>,
190
+ so all the data stored within the <quote>custom</> fields must consist of
191
+ nodes that that function can handle. Furthermore, custom scan providers
192
+ cannot substitute a larger structure that embeds
193
+ a <structname>CustomScan</> for the structure itself, as would be possible
194
+ for a <structname>CustomPath</> or <structname>CustomScanState</>.
187
195
</para>
188
196
189
197
<sect2 id="custom-scan-plan-callbacks">
190
- <title>Custom Scan Callbacks</title>
198
+ <title>Custom Scan Plan Callbacks</title>
191
199
<para>
192
200
<programlisting>
193
201
Node *(*CreateCustomScanState) (CustomScan *cscan);
194
202
</programlisting>
195
203
Allocate a <structname>CustomScanState</> for this
196
204
<structname>CustomScan</>. The actual allocation will often be larger than
197
205
required for an ordinary <structname>CustomScanState</>, because many
198
- scan types will wish to embed that as the first field of a large structure.
206
+ providers will wish to embed that as the first field of a larger structure.
199
207
The value returned must have the node tag and <structfield>methods</>
200
- set appropriately, but the other fields need not be initialized at this
208
+ set appropriately, but other fields should be left as zeroes at this
201
209
stage; after <function>ExecInitCustomScan</> performs basic initialization,
202
210
the <function>BeginCustomScan</> callback will be invoked to give the
203
- custom scan state a chance to do whatever else is needed.
211
+ custom scan provider a chance to do whatever else is needed.
204
212
</para>
205
213
206
214
<para>
@@ -209,23 +217,21 @@ void (*TextOutCustomScan) (StringInfo str,
209
217
const CustomScan *node);
210
218
</programlisting>
211
219
Generate additional output when <function>nodeToString</> is invoked on
212
- this custom plan. This callback is optional. Since a
213
- <structname>CustomScan</> must be copyable by <function>copyObject</>,
214
- custom scan providers cannot substitute a larger structure that embeds a
215
- <structname>CustomScan</> for the structure itself, as would be possible
216
- for a <structname>CustomPath</> or <structname>CustomScanState</>.
217
- Therefore, providing this callback is unlikely to be useful.
220
+ this custom plan node. This callback is optional. Since
221
+ <function>nodeToString</> will automatically dump all fields in the
222
+ structure, including the substructure of the <quote>custom</> fields,
223
+ there is usually not much need for this callback.
218
224
</para>
219
225
</sect2>
220
226
</sect1>
221
227
222
- <sect1 id="custom-scan-scan ">
223
- <title>Implementing Custom Scans</title>
228
+ <sect1 id="custom-scan-execution ">
229
+ <title>Executing Custom Scans</title>
224
230
225
231
<para>
226
232
When a <structfield>CustomScan</> is executed, its execution state is
227
233
represented by a <structfield>CustomScanState</>, which is declared as
228
- follows.
234
+ follows:
229
235
<programlisting>
230
236
typedef struct CustomScanState
231
237
{
@@ -237,7 +243,9 @@ typedef struct CustomScanState
237
243
</para>
238
244
239
245
<para>
240
- <structfield>ss</> must be initialized as for any other scanstate;
246
+ <structfield>ss</> is initialized as for any other scanstate,
247
+ except that if the scan is for a join rather than a base relation,
248
+ <literal>ss.ss_currentRelation</> is left NULL.
241
249
<structfield>flags</> is a bitmask with the same meaning as in
242
250
<structname>CustomPath</> and <structname>CustomScan</>.
243
251
<structfield>methods</> must point to a (usually statically allocated)
@@ -247,8 +255,8 @@ typedef struct CustomScanState
247
255
structure embedding the above as its first member.
248
256
</para>
249
257
250
- <sect2 id="custom-scan-scan -callbacks">
251
- <title>Custom Execution-Time Callbacks</title>
258
+ <sect2 id="custom-scan-execution -callbacks">
259
+ <title>Custom Scan Execution Callbacks</title>
252
260
253
261
<para>
254
262
<programlisting>
@@ -257,8 +265,8 @@ void (*BeginCustomScan) (CustomScanState *node,
257
265
int eflags);
258
266
</programlisting>
259
267
Complete initialization of the supplied <structname>CustomScanState</>.
260
- Some initialization is performed by <function>ExecInitCustomScan</>, but
261
- any private fields should be initialized here.
268
+ Standard fields have been initialized by <function>ExecInitCustomScan</>,
269
+ but any private fields should be initialized here.
262
270
</para>
263
271
264
272
<para>
@@ -276,8 +284,8 @@ TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);
276
284
void (*EndCustomScan) (CustomScanState *node);
277
285
</programlisting>
278
286
Clean up any private data associated with the <literal>CustomScanState</>.
279
- This method is required, but may not need to do anything if the associated
280
- data does not exist or will be cleaned up automatically.
287
+ This method is required, but it does not need to do anything if there is
288
+ no associated data or it will be cleaned up automatically.
281
289
</para>
282
290
283
291
<para>
@@ -293,8 +301,8 @@ void (*ReScanCustomScan) (CustomScanState *node);
293
301
void (*MarkPosCustomScan) (CustomScanState *node);
294
302
</programlisting>
295
303
Save the current scan position so that it can subsequently be restored
296
- by the <function>RestrPosCustomScan</> callback. This calback is optional,
297
- and need only be supplied if
304
+ by the <function>RestrPosCustomScan</> callback. This callback is
305
+ optional, and need only be supplied if the
298
306
<literal>CUSTOMPATH_SUPPORT_MARK_RESTORE</> flag is set.
299
307
</para>
300
308
@@ -304,7 +312,7 @@ void (*RestrPosCustomScan) (CustomScanState *node);
304
312
</programlisting>
305
313
Restore the previous scan position as saved by the
306
314
<function>MarkPosCustomScan</> callback. This callback is optional,
307
- and need only be supplied if
315
+ and need only be supplied if the
308
316
<literal>CUSTOMPATH_SUPPORT_MARK_RESTORE</> flag is set.
309
317
</para>
310
318
@@ -314,8 +322,8 @@ void (*ExplainCustomScan) (CustomScanState *node,
314
322
List *ancestors,
315
323
ExplainState *es);
316
324
</programlisting>
317
- Output additional information on <command>EXPLAIN</> that involves
318
- custom-scan node. This callback is optional. Common data stored in the
325
+ Output additional information for <command>EXPLAIN</> of a custom-scan
326
+ plan node. This callback is optional. Common data stored in the
319
327
<structname>ScanState</>, such as the target list and scan relation, will
320
328
be shown even without this callback, but the callback allows the display
321
329
of additional, private state.
0 commit comments