PostgreSQL Source Code  git master
dest.h File Reference
#include "executor/tuptable.h"
#include "tcop/cmdtag.h"
Include dependency graph for dest.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _DestReceiver
 

Macros

#define COMPLETION_TAG_BUFSIZE   64
 

Typedefs

typedef struct _DestReceiver DestReceiver
 

Enumerations

enum  CommandDest {
  DestNone, DestDebug, DestRemote, DestRemoteExecute,
  DestRemoteSimple, DestSPI, DestTuplestore, DestIntoRel,
  DestCopyOut, DestSQLFunction, DestTransientRel, DestTupleQueue
}
 

Functions

void BeginCommand (CommandTag commandTag, CommandDest dest)
 
DestReceiverCreateDestReceiver (CommandDest dest)
 
void EndCommand (const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output)
 
void NullCommand (CommandDest dest)
 
void ReadyForQuery (CommandDest dest)
 

Variables

PGDLLIMPORT DestReceiverNone_Receiver
 

Macro Definition Documentation

◆ COMPLETION_TAG_BUFSIZE

#define COMPLETION_TAG_BUFSIZE   64

Definition at line 75 of file dest.h.

Referenced by EndCommand().

Typedef Documentation

◆ DestReceiver

typedef struct _DestReceiver DestReceiver

Definition at line 114 of file dest.h.

Enumeration Type Documentation

◆ CommandDest

Enumerator
DestNone 
DestDebug 
DestRemote 
DestRemoteExecute 
DestRemoteSimple 
DestSPI 
DestTuplestore 
DestIntoRel 
DestCopyOut 
DestSQLFunction 
DestTransientRel 
DestTupleQueue 

Definition at line 87 of file dest.h.

88 {
89  DestNone, /* results are discarded */
90  DestDebug, /* results go to debugging output */
91  DestRemote, /* results sent to frontend process */
92  DestRemoteExecute, /* sent to frontend, in Execute command */
93  DestRemoteSimple, /* sent to frontend, w/no catalog access */
94  DestSPI, /* results sent to SPI manager */
95  DestTuplestore, /* results sent to Tuplestore */
96  DestIntoRel, /* results sent to relation (SELECT INTO) */
97  DestCopyOut, /* results sent to COPY TO code */
98  DestSQLFunction, /* results sent to SQL-language func mgr */
99  DestTransientRel, /* results sent to transient relation */
100  DestTupleQueue /* results sent to tuple queue */
101 } CommandDest;
CommandDest
Definition: dest.h:87
Definition: dest.h:94
Definition: dest.h:89
Definition: dest.h:90

Function Documentation

◆ BeginCommand()

void BeginCommand ( CommandTag  commandTag,
CommandDest  dest 
)

Definition at line 103 of file dest.c.

Referenced by exec_execute_message(), and exec_simple_query().

104 {
105  /* Nothing to do at present */
106 }

◆ CreateDestReceiver()

DestReceiver* CreateDestReceiver ( CommandDest  dest)

Definition at line 113 of file dest.c.

References CreateCopyDestReceiver(), CreateIntoRelDestReceiver(), CreateSQLFunctionDestReceiver(), CreateTransientRelDestReceiver(), CreateTupleQueueDestReceiver(), CreateTuplestoreDestReceiver(), DestCopyOut, DestDebug, DestIntoRel, DestNone, DestRemote, DestRemoteExecute, DestRemoteSimple, DestSPI, DestSQLFunction, DestTransientRel, DestTupleQueue, DestTuplestore, InvalidOid, pg_unreachable, printtup_create_DR(), and unconstify.

