PostgreSQL Source Code  git master
printtup.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * printtup.c
4  * Routines to print out tuples to the destination (both frontend
5  * clients and standalone backends are supported here).
6  *
7  *
8  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * IDENTIFICATION
12  * src/backend/access/common/printtup.c
13  *
14  *-------------------------------------------------------------------------
15  */
16 #include "postgres.h"
17 
18 #include "access/printtup.h"
19 #include "libpq/libpq.h"
20 #include "libpq/pqformat.h"
21 #include "tcop/pquery.h"
22 #include "utils/lsyscache.h"
23 #include "utils/memdebug.h"
24 #include "utils/memutils.h"
25 
26 
27 static void printtup_startup(DestReceiver *self, int operation,
28  TupleDesc typeinfo);
29 static bool printtup(TupleTableSlot *slot, DestReceiver *self);
30 static bool printtup_20(TupleTableSlot *slot, DestReceiver *self);
31 static bool printtup_internal_20(TupleTableSlot *slot, DestReceiver *self);
32 static void printtup_shutdown(DestReceiver *self);
33 static void printtup_destroy(DestReceiver *self);
34 
35 static void SendRowDescriptionCols_2(StringInfo buf, TupleDesc typeinfo,
36  List *targetlist, int16 *formats);
37 static void SendRowDescriptionCols_3(StringInfo buf, TupleDesc typeinfo,
38  List *targetlist, int16 *formats);
39 
40 /* ----------------------------------------------------------------
41  * printtup / debugtup support
42  * ----------------------------------------------------------------
43  */
44 
45 /* ----------------
46  * Private state for a printtup destination object
47  *
48  * NOTE: finfo is the lookup info for either typoutput or typsend, whichever
49  * we are using for this column.
50  * ----------------
51  */
52 typedef struct
53 { /* Per-attribute information */
54  Oid typoutput; /* Oid for the type's text output fn */
55  Oid typsend; /* Oid for the type's binary output fn */
56  bool typisvarlena; /* is it varlena (ie possibly toastable)? */
57  int16 format; /* format code for this column */
58  FmgrInfo finfo; /* Precomputed call info for output fn */
60 
61 typedef struct
62 {
63  DestReceiver pub; /* publicly-known function pointers */
64  StringInfoData buf; /* output buffer */
65  Portal portal; /* the Portal we are printing from */
66  bool sendDescrip; /* send RowDescription at startup? */
67  TupleDesc attrinfo; /* The attr info we are set up for */
68  int nattrs;
69  PrinttupAttrInfo *myinfo; /* Cached info about each attr */
70  MemoryContext tmpcontext; /* Memory context for per-row workspace */
71 } DR_printtup;
72 
73 /* ----------------
74  * Initialize: create a DestReceiver for printtup
75  * ----------------
76  */
79 {
80  DR_printtup *self = (DR_printtup *) palloc0(sizeof(DR_printtup));
81 
82  self->pub.receiveSlot = printtup; /* might get changed later */
83  self->pub.rStartup = printtup_startup;
84  self->pub.rShutdown = printtup_shutdown;
85  self->pub.rDestroy = printtup_destroy;
86  self->pub.mydest = dest;
87 
88  /*
89  * Send T message automatically if DestRemote, but not if
90  * DestRemoteExecute
91  */
92  self->sendDescrip = (dest == DestRemote);
93 
94  self->attrinfo = NULL;
95  self->nattrs = 0;
96  self->myinfo = NULL;
97  self->tmpcontext = NULL;
98 
99  return (DestReceiver *) self;
100 }
101 
102 /*
103  * Set parameters for a DestRemote (or DestRemoteExecute) receiver
104  */
105 void
107 {
108  DR_printtup *myState = (DR_printtup *) self;
109 
110  Assert(myState->pub.mydest == DestRemote ||
111  myState->pub.mydest == DestRemoteExecute);
112 
113  myState->portal = portal;
114 
116  {
117  /*
118  * In protocol 2.0 the Bind message does not exist, so there is no way
119  * for the columns to have different print formats; it's sufficient to
120  * look at the first one.
121  */
122  if (portal->formats && portal->formats[0] != 0)
124  else
125  myState->pub.receiveSlot = printtup_20;
126  }
127 }
128 
129 static void
130 printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
131 {
132  DR_printtup *myState = (DR_printtup *) self;
133  Portal portal = myState->portal;
134 
135  /* create buffer to be used for all messages */
136  initStringInfo(&myState->buf);
137 
138  /*
139  * Create a temporary memory context that we can reset once per row to
140  * recover palloc'd memory. This avoids any problems with leaks inside
141  * datatype output routines, and should be faster than retail pfree's
142  * anyway.
143  */
145  "printtup",
147 
149  {
150  /*
151  * Send portal name to frontend (obsolete cruft, gone in proto 3.0)
152  *
153  * If portal name not specified, use "blank" portal.
154  */
155  const char *portalName = portal->name;
156 
157  if (portalName == NULL || portalName[0] == '\0')
158  portalName = "blank";
159 
160  pq_puttextmessage('P', portalName);
161  }
162 
163  /*
164  * If we are supposed to emit row descriptions, then send the tuple
165  * descriptor of the tuples.
166  */
167  if (myState->sendDescrip)
168  SendRowDescriptionMessage(&myState->buf,
169  typeinfo,
170  FetchPortalTargetList(portal),
171  portal->formats);
172 
173  /* ----------------
174  * We could set up the derived attr info at this time, but we postpone it
175  * until the first call of printtup, for 2 reasons:
176  * 1. We don't waste time (compared to the old way) if there are no
177  * tuples at all to output.
178  * 2. Checking in printtup allows us to handle the case that the tuples
179  * change type midway through (although this probably can't happen in
180  * the current executor).
181  * ----------------
182  */
183 }
184 
185 /*
186  * SendRowDescriptionMessage --- send a RowDescription message to the frontend
187  *
188  * Notes: the TupleDesc has typically been manufactured by ExecTypeFromTL()
189  * or some similar function; it does not contain a full set of fields.
190  * The targetlist will be NIL when executing a utility function that does
191  * not have a plan. If the targetlist isn't NIL then it is a Query node's
192  * targetlist; it is up to us to ignore resjunk columns in it. The formats[]
193  * array pointer might be NULL (if we are doing Describe on a prepared stmt);
194  * send zeroes for the format codes in that case.
195  */
196 void
198  List *targetlist, int16 *formats)
199 {
200  int natts = typeinfo->natts;
201  int proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
202 
203  /* tuple descriptor message type */
204  pq_beginmessage_reuse(buf, 'T');
205  /* # of attrs in tuples */
206  pq_sendint16(buf, natts);
207 
208  if (proto >= 3)
209  SendRowDescriptionCols_3(buf, typeinfo, targetlist, formats);
210  else
211  SendRowDescriptionCols_2(buf, typeinfo, targetlist, formats);
212 
213  pq_endmessage_reuse(buf);
214 }
215 
216 /*
217  * Send description for each column when using v3+ protocol
218  */
219 static void
220 SendRowDescriptionCols_3(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
221 {
222  int natts = typeinfo->natts;
223  int i;
224  ListCell *tlist_item = list_head(targetlist);
225 
226  /*
227  * Preallocate memory for the entire message to be sent. That allows to
228  * use the significantly faster inline pqformat.h functions and to avoid
229  * reallocations.
230  *
231  * Have to overestimate the size of the column-names, to account for
232  * character set overhead.
233  */
235  + sizeof(Oid) /* resorigtbl */
236  + sizeof(AttrNumber) /* resorigcol */
237  + sizeof(Oid) /* atttypid */
238  + sizeof(int16) /* attlen */
239  + sizeof(int32) /* attypmod */
240  + sizeof(int16) /* format */
241  ) * natts);
242 
243  for (i = 0; i < natts; ++i)
244  {
245  Form_pg_attribute att = TupleDescAttr(typeinfo, i);
246  Oid atttypid = att->atttypid;
247  int32 atttypmod = att->atttypmod;
248  Oid resorigtbl;
249  AttrNumber resorigcol;
250  int16 format;
251 
252  /*
253  * If column is a domain, send the base type and typmod instead.
254  * Lookup before sending any ints, for efficiency.
255  */
256  atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
257 
258  /* Do we have a non-resjunk tlist item? */
259  while (tlist_item &&
260  ((TargetEntry *) lfirst(tlist_item))->resjunk)
261  tlist_item = lnext(tlist_item);
262  if (tlist_item)
263  {
264  TargetEntry *tle = (TargetEntry *) lfirst(tlist_item);
265 
266  resorigtbl = tle->resorigtbl;
267  resorigcol = tle->resorigcol;
268  tlist_item = lnext(tlist_item);
269  }
270  else
271  {
272  /* No info available, so send zeroes */
273  resorigtbl = 0;
274  resorigcol = 0;
275  }
276 
277  if (formats)
278  format = formats[i];
279  else
280  format = 0;
281 
282  pq_writestring(buf, NameStr(att->attname));
283  pq_writeint32(buf, resorigtbl);
284  pq_writeint16(buf, resorigcol);
285  pq_writeint32(buf, atttypid);
286  pq_writeint16(buf, att->attlen);
287  pq_writeint32(buf, atttypmod);
288  pq_writeint16(buf, format);
289  }
290 }
291 
292 /*
293  * Send description for each column when using v2 protocol
294  */
295 static void
296 SendRowDescriptionCols_2(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
297 {
298  int natts = typeinfo->natts;
299  int i;
300 
301  for (i = 0; i < natts; ++i)
302  {
303  Form_pg_attribute att = TupleDescAttr(typeinfo, i);
304  Oid atttypid = att->atttypid;
305  int32 atttypmod = att->atttypmod;
306 
307  /* If column is a domain, send the base type and typmod instead */
308  atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
309 
310  pq_sendstring(buf, NameStr(att->attname));
311  /* column ID only info appears in protocol 3.0 and up */
312  pq_sendint32(buf, atttypid);
313  pq_sendint16(buf, att->attlen);
314  pq_sendint32(buf, atttypmod);
315  /* format info only appears in protocol 3.0 and up */
316  }
317 }
318 
319 /*
320  * Get the lookup info that printtup() needs
321  */
322 static void
323 printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
324 {
325  int16 *formats = myState->portal->formats;
326  int i;
327 
328  /* get rid of any old data */
329  if (myState->myinfo)
330  pfree(myState->myinfo);
331  myState->myinfo = NULL;
332 
333  myState->attrinfo = typeinfo;
334  myState->nattrs = numAttrs;
335  if (numAttrs <= 0)
336  return;
337 
338  myState->myinfo = (PrinttupAttrInfo *)
339  palloc0(numAttrs * sizeof(PrinttupAttrInfo));
340 
341  for (i = 0; i < numAttrs; i++)
342  {
343  PrinttupAttrInfo *thisState = myState->myinfo + i;
344  int16 format = (formats ? formats[i] : 0);
345  Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
346 
347  thisState->format = format;
348  if (format == 0)
349  {
350  getTypeOutputInfo(attr->atttypid,
351  &thisState->typoutput,
352  &thisState->typisvarlena);
353  fmgr_info(thisState->typoutput, &thisState->finfo);
354  }
355  else if (format == 1)
356  {
357  getTypeBinaryOutputInfo(attr->atttypid,
358  &thisState->typsend,
359  &thisState->typisvarlena);
360  fmgr_info(thisState->typsend, &thisState->finfo);
361  }
362  else
363  ereport(ERROR,
364  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
365  errmsg("unsupported format code: %d", format)));
366  }
367 }
368 
369 /* ----------------
370  * printtup --- print a tuple in protocol 3.0
371  * ----------------
372  */
373 static bool
375 {
376  TupleDesc typeinfo = slot->tts_tupleDescriptor;
377  DR_printtup *myState = (DR_printtup *) self;
378  MemoryContext oldcontext;
379  StringInfo buf = &myState->buf;
380  int natts = typeinfo->natts;
381  int i;
382 
383  /* Set or update my derived attribute info, if needed */
384  if (myState->attrinfo != typeinfo || myState->nattrs != natts)
385  printtup_prepare_info(myState, typeinfo, natts);
386 
387  /* Make sure the tuple is fully deconstructed */
388  slot_getallattrs(slot);
389 
390  /* Switch into per-row context so we can recover memory below */
391  oldcontext = MemoryContextSwitchTo(myState->tmpcontext);
392 
393  /*
394  * Prepare a DataRow message (note buffer is in per-row context)
395  */
396  pq_beginmessage_reuse(buf, 'D');
397 
398  pq_sendint16(buf, natts);
399 
400  /*
401  * send the attributes of this tuple
402  */
403  for (i = 0; i < natts; ++i)
404  {
405  PrinttupAttrInfo *thisState = myState->myinfo + i;
406  Datum attr = slot->tts_values[i];
407 
408  if (slot->tts_isnull[i])
409  {
410  pq_sendint32(buf, -1);
411  continue;
412  }
413 
414  /*
415  * Here we catch undefined bytes in datums that are returned to the
416  * client without hitting disk; see comments at the related check in
417  * PageAddItem(). This test is most useful for uncompressed,
418  * non-external datums, but we're quite likely to see such here when
419  * testing new C functions.
420  */
421  if (thisState->typisvarlena)
423  VARSIZE_ANY(attr));
424 
425  if (thisState->format == 0)
426  {
427  /* Text output */
428  char *outputstr;
429 
430  outputstr = OutputFunctionCall(&thisState->finfo, attr);
431  pq_sendcountedtext(buf, outputstr, strlen(outputstr), false);
432  }
433  else
434  {
435  /* Binary output */
436  bytea *outputbytes;
437 
438  outputbytes = SendFunctionCall(&thisState->finfo, attr);
439  pq_sendint32(buf, VARSIZE(outputbytes) - VARHDRSZ);
440  pq_sendbytes(buf, VARDATA(outputbytes),
441  VARSIZE(outputbytes) - VARHDRSZ);
442  }
443  }
444 
445  pq_endmessage_reuse(buf);
446 
447  /* Return to caller's context, and flush row's temporary memory */
448  MemoryContextSwitchTo(oldcontext);
449  MemoryContextReset(myState->tmpcontext);
450 
451  return true;
452 }
453 
454 /* ----------------
455  * printtup_20 --- print a tuple in protocol 2.0
456  * ----------------
457  */
458 static bool
460 {
461  TupleDesc typeinfo = slot->tts_tupleDescriptor;
462  DR_printtup *myState = (DR_printtup *) self;
463  MemoryContext oldcontext;
464  StringInfo buf = &myState->buf;
465  int natts = typeinfo->natts;
466  int i,
467  j,
468  k;
469 
470  /* Set or update my derived attribute info, if needed */
471  if (myState->attrinfo != typeinfo || myState->nattrs != natts)
472  printtup_prepare_info(myState, typeinfo, natts);
473 
474  /* Make sure the tuple is fully deconstructed */
475  slot_getallattrs(slot);
476 
477  /* Switch into per-row context so we can recover memory below */
478  oldcontext = MemoryContextSwitchTo(myState->tmpcontext);
479 
480  /*
481  * tell the frontend to expect new tuple data (in ASCII style)
482  */
483  pq_beginmessage_reuse(buf, 'D');
484 
485  /*
486  * send a bitmap of which attributes are not null
487  */
488  j = 0;
489  k = 1 << 7;
490  for (i = 0; i < natts; ++i)
491  {
492  if (!slot->tts_isnull[i])
493  j |= k; /* set bit if not null */
494  k >>= 1;
495  if (k == 0) /* end of byte? */
496  {
497  pq_sendint8(buf, j);
498  j = 0;
499  k = 1 << 7;
500  }
501  }
502  if (k != (1 << 7)) /* flush last partial byte */
503  pq_sendint8(buf, j);
504 
505  /*
506  * send the attributes of this tuple
507  */
508  for (i = 0; i < natts; ++i)
509  {
510  PrinttupAttrInfo *thisState = myState->myinfo + i;
511  Datum attr = slot->tts_values[i];
512  char *outputstr;
513 
514  if (slot->tts_isnull[i])
515  continue;
516 
517  Assert(thisState->format == 0);
518 
519  outputstr = OutputFunctionCall(&thisState->finfo, attr);
520  pq_sendcountedtext(buf, outputstr, strlen(outputstr), true);
521  }
522 
523  pq_endmessage_reuse(buf);
524 
525  /* Return to caller's context, and flush row's temporary memory */
526  MemoryContextSwitchTo(oldcontext);
527  MemoryContextReset(myState->tmpcontext);
528 
529  return true;
530 }
531 
532 /* ----------------
533  * printtup_shutdown
534  * ----------------
535  */
536 static void
538 {
539  DR_printtup *myState = (DR_printtup *) self;
540 
541  if (myState->myinfo)
542  pfree(myState->myinfo);
543  myState->myinfo = NULL;
544 
545  myState->attrinfo = NULL;
546 
547  if (myState->tmpcontext)
549  myState->tmpcontext = NULL;
550 }
551 
552 /* ----------------
553  * printtup_destroy
554  * ----------------
555  */
556 static void
558 {
559  pfree(self);
560 }
561 
562 /* ----------------
563  * printatt
564  * ----------------
565  */
566 static void
567 printatt(unsigned attributeId,
568  Form_pg_attribute attributeP,
569  char *value)
570 {
571  printf("\t%2d: %s%s%s%s\t(typeid = %u, len = %d, typmod = %d, byval = %c)\n",
572  attributeId,
573  NameStr(attributeP->attname),
574  value != NULL ? " = \"" : "",
575  value != NULL ? value : "",
576  value != NULL ? "\"" : "",
577  (unsigned int) (attributeP->atttypid),
578  attributeP->attlen,
579  attributeP->atttypmod,
580  attributeP->attbyval ? 't' : 'f');
581 }
582 
583 /* ----------------
584  * debugStartup - prepare to print tuples for an interactive backend
585  * ----------------
586  */
587 void
588 debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
589 {
590  int natts = typeinfo->natts;
591  int i;
592 
593  /*
594  * show the return type of the tuples
595  */
596  for (i = 0; i < natts; ++i)
597  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
598  printf("\t----\n");
599 }
600 
601 /* ----------------
602  * debugtup - print one tuple for an interactive backend
603  * ----------------
604  */
605 bool
607 {
608  TupleDesc typeinfo = slot->tts_tupleDescriptor;
609  int natts = typeinfo->natts;
610  int i;
611  Datum attr;
612  char *value;
613  bool isnull;
614  Oid typoutput;
615  bool typisvarlena;
616 
617  for (i = 0; i < natts; ++i)
618  {
619  attr = slot_getattr(slot, i + 1, &isnull);
620  if (isnull)
621  continue;
622  getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
623  &typoutput, &typisvarlena);
624 
625  value = OidOutputFunctionCall(typoutput, attr);
626 
627  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
628  }
629  printf("\t----\n");
630 
631  return true;
632 }
633 
634 /* ----------------
635  * printtup_internal_20 --- print a binary tuple in protocol 2.0
636  *
637  * We use a different message type, i.e. 'B' instead of 'D' to
638  * indicate a tuple in internal (binary) form.
639  *
640  * This is largely same as printtup_20, except we use binary formatting.
641  * ----------------
642  */
643 static bool
645 {
646  TupleDesc typeinfo = slot->tts_tupleDescriptor;
647  DR_printtup *myState = (DR_printtup *) self;
648  MemoryContext oldcontext;
649  StringInfo buf = &myState->buf;
650  int natts = typeinfo->natts;
651  int i,
652  j,
653  k;
654 
655  /* Set or update my derived attribute info, if needed */
656  if (myState->attrinfo != typeinfo || myState->nattrs != natts)
657  printtup_prepare_info(myState, typeinfo, natts);
658 
659  /* Make sure the tuple is fully deconstructed */
660  slot_getallattrs(slot);
661 
662  /* Switch into per-row context so we can recover memory below */
663  oldcontext = MemoryContextSwitchTo(myState->tmpcontext);
664 
665  /*
666  * tell the frontend to expect new tuple data (in binary style)
667  */
668  pq_beginmessage_reuse(buf, 'B');
669 
670  /*
671  * send a bitmap of which attributes are not null
672  */
673  j = 0;
674  k = 1 << 7;
675  for (i = 0; i < natts; ++i)
676  {
677  if (!slot->tts_isnull[i])
678  j |= k; /* set bit if not null */
679  k >>= 1;
680  if (k == 0) /* end of byte? */
681  {
682  pq_sendint8(buf, j);
683  j = 0;
684  k = 1 << 7;
685  }
686  }
687  if (k != (1 << 7)) /* flush last partial byte */
688  pq_sendint8(buf, j);
689 
690  /*
691  * send the attributes of this tuple
692  */
693  for (i = 0; i < natts; ++i)
694  {
695  PrinttupAttrInfo *thisState = myState->myinfo + i;
696  Datum attr = slot->tts_values[i];
697  bytea *outputbytes;
698 
699  if (slot->tts_isnull[i])
700  continue;
701 
702  Assert(thisState->format == 1);
703 
704  outputbytes = SendFunctionCall(&thisState->finfo, attr);
705  pq_sendint32(buf, VARSIZE(outputbytes) - VARHDRSZ);
706  pq_sendbytes(buf, VARDATA(outputbytes),
707  VARSIZE(outputbytes) - VARHDRSZ);
708  }
709 
710  pq_endmessage_reuse(buf);
711 
712  /* Return to caller's context, and flush row's temporary memory */
713  MemoryContextSwitchTo(oldcontext);
714  MemoryContextReset(myState->tmpcontext);
715 
716  return true;
717 }
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
signed short int16
Definition: c.h:283
Definition: fmgr.h:56
void SetRemoteDestReceiverParams(DestReceiver *self, Portal portal)
Definition: printtup.c:106
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2288
static void pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
Definition: pqformat.h:112
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2646
#define VARDATA(PTR)
Definition: postgres.h:303
CommandDest
Definition: dest.h:86
static bool printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:644
DestReceiver pub
Definition: printtup.c:63
#define VARSIZE(PTR)
Definition: postgres.h:304
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:90
#define VARHDRSZ
Definition: c.h:493
CommandDest mydest
Definition: dest.h:128
#define VALGRIND_CHECK_MEM_IS_DEFINED(addr, size)
Definition: memdebug.h:23
static void printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
Definition: printtup.c:323
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid resorigtbl
Definition: primnodes.h:1380
Datum * tts_values
Definition: tuptable.h:125
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:135
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:197
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
int natts
Definition: tupdesc.h:79
static void pq_sendint8(StringInfo buf, int8 i)
Definition: pqformat.h:132
signed int int32
Definition: c.h:284
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1662
#define NAMEDATALEN
void pfree(void *pointer)
Definition: mcxt.c:949
TupleDesc attrinfo
Definition: printtup.c:67
const char * name
Definition: portal.h:117
static void SendRowDescriptionCols_3(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:220
#define ERROR
Definition: elog.h:43
Portal portal
Definition: printtup.c:65
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
PrinttupAttrInfo * myinfo
Definition: printtup.c:69
static struct @121 value
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
static char * buf
Definition: pg_test_fsync.c:67
bool * tts_isnull
Definition: tuptable.h:126
DestReceiver * printtup_create_DR(CommandDest dest)
Definition: printtup.c:78
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:264
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1723
int nattrs
Definition: printtup.c:68
void pq_sendcountedtext(StringInfo buf, const char *str, int slen, bool countincludesself)
Definition: pqformat.c:142
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define lnext(lc)
Definition: pg_list.h:105
#define ereport(elevel, rest)
Definition: elog.h:122
void slot_getallattrs(TupleTableSlot *slot)
Definition: heaptuple.c:1238
static void pq_writeint16(StringInfoData *pg_restrict buf, int16 i)
Definition: pqformat.h:64
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
MemoryContext tmpcontext
Definition: printtup.c:70
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
void getTypeBinaryOutputInfo(Oid type, Oid *typSend, bool *typIsVarlena)
Definition: lsyscache.c:2712
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:567
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
void * palloc0(Size size)
Definition: mcxt.c:877
bool sendDescrip
Definition: printtup.c:66
int16 * formats
Definition: portal.h:157
uintptr_t Datum
Definition: postgres.h:372
#define VARSIZE_ANY(PTR)
Definition: postgres.h:334
static void printtup_destroy(DestReceiver *self)
Definition: printtup.c:557
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
bool typisvarlena
Definition: printtup.c:56
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: printtup.c:130
static bool printtup_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:459
static bool printtup(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:374
bool debugtup(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:606
#define DatumGetPointer(X)
Definition: postgres.h:555
static void pq_sendint16(StringInfo buf, int16 i)
Definition: pqformat.h:140
#define MAX_CONVERSION_GROWTH
Definition: pg_wchar.h:316
AttrNumber resorigcol
Definition: primnodes.h:1381
void pq_sendbytes(StringInfo buf, const char *data, int datalen)
Definition: pqformat.c:125
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1742
int errmsg(const char *fmt,...)
Definition: elog.c:797
static void SendRowDescriptionCols_2(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:296
int i
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1142
#define NameStr(name)
Definition: c.h:547
StringInfoData buf
Definition: printtup.c:64
Definition: c.h:487
static void printtup_shutdown(DestReceiver *self)
Definition: printtup.c:537
static char format
Definition: pg_basebackup.c:81
static void pq_writeint32(StringInfoData *pg_restrict buf, int32 i)
Definition: pqformat.h:78
List * FetchPortalTargetList(Portal portal)
Definition: pquery.c:338
void debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: printtup.c:588
void SendRowDescriptionMessage(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:197
void pq_puttextmessage(char msgtype, const char *str)
Definition: pqformat.c:369
Definition: pg_list.h:45
void pq_endmessage_reuse(StringInfo buf)
Definition: pqformat.c:316
int16 AttrNumber
Definition: attnum.h:21
ProtocolVersion FrontendProtocol
Definition: globals.c:27
FmgrInfo finfo
Definition: printtup.c:58
void pq_beginmessage_reuse(StringInfo buf, char msgtype)
Definition: pqformat.c:108