Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita315b96

Browse files
committed
Allow custom and foreign scans to have shutdown callbacks.
This is expected to be useful mostly when performing such scans inparallel, because in that case it allows (in combination with commitacf555b) nodes below a Gather to getcontrol just before the DSM segment goes away.KaiGai Kohei, except that I rewrote the documentation. Reviewed byClaudio Freire.Discussion:http://postgr.es/m/CADyhKSXJK0jUJ8rWv4AmKDhsUh124_rEn39eqgfC5D8fu6xVuw@mail.gmail.com
1 parent285ca26 commita315b96

File tree

9 files changed

+63
-0
lines changed

9 files changed

+63
-0
lines changed

‎doc/src/sgml/custom-scan.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ void (*InitializeWorkerCustomScan) (CustomScanState *node,
340340

341341
<para>
342342
<programlisting>
343+
void (*ShutdownCustomScan) (CustomScanState *node);
344+
</programlisting>
345+
Release resources when it is anticipated the node will not be executed
346+
to completion. This is not called in all cases; sometimes,
347+
<literal>EndCustomScan</> may be called without this function having
348+
been called first. Since the DSM segment used by parallel query is
349+
destroyed just after this callback is invoked, custom scan providers that
350+
wish to take some action before the DSM segment goes away should implement
351+
this method.
352+
</para>
353+
354+
<para>
355+
<programlisting>
343356
void (*ExplainCustomScan) (CustomScanState *node,
344357
List *ancestors,
345358
ExplainState *es);

‎doc/src/sgml/fdwhandler.sgml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,20 @@ InitializeWorkerForeignScan(ForeignScanState *node, shm_toc *toc,
12541254
This callback is optional, and needs only be supplied if this
12551255
custom path supports parallel execution.
12561256
</para>
1257+
1258+
<para>
1259+
<programlisting>
1260+
void
1261+
ShutdownForeignScan(ForeignScanState *node);
1262+
</programlisting>
1263+
Release resources when it is anticipated the node will not be executed
1264+
to completion. This is not called in all cases; sometimes,
1265+
<literal>EndForeignScan</> may be called without this function having
1266+
been called first. Since the DSM segment used by parallel query is
1267+
destroyed just after this callback is invoked, foreign data wrappers that
1268+
wish to take some action before the DSM segment goes away should implement
1269+
this method.
1270+
</para>
12571271
</sect2>
12581272

12591273
</sect1>

‎src/backend/executor/execProcnode.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,12 @@ ExecShutdownNode(PlanState *node)
822822
caseT_GatherState:
823823
ExecShutdownGather((GatherState*)node);
824824
break;
825+
caseT_ForeignScanState:
826+
ExecShutdownForeignScan((ForeignScanState*)node);
827+
break;
828+
caseT_CustomScanState:
829+
ExecShutdownCustomScan((CustomScanState*)node);
830+
break;
825831
default:
826832
break;
827833
}

‎src/backend/executor/nodeCustom.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,12 @@ ExecCustomScanInitializeWorker(CustomScanState *node, shm_toc *toc)
202202
methods->InitializeWorkerCustomScan(node,toc,coordinate);
203203
}
204204
}
205+
206+
void
207+
ExecShutdownCustomScan(CustomScanState*node)
208+
{
209+
constCustomExecMethods*methods=node->methods;
210+
211+
if (methods->ShutdownCustomScan)
212+
methods->ShutdownCustomScan(node);
213+
}

‎src/backend/executor/nodeForeignscan.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,19 @@ ExecForeignScanInitializeWorker(ForeignScanState *node, shm_toc *toc)
353353
fdwroutine->InitializeWorkerForeignScan(node,toc,coordinate);
354354
}
355355
}
356+
357+
/* ----------------------------------------------------------------
358+
*ExecShutdownForeignScan
359+
*
360+
*Gives FDW chance to stop asynchronous resource consumption
361+
*and release any resources still held.
362+
* ----------------------------------------------------------------
363+
*/
364+
void
365+
ExecShutdownForeignScan(ForeignScanState*node)
366+
{
367+
FdwRoutine*fdwroutine=node->fdwroutine;
368+
369+
if (fdwroutine->ShutdownForeignScan)
370+
fdwroutine->ShutdownForeignScan(node);
371+
}

‎src/include/executor/nodeCustom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ extern void ExecCustomScanInitializeDSM(CustomScanState *node,
3737
ParallelContext*pcxt);
3838
externvoidExecCustomScanInitializeWorker(CustomScanState*node,
3939
shm_toc*toc);
40+
externvoidExecShutdownCustomScan(CustomScanState*node);
4041

4142
#endif/* NODECUSTOM_H */

‎src/include/executor/nodeForeignscan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ extern void ExecForeignScanInitializeDSM(ForeignScanState *node,
2828
ParallelContext*pcxt);
2929
externvoidExecForeignScanInitializeWorker(ForeignScanState*node,
3030
shm_toc*toc);
31+
externvoidExecShutdownForeignScan(ForeignScanState*node);
3132

3233
#endif/* NODEFOREIGNSCAN_H */

‎src/include/foreign/fdwapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ typedef void (*InitializeDSMForeignScan_function) (ForeignScanState *node,
151151
typedefvoid (*InitializeWorkerForeignScan_function) (ForeignScanState*node,
152152
shm_toc*toc,
153153
void*coordinate);
154+
typedefvoid (*ShutdownForeignScan_function) (ForeignScanState*node);
154155
typedefbool (*IsForeignScanParallelSafe_function) (PlannerInfo*root,
155156
RelOptInfo*rel,
156157
RangeTblEntry*rte);
@@ -224,6 +225,7 @@ typedef struct FdwRoutine
224225
EstimateDSMForeignScan_functionEstimateDSMForeignScan;
225226
InitializeDSMForeignScan_functionInitializeDSMForeignScan;
226227
InitializeWorkerForeignScan_functionInitializeWorkerForeignScan;
228+
ShutdownForeignScan_functionShutdownForeignScan;
227229
}FdwRoutine;
228230

229231

‎src/include/nodes/extensible.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ typedef struct CustomExecMethods
139139
void(*InitializeWorkerCustomScan) (CustomScanState*node,
140140
shm_toc*toc,
141141
void*coordinate);
142+
void(*ShutdownCustomScan) (CustomScanState*node);
142143

143144
/* Optional: print additional information in EXPLAIN */
144145
void(*ExplainCustomScan) (CustomScanState*node,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp