PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 
)
extern

Definition at line 445 of file printtup.c.

446{
447 int natts = typeinfo->natts;
448 int i;
449
450 /*
451 * show the return type of the tuples
452 */
453 for (i = 0; i < natts; ++i)
454 printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
455 printf("\t----\n");
456}
int i
Definition isn.c:77
#define printf(...)
Definition port.h:266
static int fb(int x)
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition printtup.c:424
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:160

References fb(), i, printatt(), printf, and TupleDescAttr().

◆ debugtup()

bool debugtup ( TupleTableSlot slot,
DestReceiver self 
)
extern

Definition at line 463 of file printtup.c.

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

References fb(), 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)
extern

Definition at line 72 of file printtup.c.

73{
75
76 self->pub.receiveSlot = printtup; /* might get changed later */
80 self->pub.mydest = dest;
81
82 /*
83 * Send T message automatically if DestRemote, but not if
84 * DestRemoteExecute
85 */
86 self->sendDescrip = (dest == DestRemote);
87
88 self->attrinfo = NULL;
89 self->nattrs = 0;
90 self->myinfo = NULL;
91 self->buf.data = NULL;
92 self->tmpcontext = NULL;
93
94 return (DestReceiver *) self;
95}
@ DestRemote
Definition dest.h:89
#define palloc0_object(type)
Definition fe_memutils.h:75
static bool printtup(TupleTableSlot *slot, DestReceiver *self)
Definition printtup.c:305
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition printtup.c:112
static void printtup_destroy(DestReceiver *self)
Definition printtup.c:414
static void printtup_shutdown(DestReceiver *self)
Definition printtup.c:390
PrinttupAttrInfo * myinfo
Definition printtup.c:62
StringInfoData buf
Definition printtup.c:63
DestReceiver pub
Definition printtup.c:57
bool sendDescrip
Definition printtup.c:59
MemoryContext tmpcontext
Definition printtup.c:64
TupleDesc attrinfo
Definition printtup.c:60
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition dest.h:121
void(* rShutdown)(DestReceiver *self)
Definition dest.h:124
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition dest.h:118
void(* rDestroy)(DestReceiver *self)
Definition dest.h:126
CommandDest mydest
Definition dest.h:128

References DR_printtup::attrinfo, DR_printtup::buf, StringInfoData::data, DestRemote, fb(), _DestReceiver::mydest, DR_printtup::myinfo, DR_printtup::nattrs, palloc0_object, printtup(), printtup_destroy(), printtup_shutdown(), printtup_startup(), DR_printtup::pub, _DestReceiver::rDestroy, _DestReceiver::receiveSlot, _DestReceiver::rShutdown, _DestReceiver::rStartup, DR_printtup::sendDescrip, and DR_printtup::tmpcontext.

Referenced by CreateDestReceiver().

◆ SendRowDescriptionMessage()

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

Definition at line 167 of file printtup.c.