Referenced by _SPI_execute_plan(), BeginCopy(), CreateReplicationSlot(), exec_execute_message(), exec_replication_command(), exec_simple_query(), execute_sql_string(), FillPortalStore(), IdentifySystem(), PersistHoldablePortal(), postquel_start(), SPI_cursor_fetch(), SPI_scroll_cursor_fetch(), and StartReplication().

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:
123  case DestRemoteExecute:
124  return printtup_create_DR(dest);
125 
126  case DestRemoteSimple:
128 
129  case DestNone:
130  return unconstify(DestReceiver *, &donothingDR);
131 
132  case DestDebug:
133  return unconstify(DestReceiver *, &debugtupDR);
134 
135  case DestSPI:
137 
138  case DestTuplestore:
140 
141  case DestIntoRel:
142  return CreateIntoRelDestReceiver(NULL);
143 
144  case DestCopyOut:
145  return CreateCopyDestReceiver();
146 
147  case DestSQLFunction:
149 
150  case DestTransientRel:
152 
153  case DestTupleQueue:
154  return CreateTupleQueueDestReceiver(NULL);
155  }
156 
157  /* should never get here */
158  pg_unreachable();
159 }
#define pg_unreachable()
Definition: c.h:191
static const DestReceiver debugtupDR
Definition: dest.c:75
Definition: dest.h:94
static const DestReceiver printsimpleDR
Definition: dest.c:80
Definition: dest.h:89
DestReceiver * printtup_create_DR(CommandDest dest)
Definition: printtup.c:78
Definition: dest.h:90
DestReceiver * CreateIntoRelDestReceiver(IntoClause *intoClause)
Definition: createas.c:411
DestReceiver * CreateSQLFunctionDestReceiver(void)
Definition: functions.c:2030
#define unconstify(underlying_type, expr)
Definition: c.h:1206
#define InvalidOid
Definition: postgres_ext.h:36
static const DestReceiver spi_printtupDR
Definition: dest.c:85
DestReceiver * CreateTuplestoreDestReceiver(void)
DestReceiver * CreateTransientRelDestReceiver(Oid transientoid)
Definition: matview.c:430
DestReceiver * CreateCopyDestReceiver(void)
Definition: copy.c:5149
static const DestReceiver donothingDR
Definition: dest.c:70
DestReceiver * CreateTupleQueueDestReceiver(shm_mq_handle *handle)
Definition: tqueue.c:119

◆ EndCommand()

void EndCommand ( const QueryCompletion qc,
CommandDest  dest,
bool  force_undecorated_output 
)

Definition at line 166 of file dest.c.

References command_tag_display_rowcount(), QueryCompletion::commandTag, COMPLETION_TAG_BUFSIZE, DestCopyOut, DestDebug, DestIntoRel, DestNone, DestRemote, DestRemoteExecute, DestRemoteSimple, DestSPI, DestSQLFunction, DestTransientRel, DestTupleQueue, DestTuplestore, GetCommandTagName(), QueryCompletion::nprocessed, pq_putmessage, snprintf, and UINT64_FORMAT.

Referenced by DropReplicationSlot(), exec_execute_message(), exec_replication_command(), exec_simple_query(), StartLogicalReplication(), and WalSndDone().

167 {
168  char completionTag[COMPLETION_TAG_BUFSIZE];
169  CommandTag tag;
170  const char *tagname;
171 
172  switch (dest)
173  {
174  case DestRemote:
175  case DestRemoteExecute:
176  case DestRemoteSimple:
177 
178  /*
179  * We assume the tagname is plain ASCII and therefore requires no
180  * encoding conversion.
181  *
182  * We no longer display LastOid, but to preserve the wire
183  * protocol, we write InvalidOid where the LastOid used to be
184  * written.
185  *
186  * All cases where LastOid was written also write nprocessed
187  * count, so just Assert that rather than having an extra test.
188  */
189  tag = qc->commandTag;
190  tagname = GetCommandTagName(tag);
191 
192  if (command_tag_display_rowcount(tag) && !force_undecorated_output)
193  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
194  tag == CMDTAG_INSERT ?
195  "%s 0 " UINT64_FORMAT : "%s " UINT64_FORMAT,
196  tagname, qc->nprocessed);
197  else
198  snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "%s", tagname);
199  pq_putmessage('C', completionTag, strlen(completionTag) + 1);
200 
201  case DestNone:
202  case DestDebug:
203  case DestSPI:
204  case DestTuplestore:
205  case DestIntoRel:
206  case DestCopyOut:
207  case DestSQLFunction:
208  case DestTransientRel:
209  case DestTupleQueue:
210  break;
211  }
212 }
CommandTag
Definition: cmdtag.h:20
Definition: dest.h:94
uint64 nprocessed
Definition: cmdtag.h:31
Definition: dest.h:89
Definition: dest.h:90
CommandTag commandTag
Definition: cmdtag.h:30
#define COMPLETION_TAG_BUFSIZE
Definition: dest.h:75
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:45
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42
#define snprintf
Definition: port.h:193
#define UINT64_FORMAT
Definition: c.h:410
bool command_tag_display_rowcount(CommandTag commandTag)
Definition: cmdtag.c:51

