PostgreSQL Source Code  git master
dest.c File Reference
#include "postgres.h"
#include "access/printsimple.h"
#include "access/printtup.h"
#include "access/xact.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/matview.h"
#include "executor/functions.h"
#include "executor/tqueue.h"
#include "executor/tstoreReceiver.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "utils/portal.h"
Include dependency graph for dest.c:

Go to the source code of this file.

Functions

static bool donothingReceive (TupleTableSlot *slot, DestReceiver *self)
 
static void donothingStartup (DestReceiver *self, int operation, TupleDesc typeinfo)
 
static void donothingCleanup (DestReceiver *self)
 
void BeginCommand (CommandTag commandTag, CommandDest dest)
 
DestReceiverCreateDestReceiver (CommandDest dest)
 
void EndCommand (const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output)
 
void EndReplicationCommand (const char *commandTag)
 
void NullCommand (CommandDest dest)
 
void ReadyForQuery (CommandDest dest)
 

Variables

static const DestReceiver donothingDR
 
static const DestReceiver debugtupDR
 
static const DestReceiver printsimpleDR
 
static const DestReceiver spi_printtupDR
 
DestReceiverNone_Receiver = (DestReceiver *) &donothingDR
 

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(), exec_stmt_return_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:1183
#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:5201
static const DestReceiver donothingDR
Definition: dest.c:70
DestReceiver * CreateTupleQueueDestReceiver(shm_mq_handle *handle)
Definition: tqueue.c:119

◆ donothingCleanup()

static void donothingCleanup ( DestReceiver self)
static

Definition at line 61 of file dest.c.

62 {
63  /* this is used for both shutdown and destroy methods */
64 }

◆ donothingReceive()

static bool donothingReceive ( TupleTableSlot slot,
DestReceiver self 
)
static

Definition at line 50 of file dest.c.

51 {
52  return true;
53 }

◆ donothingStartup()

static void donothingStartup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)
static

Definition at line 56 of file dest.c.

57 {
58 }

◆ 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 exec_execute_message(), 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:417
bool command_tag_display_rowcount(CommandTag commandTag)
Definition: cmdtag.c:51

◆ EndReplicationCommand()

void EndReplicationCommand ( const char *  commandTag)

Definition at line 221 of file dest.c.

References pq_putmessage.

Referenced by exec_replication_command(), and StartReplication().

222 {
223  pq_putmessage('C', commandTag, strlen(commandTag) + 1);
224 }
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42

◆ NullCommand()

void NullCommand ( CommandDest  dest)

Definition at line 239 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().

240 {
241  switch (dest)
242  {
243  case DestRemote:
244  case DestRemoteExecute:
245  case DestRemoteSimple:
246 
247  /*
248  * tell the fe that we saw an empty query string. In protocols
249  * before 3.0 this has a useless empty-string message body.
250  */
252  pq_putemptymessage('I');
253  else
254  pq_putmessage('I', "", 1);
255  break;
256 
257  case DestNone:
258  case DestDebug:
259  case DestSPI:
260  case DestTuplestore:
261  case DestIntoRel:
262  case DestCopyOut:
263  case DestSQLFunction:
264  case DestTransientRel:
265  case DestTupleQueue:
266  break;
267  }
268 }
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 282 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().

283 {
284  switch (dest)
285  {
286  case DestRemote:
287  case DestRemoteExecute:
288  case DestRemoteSimple:
290  {
292 
293  pq_beginmessage(&buf, 'Z');
295  pq_endmessage(&buf);
296  }
297  else
298  pq_putemptymessage('Z');
299  /* Flush output at end of cycle in any case. */
300  pq_flush();
301  break;
302 
303  case DestNone:
304  case DestDebug:
305  case DestSPI:
306  case DestTuplestore:
307  case DestIntoRel:
308  case DestCopyOut:
309  case DestSQLFunction:
310  case DestTransientRel:
311  case DestTupleQueue:
312  break;
313  }
314 }
#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:4716
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

◆ debugtupDR

const DestReceiver debugtupDR
static
Initial value:
= {
}
Definition: dest.h:90
bool debugtup(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:614
void debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: printtup.c:596
static void donothingCleanup(DestReceiver *self)
Definition: dest.c:61

Definition at line 75 of file dest.c.

◆ donothingDR

const DestReceiver donothingDR
static
Initial value:
= {
}
static bool donothingReceive(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.c:50
Definition: dest.h:89
static void donothingStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: dest.c:56
static void donothingCleanup(DestReceiver *self)
Definition: dest.c:61

Definition at line 70 of file dest.c.

◆ None_Receiver

◆ printsimpleDR

const DestReceiver printsimpleDR
static
Initial value:
= {
}
bool printsimple(TupleTableSlot *slot, DestReceiver *self)
Definition: printsimple.c:58
void printsimple_startup(DestReceiver *self, int operation, TupleDesc tupdesc)
Definition: printsimple.c:30
static void donothingCleanup(DestReceiver *self)
Definition: dest.c:61

Definition at line 80 of file dest.c.

◆ spi_printtupDR

const DestReceiver spi_printtupDR
static
Initial value:
= {
}
Definition: dest.h:94
void spi_dest_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: spi.c:1951
static void donothingCleanup(DestReceiver *self)
Definition: dest.c:61
bool spi_printtup(TupleTableSlot *slot, DestReceiver *self)
Definition: spi.c:1999

Definition at line 85 of file dest.c.