PostgreSQL Source Code  git master
printtup.h File Reference
#include "utils/portal.h"
Include dependency graph for printtup.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

DestReceiverprinttup_create_DR (CommandDest dest)
 
void SetRemoteDestReceiverParams (DestReceiver *self, Portal portal)
 
void SendRowDescriptionMessage (StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
 
void debugStartup (DestReceiver *self, int operation, TupleDesc typeinfo)
 
bool debugtup (TupleTableSlot *slot, DestReceiver *self)
 
void spi_dest_startup (DestReceiver *self, int operation, TupleDesc typeinfo)
 
bool spi_printtup (TupleTableSlot *slot, DestReceiver *self)
 

Function Documentation

◆ debugStartup()

void debugStartup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)

Definition at line 443 of file printtup.c.

444 {
445  int natts = typeinfo->natts;
446  int i;
447 
448  /*
449  * show the return type of the tuples
450  */
451  for (i = 0; i < natts; ++i)
452  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
453  printf("\t----\n");
454 }
int i
Definition: isn.c:73
#define printf(...)
Definition: port.h:244
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:422
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References i, TupleDescData::natts, printatt(), printf, and TupleDescAttr.

◆ debugtup()

bool debugtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 461 of file printtup.c.

462 {
463  TupleDesc typeinfo = slot->tts_tupleDescriptor;
464  int natts = typeinfo->natts;
465  int i;
466  Datum attr;
467  char *value;
468  bool isnull;
469  Oid typoutput;
470  bool typisvarlena;
471 
472  for (i = 0; i < natts; ++i)
473  {
474  attr = slot_getattr(slot, i + 1, &isnull);
475  if (isnull)
476  continue;
477  getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
478  &typoutput, &typisvarlena);
479 
480  value = OidOutputFunctionCall(typoutput, attr);
481 
482  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
483  }
484  printf("\t----\n");
485 
486  return true;
487 }
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1763
static struct @155 value
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2907
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:395

References getTypeOutputInfo(), i, TupleDescData::natts, OidOutputFunctionCall(), printatt(), printf, slot_getattr(), TupleTableSlot::tts_tupleDescriptor, TupleDescAttr, and value.

Referenced by print_slot().

◆ printtup_create_DR()

DestReceiver* printtup_create_DR ( CommandDest  dest)

Definition at line 70 of file printtup.c.