169{
170 int natts = typeinfo->natts;
171 int i;
172 ListCell *tlist_item = list_head(targetlist);
173
174 /* tuple descriptor message type */
176 /* # of attrs in tuples */
177 pq_sendint16(buf, natts);
178
179 /*
180 * Preallocate memory for the entire message to be sent. That allows to
181 * use the significantly faster inline pqformat.h functions and to avoid
182 * reallocations.
183 *
184 * Have to overestimate the size of the column-names, to account for
185 * character set overhead.
186 */
188 + sizeof(Oid) /* resorigtbl */
189 + sizeof(AttrNumber) /* resorigcol */
190 + sizeof(Oid) /* atttypid */
191 + sizeof(int16) /* attlen */
192 + sizeof(int32) /* attypmod */
193 + sizeof(int16) /* format */
194 ) * natts);
195
196 for (i = 0; i < natts; ++i)
197 {
199 Oid atttypid = att->atttypid;
200 int32 atttypmod = att->atttypmod;
204
205 /*
206 * If column is a domain, send the base type and typmod instead.
207 * Lookup before sending any ints, for efficiency.
208 */
210
211 /* Do we have a non-resjunk tlist item? */
212 while (tlist_item &&
214 tlist_item = lnext(targetlist, tlist_item);
215 if (tlist_item)
216 {
218
219 resorigtbl = tle->resorigtbl;
220 resorigcol = tle->resorigcol;
221 tlist_item = lnext(targetlist, tlist_item);
222 }
223 else
224 {
225 /* No info available, so send zeroes */
226 resorigtbl = 0;
227 resorigcol = 0;
228 }
229
230 if (formats)
231 format = formats[i];
232 else
233 format = 0;
234
235 pq_writestring(buf, NameStr(att->attname));
239 pq_writeint16(buf, att->attlen);
240 pq_writeint32(buf, atttypmod);
242 }
243
245}
int16 AttrNumber
Definition attnum.h:21
#define NameStr(name)
Definition c.h:765
int16_t int16
Definition c.h:541
int32_t int32
Definition c.h:542
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition lsyscache.c:2688
FormData_pg_attribute * Form_pg_attribute
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[DEFAULT_XLOG_SEG_SIZE]
#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:313
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
#define PqMsg_RowDescription
Definition protocol.h:52
void enlargeStringInfo(StringInfo str, int needed)
Definition stringinfo.c:337

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

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

◆ SetRemoteDestReceiverParams()

void SetRemoteDestReceiverParams ( DestReceiver self,
Portal  portal 
)
extern

Definition at line 101 of file printtup.c.

102{
103 DR_printtup *myState = (DR_printtup *) self;
104
105 Assert(myState->pub.mydest == DestRemote ||
106 myState->pub.mydest == DestRemoteExecute);
107
108 myState->portal = portal;
109}
#define Assert(condition)
Definition c.h:873
@ DestRemoteExecute
Definition dest.h:90

References Assert, DestRemote, DestRemoteExecute, and fb().

Referenced by exec_execute_message(), and exec_simple_query().

◆ spi_dest_startup()

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

Definition at line 2123 of file spi.c.

2124{
2125 SPITupleTable *tuptable;
2127 MemoryContext tuptabcxt;
2128
2129 if (_SPI_current == NULL)
2130 elog(ERROR, "spi_dest_startup called while not connected to SPI");
2131
2132 if (_SPI_current->tuptable != NULL)
2133 elog(ERROR, "improper call to spi_dest_startup");
2134
2135 /* We create the tuple table context as a child of procCxt */
2136
2137 oldcxt = _SPI_procmem(); /* switch to procedure memory context */
2138
2140 "SPI TupTable",
2142 MemoryContextSwitchTo(tuptabcxt);
2143
2145 tuptable->tuptabcxt = tuptabcxt;
2146 tuptable->subid = GetCurrentSubTransactionId();
2147
2148 /*
2149 * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
2150 * it onto the SPI context's tuptables list. This will ensure it's not
2151 * leaked even in the unlikely event the following few lines fail.
2152 */
2154
2155 /* set up initial allocations */
2156 tuptable->alloced = 128;
2157 tuptable->vals = palloc_array(HeapTuple, tuptable->alloced);
2158 tuptable->numvals = 0;
2160
2162}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define palloc_array(type, count)
Definition fe_memutils.h:76
static void slist_push_head(slist_head *head, slist_node *node)
Definition ilist.h:1006
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
static _SPI_connection * _SPI_current
Definition spi.c:49
static MemoryContext _SPI_procmem(void)
Definition spi.c:3063
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:235
SubTransactionId GetCurrentSubTransactionId(void)
Definition xact.c:792

References _SPI_current, _SPI_procmem(), SPITupleTable::alloced, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CreateTupleDescCopy(), CurrentMemoryContext, elog, ERROR, fb(), GetCurrentSubTransactionId(), MemoryContextSwitchTo(), SPITupleTable::next, SPITupleTable::numvals, palloc0_object, palloc_array, 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 
)
extern

Definition at line 2170 of file spi.c.

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

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