PostgreSQL Source Code git master
Loading...
Searching...
No Matches
dest.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * dest.c
4 * support for communication destinations
5 *
6 *
7 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * IDENTIFICATION
11 * src/backend/tcop/dest.c
12 *
13 *-------------------------------------------------------------------------
14 */
15/*
16 * INTERFACE ROUTINES
17 * BeginCommand - initialize the destination at start of command
18 * CreateDestReceiver - create tuple receiver object for destination
19 * EndCommand - clean up the destination at end of command
20 * NullCommand - tell dest that an empty query string was recognized
21 * ReadyForQuery - tell dest that we are ready for a new query
22 *
23 * NOTES
24 * These routines do the appropriate work before and after
25 * tuples are returned by a query to keep the backend and the
26 * "destination" portals synchronized.
27 */
28
29#include "postgres.h"
30
31#include "access/printsimple.h"
32#include "access/printtup.h"
33#include "access/xact.h"
34#include "commands/copy.h"
35#include "commands/createas.h"
36#include "commands/explain_dr.h"
37#include "commands/matview.h"
38#include "executor/functions.h"
39#include "executor/tqueue.h"
41#include "libpq/libpq.h"
42#include "libpq/pqformat.h"
43
44
45/* ----------------
46 * dummy DestReceiver functions
47 * ----------------
48 */
49static bool
51{
52 return true;
53}
54
55static void
59
60static void
62{
63 /* this is used for both shutdown and destroy methods */
64}
65
66/* ----------------
67 * static DestReceiver structs for dest types needing no local state
68 * ----------------
69 */
74
79
84
89
90/*
91 * Globally available receiver for DestNone.
92 *
93 * It's ok to cast the constness away as any modification of the none receiver
94 * would be a bug (which gets easier to catch this way).
95 */
97
98/* ----------------
99 * BeginCommand - initialize the destination at start of command
100 * ----------------
101 */
102void
104{
105 /* Nothing to do at present */
106}
107
108/* ----------------
109 * CreateDestReceiver - return appropriate receiver function set for dest
110 * ----------------
111 */
114{
115 /*
116 * It's ok to cast the constness away as any modification of the none
117 * receiver would be a bug (which gets easier to catch this way).
118 */
119
120 switch (dest)
121 {
122 case DestRemote:
124 return printtup_create_DR(dest);
125
126 case DestRemoteSimple:
128
129 case DestNone:
131
132 case DestDebug:
134
135 case DestSPI:
137
138 case DestTuplestore:
140
141 case DestIntoRel:
143
144 case DestCopyOut:
145 return CreateCopyDestReceiver();
146
147 case DestSQLFunction:
149
150 case DestTransientRel:
152
153 case DestTupleQueue:
155
158 }
159
160 /* should never get here */
162}
163
164/* ----------------
165 * EndCommand - clean up the destination at end of command
166 * ----------------
167 */
168
169void
171 bool force_undecorated_output, bool noblock)
172{
174 Size len;
175
176 switch (dest)
177 {
178 case DestRemote:
180 case DestRemoteSimple:
181
184 if (noblock)
186 else
188 break;
189
190 case DestNone:
191 case DestDebug:
192 case DestSPI:
193 case DestTuplestore:
194 case DestIntoRel:
195 case DestCopyOut:
196 case DestSQLFunction:
197 case DestTransientRel:
198 case DestTupleQueue:
200 break;
201 }
202}
203
204void
209
210/* ----------------
211 * EndReplicationCommand - stripped down version of EndCommand
212 *
213 * For use by replication commands.
214 * ----------------
215 */
216void
217EndReplicationCommand(const char *commandTag)
218{
219 pq_putmessage(PqMsg_CommandComplete, commandTag, strlen(commandTag) + 1);
220}
221
222/* ----------------
223 * NullCommand - tell dest that an empty query string was recognized
224 *
225 * This ensures that there will be a recognizable end to the response
226 * to an Execute message in the extended query protocol.
227 * ----------------
228 */
229void
231{
232 switch (dest)
233 {
234 case DestRemote:
236 case DestRemoteSimple:
237
238 /* Tell the FE that we saw an empty query string */
240 break;
241
242 case DestNone:
243 case DestDebug:
244 case DestSPI:
245 case DestTuplestore:
246 case DestIntoRel:
247 case DestCopyOut:
248 case DestSQLFunction:
249 case DestTransientRel:
250 case DestTupleQueue:
252 break;
253 }
254}
255
256/* ----------------
257 * ReadyForQuery - tell dest that we are ready for a new query
258 *
259 * The ReadyForQuery message is sent so that the FE can tell when
260 * we are done processing a query string.
261 * In versions 3.0 and up, it also carries a transaction state indicator.
262 *
263 * Note that by flushing the stdio buffer here, we can avoid doing it
264 * most other places and thus reduce the number of separate packets sent.
265 * ----------------
266 */
267void
269{
270 switch (dest)
271 {
272 case DestRemote:
274 case DestRemoteSimple:
275 {
277
281 }
282 /* Flush output at end of cycle in any case. */
283 pq_flush();
284 break;
285
286 case DestNone:
287 case DestDebug:
288 case DestSPI:
289 case DestTuplestore:
290 case DestIntoRel:
291 case DestCopyOut:
292 case DestSQLFunction:
293 case DestTransientRel:
294 case DestTupleQueue:
296 break;
297 }
298}
#define unconstify(underlying_type, expr)
Definition c.h:1325
#define pg_unreachable()
Definition c.h:367
size_t Size
Definition c.h:689
Size BuildQueryCompletionString(char *buff, const QueryCompletion *qc, bool nameonly)
Definition cmdtag.c:121
#define COMPLETION_TAG_BUFSIZE
Definition cmdtag.h:17
CommandTag
Definition cmdtag.h:23
DestReceiver * CreateCopyDestReceiver(void)
Definition copyto.c:1709
DestReceiver * CreateIntoRelDestReceiver(IntoClause *intoClause)
Definition createas.c:440
static DataChecksumsWorkerOperation operation
void EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output)
Definition dest.c:205
static const DestReceiver spi_printtupDR
Definition dest.c:85
DestReceiver * CreateDestReceiver(CommandDest dest)
Definition dest.c:113
void EndCommandExtended(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output, bool noblock)
Definition dest.c:170
static void donothingStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition dest.c:56
static void donothingCleanup(DestReceiver *self)
Definition dest.c:61
void BeginCommand(CommandTag commandTag, CommandDest dest)
Definition dest.c:103
static const DestReceiver debugtupDR
Definition dest.c:75
static const DestReceiver donothingDR
Definition dest.c:70
void ReadyForQuery(CommandDest dest)
Definition dest.c:268
static bool donothingReceive(TupleTableSlot *slot, DestReceiver *self)
Definition dest.c:50
void EndReplicationCommand(const char *commandTag)
Definition dest.c:217
DestReceiver * None_Receiver
Definition dest.c:96
static const DestReceiver printsimpleDR
Definition dest.c:80
void NullCommand(CommandDest dest)
Definition dest.c:230
CommandDest
Definition dest.h:86
@ DestSQLFunction
Definition dest.h:96
@ DestTupleQueue
Definition dest.h:98
@ DestTuplestore
Definition dest.h:93
@ DestRemote
Definition dest.h:89
@ DestDebug
Definition dest.h:88
@ DestExplainSerialize
Definition dest.h:99
@ DestRemoteSimple
Definition dest.h:91
@ DestCopyOut
Definition dest.h:95
@ DestTransientRel
Definition dest.h:97
@ DestSPI
Definition dest.h:92
@ DestIntoRel
Definition dest.h:94
@ DestRemoteExecute
Definition dest.h:90
@ DestNone
Definition dest.h:87
DestReceiver * CreateExplainSerializeDestReceiver(ExplainState *es)
Definition explain_dr.c:275
DestReceiver * CreateSQLFunctionDestReceiver(void)
Definition functions.c:2618
#define pq_flush()
Definition libpq.h:49
#define pq_putmessage(msgtype, s, len)
Definition libpq.h:52
#define pq_putmessage_noblock(msgtype, s, len)
Definition libpq.h:54
DestReceiver * CreateTransientRelDestReceiver(Oid transientoid)
Definition matview.c:464
const void size_t len
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define InvalidOid
void pq_putemptymessage(char msgtype)
Definition pqformat.c:387
void pq_endmessage(StringInfo buf)
Definition pqformat.c:296
void pq_beginmessage(StringInfo buf, char msgtype)
Definition pqformat.c:88
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition pqformat.h:160
static int fb(int x)
void printsimple_startup(DestReceiver *self, int operation, TupleDesc tupdesc)
Definition printsimple.c:32
bool printsimple(TupleTableSlot *slot, DestReceiver *self)
Definition printsimple.c:60
bool debugtup(TupleTableSlot *slot, DestReceiver *self)
Definition printtup.c:463
void debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition printtup.c:445
DestReceiver * printtup_create_DR(CommandDest dest)
Definition printtup.c:72
#define PqMsg_ReadyForQuery
Definition protocol.h:55
#define PqMsg_EmptyQueryResponse
Definition protocol.h:47
#define PqMsg_CommandComplete
Definition protocol.h:42
bool spi_printtup(TupleTableSlot *slot, DestReceiver *self)
Definition spi.c:2171
void spi_dest_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition spi.c:2124
DestReceiver * CreateTupleQueueDestReceiver(shm_mq_handle *handle)
Definition tqueue.c:119
DestReceiver * CreateTuplestoreDestReceiver(void)
char TransactionBlockStatusCode(void)
Definition xact.c:5054