71 {
72  DR_printtup *self = (DR_printtup *) palloc0(sizeof(DR_printtup));
73 
74  self->pub.receiveSlot = printtup; /* might get changed later */
75  self->pub.rStartup = printtup_startup;
76  self->pub.rShutdown = printtup_shutdown;
77  self->pub.rDestroy = printtup_destroy;
78  self->pub.mydest = dest;
79 
80  /*
81  * Send T message automatically if DestRemote, but not if
82  * DestRemoteExecute
83  */
84  self->sendDescrip = (dest == DestRemote);
85 
86  self->attrinfo = NULL;
87  self->nattrs = 0;
88  self->myinfo = NULL;
89  self->buf.data = NULL;
90  self->tmpcontext = NULL;
91 
92  return (DestReceiver *) self;
93 }
@ DestRemote
Definition: dest.h:89
void * palloc0(Size size)
Definition: mcxt.c:1346
static bool printtup(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:303
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: printtup.c:110
static void printtup_destroy(DestReceiver *self)
Definition: printtup.c:412
static void printtup_shutdown(DestReceiver *self)
Definition: printtup.c:388

References generate_unaccent_rules::dest, DestRemote, palloc0(), printtup(), printtup_destroy(), printtup_shutdown(), and printtup_startup().

Referenced by CreateDestReceiver().

◆ SendRowDescriptionMessage()

void SendRowDescriptionMessage ( StringInfo  buf,
TupleDesc  typeinfo,
List targetlist,
int16 formats 
)

Definition at line 165 of file printtup.c.

167 {
168  int natts = typeinfo->natts;
169  int i;
170  ListCell *tlist_item = list_head(targetlist);
171 
172  /* tuple descriptor message type */
174  /* # of attrs in tuples */
175  pq_sendint16(buf, natts);
176 
177  /*
178  * Preallocate memory for the entire message to be sent. That allows to
179  * use the significantly faster inline pqformat.h functions and to avoid
180  * reallocations.
181  *
182  * Have to overestimate the size of the column-names, to account for
183  * character set overhead.
184  */
186  + sizeof(Oid) /* resorigtbl */
187  + sizeof(AttrNumber) /* resorigcol */
188  + sizeof(Oid) /* atttypid */
189  + sizeof(int16) /* attlen */
190  + sizeof(int32) /* attypmod */
191  + sizeof(int16) /* format */
192  ) * natts);
193 
194  for (i = 0; i < natts; ++i)
195  {
196  Form_pg_attribute att = TupleDescAttr(typeinfo, i);
197  Oid atttypid = att->atttypid;
198  int32 atttypmod = att->atttypmod;
199  Oid resorigtbl;
200  AttrNumber resorigcol;
201  int16 format;
202 
203  /*
204  * If column is a domain, send the base type and typmod instead.
205  * Lookup before sending any ints, for efficiency.
206  */
207  atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
208 
209  /* Do we have a non-resjunk tlist item? */
210  while (tlist_item &&
211  ((TargetEntry *) lfirst(tlist_item))->resjunk)
212  tlist_item = lnext(targetlist, tlist_item);
213  if (tlist_item)
214  {
215  TargetEntry *tle = (TargetEntry *) lfirst(tlist_item);
216 
217  resorigtbl = tle->resorigtbl;
218  resorigcol = tle->resorigcol;
219  tlist_item = lnext(targetlist, tlist_item);
220  }
221  else
222  {
223  /* No info available, so send zeroes */
224  resorigtbl = 0;
225  resorigcol = 0;
226  }
227 
228  if (formats)
229  format = formats[i];
230  else
231  format = 0;
232 
233  pq_writestring(buf, NameStr(att->attname));
234  pq_writeint32(buf, resorigtbl);
235  pq_writeint16(buf, resorigcol);
236  pq_writeint32(buf, atttypid);
237  pq_writeint16(buf, att->attlen);
238  pq_writeint32(buf, atttypmod);
240  }
241 
243 }
int16 AttrNumber
Definition: attnum.h:21
#define NameStr(name)
Definition: c.h:746
signed short int16
Definition: c.h:493
signed int int32
Definition: c.h:494
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2538
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
static char format
#define NAMEDATALEN
#define lfirst(lc)
Definition: pg_list.h:172
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
static char * buf
Definition: pg_test_fsync.c:73
#define MAX_CONVERSION_GROWTH
Definition: pg_wchar.h:302
void pq_beginmessage_reuse(StringInfo buf, char msgtype)
Definition: pqformat.c:109
void pq_endmessage_reuse(StringInfo buf)
Definition: pqformat.c:314
static void pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
Definition: pqformat.h:108
static void pq_writeint32(StringInfoData *pg_restrict buf, uint32 i)
Definition: pqformat.h:74
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:136
static void pq_writeint16(StringInfoData *pg_restrict buf, uint16 i)
Definition: pqformat.h:60
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:289

References buf, enlargeStringInfo(), format, getBaseTypeAndTypmod(), i, lfirst, list_head(), lnext(), MAX_CONVERSION_GROWTH, NAMEDATALEN, NameStr, TupleDescData::natts, pq_beginmessage_reuse(), pq_endmessage_reuse(), pq_sendint16(), pq_writeint16(), pq_writeint32(), pq_writestring(), and TupleDescAttr.

Referenced by exec_describe_portal_message(), exec_describe_statement_message(), and printtup_startup().

◆ SetRemoteDestReceiverParams()

void SetRemoteDestReceiverParams ( DestReceiver self,
Portal  portal 
)

Definition at line 99 of file printtup.c.

100 {
101  DR_printtup *myState = (DR_printtup *) self;
102 
103  Assert(myState->pub.mydest == DestRemote ||
104  myState->pub.mydest == DestRemoteExecute);
105 
106  myState->portal = portal;
107 }
#define Assert(condition)
Definition: c.h:858
@ DestRemoteExecute
Definition: dest.h:90
DestReceiver pub
Definition: printtup.c:55
Portal portal
Definition: printtup.c:56
CommandDest mydest
Definition: dest.h:128

References Assert, DestRemote, DestRemoteExecute, _DestReceiver::mydest, DR_printtup::portal, and DR_printtup::pub.

Referenced by exec_execute_message(), and exec_simple_query().

◆ spi_dest_startup()

void spi_dest_startup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)

Definition at line 2118 of file spi.c.

