PostgreSQL Source Code git master
Loading...
Searching...
No Matches
execAsync.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * execAsync.c
4 * Support routines for asynchronous execution
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/backend/executor/execAsync.c
11 *
12 *-------------------------------------------------------------------------
13 */
14
15#include "postgres.h"
16
17#include "executor/execAsync.h"
18#include "executor/executor.h"
19#include "executor/instrument.h"
20#include "executor/nodeAppend.h"
22
23/*
24 * Asynchronously request a tuple from a designed async-capable node.
25 */
26void
28{
29 if (areq->requestee->chgParam != NULL) /* something changed? */
30 ExecReScan(areq->requestee); /* let ReScan handle this */
31
32 /* must provide our own instrumentation support */
33 if (areq->requestee->instrument)
34 InstrStartNode(areq->requestee->instrument);
35
36 switch (nodeTag(areq->requestee))
37 {
40 break;
41 default:
42 /* If the node doesn't support async, caller messed up. */
43 elog(ERROR, "unrecognized node type: %d",
44 (int) nodeTag(areq->requestee));
45 }
46
48
49 /* must provide our own instrumentation support */
50 if (areq->requestee->instrument)
51 InstrStopNode(areq->requestee->instrument,
52 TupIsNull(areq->result) ? 0.0 : 1.0);
53}
54
55/*
56 * Give the asynchronous node a chance to configure the file descriptor event
57 * for which it wishes to wait. We expect the node-type specific callback to
58 * make a single call of the following form:
59 *
60 * AddWaitEventToSet(set, WL_SOCKET_READABLE, fd, NULL, areq);
61 */
62void
64{
65 /* must provide our own instrumentation support */
66 if (areq->requestee->instrument)
67 InstrStartNode(areq->requestee->instrument);
68
69 switch (nodeTag(areq->requestee))
70 {
73 break;
74 default:
75 /* If the node doesn't support async, caller messed up. */
76 elog(ERROR, "unrecognized node type: %d",
77 (int) nodeTag(areq->requestee));
78 }
79
80 /* must provide our own instrumentation support */
81 if (areq->requestee->instrument)
82 InstrStopNode(areq->requestee->instrument, 0.0);
83}
84
85/*
86 * Call the asynchronous node back when a relevant event has occurred.
87 */
88void
90{
91 /* must provide our own instrumentation support */
92 if (areq->requestee->instrument)
93 InstrStartNode(areq->requestee->instrument);
94
95 switch (nodeTag(areq->requestee))
96 {
99 break;
100 default:
101 /* If the node doesn't support async, caller messed up. */
102 elog(ERROR, "unrecognized node type: %d",
103 (int) nodeTag(areq->requestee));
104 }
105
107
108 /* must provide our own instrumentation support */
109 if (areq->requestee->instrument)
110 InstrStopNode(areq->requestee->instrument,
111 TupIsNull(areq->result) ? 0.0 : 1.0);
112}
113
114/*
115 * Call the requestor back when an asynchronous node has produced a result.
116 */
117void
119{
120 switch (nodeTag(areq->requestor))
121 {
122 case T_AppendState:
124 break;
125 default:
126 /* If the node doesn't support async, caller messed up. */
127 elog(ERROR, "unrecognized node type: %d",
128 (int) nodeTag(areq->requestor));
129 }
130}
131
132/*
133 * A requestee node should call this function to deliver the tuple to its
134 * requestor node. The requestee node can call this from its ExecAsyncRequest
135 * or ExecAsyncNotify callback.
136 */
137void
139{
140 areq->request_complete = true;
141 areq->result = result;
142}
143
144/*
145 * A requestee node should call this function to indicate that it is pending
146 * for a callback. The requestee node can call this from its ExecAsyncRequest
147 * or ExecAsyncNotify callback.
148 */
149void
151{
152 areq->callback_pending = true;
153 areq->request_complete = false;
154 areq->result = NULL;
155}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
void ExecReScan(PlanState *node)
Definition execAmi.c:78
void ExecAsyncResponse(AsyncRequest *areq)
Definition execAsync.c:118
void ExecAsyncRequestPending(AsyncRequest *areq)
Definition execAsync.c:150
void ExecAsyncRequestDone(AsyncRequest *areq, TupleTableSlot *result)
Definition execAsync.c:138
void ExecAsyncRequest(AsyncRequest *areq)
Definition execAsync.c:27
void ExecAsyncConfigureWait(AsyncRequest *areq)
Definition execAsync.c:63
void ExecAsyncNotify(AsyncRequest *areq)
Definition execAsync.c:89
void InstrStartNode(Instrumentation *instr)
Definition instrument.c:68
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition instrument.c:88
void ExecAsyncAppendResponse(AsyncRequest *areq)
void ExecAsyncForeignScanNotify(AsyncRequest *areq)
void ExecAsyncForeignScanConfigureWait(AsyncRequest *areq)
void ExecAsyncForeignScanRequest(AsyncRequest *areq)
#define nodeTag(nodeptr)
Definition nodes.h:139
static int fb(int x)
#define TupIsNull(slot)
Definition tuptable.h:325