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 441 of file printtup.c.

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

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

◆ debugtup()

bool debugtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 459 of file printtup.c.

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

Referenced by print_slot().

460 {
461  TupleDesc typeinfo = slot->tts_tupleDescriptor;
462  int natts = typeinfo->natts;
463  int i;
464  Datum attr;
465  char *value;
466  bool isnull;
467  Oid typoutput;
468  bool typisvarlena;
469 
470  for (i = 0; i < natts; ++i)
471  {
472  attr = slot_getattr(slot, i + 1, &isnull);
473  if (isnull)
474  continue;
475  getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
476  &typoutput, &typisvarlena);
477 
478  value = OidOutputFunctionCall(typoutput, attr);
479 
480  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
481  }
482  printf("\t----\n");
483 
484  return true;
485 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2854
static struct @142 value
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define printf(...)
Definition: port.h:222
unsigned int Oid
Definition: postgres_ext.h:31
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:420
uintptr_t Datum
Definition: postgres.h:411
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:381
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1653
int i

◆ printtup_create_DR()

DestReceiver* printtup_create_DR ( CommandDest  dest)

Definition at line 71 of file printtup.c.

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

Referenced by CreateDestReceiver().

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

◆ SendRowDescriptionMessage()

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

Definition at line 166 of file printtup.c.

References 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(), TargetEntry::resorigcol, TargetEntry::resorigtbl, and TupleDescAttr.

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

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

◆ SetRemoteDestReceiverParams()

void SetRemoteDestReceiverParams ( DestReceiver self,
Portal  portal 
)

Definition at line 100 of file printtup.c.

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

Referenced by exec_execute_message(), and exec_simple_query().

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

◆ spi_dest_startup()

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

Definition at line 2005 of file spi.c.

References _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.

2006 {
2007  SPITupleTable *tuptable;
2008  MemoryContext oldcxt;
2009  MemoryContext tuptabcxt;
2010 
2011  if (_SPI_current == NULL)
2012  elog(ERROR, "spi_dest_startup called while not connected to SPI");
2013 
2014  if (_SPI_current->tuptable != NULL)
2015  elog(ERROR, "improper call to spi_dest_startup");
2016 
2017  /* We create the tuple table context as a child of procCxt */
2018 
2019  oldcxt = _SPI_procmem(); /* switch to procedure memory context */
2020 
2022  "SPI TupTable",
2024  MemoryContextSwitchTo(tuptabcxt);
2025 
2026  _SPI_current->tuptable = tuptable = (SPITupleTable *)
2027  palloc0(sizeof(SPITupleTable));
2028  tuptable->tuptabcxt = tuptabcxt;
2029  tuptable->subid = GetCurrentSubTransactionId();
2030 
2031  /*
2032  * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
2033  * it onto the SPI context's tuptables list. This will ensure it's not
2034  * leaked even in the unlikely event the following few lines fail.
2035  */
2036  slist_push_head(&_SPI_current->tuptables, &tuptable->next);
2037 
2038  /* set up initial allocations */
2039  tuptable->alloced = 128;
2040  tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
2041  tuptable->numvals = 0;
2042  tuptable->tupdesc = CreateTupleDescCopy(typeinfo);
2043 
2044  MemoryContextSwitchTo(oldcxt);
2045 }
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
#define AllocSetContextCreate
Definition: memutils.h:173
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:593
slist_node next
Definition: spi.h:32
static _SPI_connection * _SPI_current
Definition: spi.c:50
HeapTuple * vals
Definition: spi.h:26
uint64 numvals
Definition: spi.h:27
#define ERROR
Definition: elog.h:46
SPITupleTable * tuptable
Definition: spi_priv.h:26
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
void * palloc0(Size size)
Definition: mcxt.c:1093
TupleDesc tupdesc
Definition: spi.h:25
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:723
void * palloc(Size size)
Definition: mcxt.c:1062
#define elog(elevel,...)
Definition: elog.h:232
uint64 alloced
Definition: spi.h:30
static MemoryContext _SPI_procmem(void)
Definition: spi.c:2861
SubTransactionId subid
Definition: spi.h:33
slist_head tuptables
Definition: spi_priv.h:32
MemoryContext tuptabcxt
Definition: spi.h:31

◆ spi_printtup()

bool spi_printtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 2053 of file spi.c.

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

2054 {
2055  SPITupleTable *tuptable;
2056  MemoryContext oldcxt;
2057 
2058  if (_SPI_current == NULL)
2059  elog(ERROR, "spi_printtup called while not connected to SPI");
2060 
2061  tuptable = _SPI_current->tuptable;
2062  if (tuptable == NULL)
2063  elog(ERROR, "improper call to spi_printtup");
2064 
2065  oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);
2066 
2067  if (tuptable->numvals >= tuptable->alloced)
2068  {
2069  /* Double the size of the pointer array */
2070  uint64 newalloced = tuptable->alloced * 2;
2071 
2072  tuptable->vals = (HeapTuple *) repalloc_huge(tuptable->vals,
2073  newalloced * sizeof(HeapTuple));
2074  tuptable->alloced = newalloced;
2075  }
2076 
2077  tuptable->vals[tuptable->numvals] = ExecCopySlotHeapTuple(slot);
2078  (tuptable->numvals)++;
2079 
2080  MemoryContextSwitchTo(oldcxt);
2081 
2082  return true;
2083 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static _SPI_connection * _SPI_current
Definition: spi.c:50
HeapTuple * vals
Definition: spi.h:26
uint64 numvals
Definition: spi.h:27
#define ERROR
Definition: elog.h:46
SPITupleTable * tuptable
Definition: spi_priv.h:26
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:452
void * repalloc_huge(void *pointer, Size size)
Definition: mcxt.c:1252
#define elog(elevel,...)
Definition: elog.h:232
uint64 alloced
Definition: spi.h:30
MemoryContext tuptabcxt
Definition: spi.h:31