2119 {
2120  SPITupleTable *tuptable;
2121  MemoryContext oldcxt;
2122  MemoryContext tuptabcxt;
2123 
2124  if (_SPI_current == NULL)
2125  elog(ERROR, "spi_dest_startup called while not connected to SPI");
2126 
2127  if (_SPI_current->tuptable != NULL)
2128  elog(ERROR, "improper call to spi_dest_startup");
2129 
2130  /* We create the tuple table context as a child of procCxt */
2131 
2132  oldcxt = _SPI_procmem(); /* switch to procedure memory context */
2133 
2135  "SPI TupTable",
2137  MemoryContextSwitchTo(tuptabcxt);
2138 
2139  _SPI_current->tuptable = tuptable = (SPITupleTable *)
2140  palloc0(sizeof(SPITupleTable));
2141  tuptable->tuptabcxt = tuptabcxt;
2142  tuptable->subid = GetCurrentSubTransactionId();
2143 
2144  /*
2145  * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
2146  * it onto the SPI context's tuptables list. This will ensure it's not
2147  * leaked even in the unlikely event the following few lines fail.
2148  */
2149  slist_push_head(&_SPI_current->tuptables, &tuptable->next);
2150 
2151  /* set up initial allocations */
2152  tuptable->alloced = 128;
2153  tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
2154  tuptable->numvals = 0;
2155  tuptable->tupdesc = CreateTupleDescCopy(typeinfo);
2156 
2157  MemoryContextSwitchTo(oldcxt);
2158 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:1006
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
void * palloc(Size size)
Definition: mcxt.c:1316
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
MemoryContextSwitchTo(old_ctx)
static _SPI_connection * _SPI_current
Definition: spi.c:49
static MemoryContext _SPI_procmem(void)
Definition: spi.c:3044
uint64 alloced
Definition: spi.h:30
uint64 numvals
Definition: spi.h:27
TupleDesc tupdesc
Definition: spi.h:25
HeapTuple * vals
Definition: spi.h:26
MemoryContext tuptabcxt
Definition: spi.h:31
slist_node next
Definition: spi.h:32
SubTransactionId subid
Definition: spi.h:33
slist_head tuptables
Definition: spi_priv.h:32
SPITupleTable * tuptable
Definition: spi_priv.h:26
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:133
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:788

References _SPI_current, _SPI_procmem(), SPITupleTable::alloced, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CreateTupleDescCopy(), CurrentMemoryContext, elog, ERROR, GetCurrentSubTransactionId(), MemoryContextSwitchTo(), SPITupleTable::next, SPITupleTable::numvals, palloc(), palloc0(), slist_push_head(), SPITupleTable::subid, SPITupleTable::tupdesc, SPITupleTable::tuptabcxt, _SPI_connection::tuptable, _SPI_connection::tuptables, and SPITupleTable::vals.

◆ spi_printtup()

bool spi_printtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 2166 of file spi.c.

2167 {
2168  SPITupleTable *tuptable;
2169  MemoryContext oldcxt;
2170 
2171  if (_SPI_current == NULL)
2172  elog(ERROR, "spi_printtup called while not connected to SPI");
2173 
2174  tuptable = _SPI_current->tuptable;
2175  if (tuptable == NULL)
2176  elog(ERROR, "improper call to spi_printtup");
2177 
2178  oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);
2179 
2180  if (tuptable->numvals >= tuptable->alloced)
2181  {
2182  /* Double the size of the pointer array */
2183  uint64 newalloced = tuptable->alloced * 2;
2184 
2185  tuptable->vals = (HeapTuple *) repalloc_huge(tuptable->vals,
2186  newalloced * sizeof(HeapTuple));
2187  tuptable->alloced = newalloced;
2188  }
2189 
2190  tuptable->vals[tuptable->numvals] = ExecCopySlotHeapTuple(slot);
2191  (tuptable->numvals)++;
2192 
2193  MemoryContextSwitchTo(oldcxt);
2194 
2195  return true;
2196 }
void * repalloc_huge(void *pointer, Size size)
Definition: mcxt.c:1671
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:481

References _SPI_current, SPITupleTable::alloced, elog, ERROR, ExecCopySlotHeapTuple(), MemoryContextSwitchTo(), SPITupleTable::numvals, repalloc_huge(), SPITupleTable::tuptabcxt, _SPI_connection::tuptable, and SPITupleTable::vals.