◆ NullCommand()

void NullCommand ( CommandDest  dest)

Definition at line 227 of file dest.c.

References DestCopyOut, DestDebug, DestIntoRel, DestNone, DestRemote, DestRemoteExecute, DestRemoteSimple, DestSPI, DestSQLFunction, DestTransientRel, DestTupleQueue, DestTuplestore, FrontendProtocol, PG_PROTOCOL_MAJOR, pq_putemptymessage(), and pq_putmessage.

Referenced by exec_execute_message(), and exec_simple_query().

228 {
229  switch (dest)
230  {
231  case DestRemote:
232  case DestRemoteExecute:
233  case DestRemoteSimple:
234 
235  /*
236  * tell the fe that we saw an empty query string. In protocols
237  * before 3.0 this has a useless empty-string message body.
238  */
240  pq_putemptymessage('I');
241  else
242  pq_putmessage('I', "", 1);
243  break;
244 
245  case DestNone:
246  case DestDebug:
247  case DestSPI:
248  case DestTuplestore:
249  case DestIntoRel:
250  case DestCopyOut:
251  case DestSQLFunction:
252  case DestTransientRel:
253  case DestTupleQueue:
254  break;
255  }
256 }
Definition: dest.h:94
void pq_putemptymessage(char msgtype)
Definition: pqformat.c:390
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
Definition: dest.h:89
Definition: dest.h:90
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ ReadyForQuery()

void ReadyForQuery ( CommandDest  dest)

Definition at line 270 of file dest.c.

References buf, DestCopyOut, DestDebug, DestIntoRel, DestNone, DestRemote, DestRemoteExecute, DestRemoteSimple, DestSPI, DestSQLFunction, DestTransientRel, DestTupleQueue, DestTuplestore, FrontendProtocol, PG_PROTOCOL_MAJOR, pq_beginmessage(), pq_endmessage(), pq_flush, pq_putemptymessage(), pq_sendbyte(), and TransactionBlockStatusCode().

Referenced by PostgresMain().

271 {
272  switch (dest)
273  {
274  case DestRemote:
275  case DestRemoteExecute:
276  case DestRemoteSimple:
278  {
280 
281  pq_beginmessage(&buf, 'Z');
283  pq_endmessage(&buf);
284  }
285  else
286  pq_putemptymessage('Z');
287  /* Flush output at end of cycle in any case. */
288  pq_flush();
289  break;
290 
291  case DestNone:
292  case DestDebug:
293  case DestSPI:
294  case DestTuplestore:
295  case DestIntoRel:
296  case DestCopyOut:
297  case DestSQLFunction:
298  case DestTransientRel:
299  case DestTupleQueue:
300  break;
301  }
302 }
#define pq_flush()
Definition: libpq.h:39
Definition: dest.h:94
void pq_putemptymessage(char msgtype)
Definition: pqformat.c:390
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
char TransactionBlockStatusCode(void)
Definition: xact.c:4686
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:87
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
Definition: dest.h:89
static char * buf
Definition: pg_test_fsync.c:67
Definition: dest.h:90
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:298
ProtocolVersion FrontendProtocol
Definition: globals.c:28

Variable Documentation

◆ None_Receiver