LCOV - differential code coverage report
Current view: top level - src/backend/access/common - printtup.c (source / functions) Coverage Total Hit UBC CBC
Current: b45a8d7d8b306b43f31a002f1b3f1dddc8defeaf vs 8767b449a3a1e75626dfb08f24da54933171d4c5 Lines: 98.0 % 149 146 3 146
Current Date: 2025-10-28 08:26:42 +0900 Functions: 100.0 % 11 11 11
Baseline: lcov-20251028-005825-baseline Branches: 85.0 % 60 51 9 51
Baseline Date: 2025-10-27 06:37:35 +0000 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 98.0 % 149 146 3 146
Function coverage date bins:
(360..) days: 100.0 % 11 11 11
Branch coverage date bins:
(360..) days: 85.0 % 60 51 9 51

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  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-2025, 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/pqformat.h"
                                 20                 :                : #include "libpq/protocol.h"
                                 21                 :                : #include "tcop/pquery.h"
                                 22                 :                : #include "utils/lsyscache.h"
                                 23                 :                : #include "utils/memdebug.h"
                                 24                 :                : #include "utils/memutils.h"
                                 25                 :                : #include "varatt.h"
                                 26                 :                : 
                                 27                 :                : 
                                 28                 :                : static void printtup_startup(DestReceiver *self, int operation,
                                 29                 :                :                              TupleDesc typeinfo);
                                 30                 :                : static bool printtup(TupleTableSlot *slot, DestReceiver *self);
                                 31                 :                : static void printtup_shutdown(DestReceiver *self);
                                 32                 :                : static void printtup_destroy(DestReceiver *self);
                                 33                 :                : 
                                 34                 :                : /* ----------------------------------------------------------------
                                 35                 :                :  *      printtup / debugtup support
                                 36                 :                :  * ----------------------------------------------------------------
                                 37                 :                :  */
                                 38                 :                : 
                                 39                 :                : /* ----------------
                                 40                 :                :  *      Private state for a printtup destination object
                                 41                 :                :  *
                                 42                 :                :  * NOTE: finfo is the lookup info for either typoutput or typsend, whichever
                                 43                 :                :  * we are using for this column.
                                 44                 :                :  * ----------------
                                 45                 :                :  */
                                 46                 :                : typedef struct
                                 47                 :                : {                               /* Per-attribute information */
                                 48                 :                :     Oid         typoutput;      /* Oid for the type's text output fn */
                                 49                 :                :     Oid         typsend;        /* Oid for the type's binary output fn */
                                 50                 :                :     bool        typisvarlena;   /* is it varlena (ie possibly toastable)? */
                                 51                 :                :     int16       format;         /* format code for this column */
                                 52                 :                :     FmgrInfo    finfo;          /* Precomputed call info for output fn */
                                 53                 :                : } PrinttupAttrInfo;
                                 54                 :                : 
                                 55                 :                : typedef struct
                                 56                 :                : {
                                 57                 :                :     DestReceiver pub;           /* publicly-known function pointers */
                                 58                 :                :     Portal      portal;         /* the Portal we are printing from */
                                 59                 :                :     bool        sendDescrip;    /* send RowDescription at startup? */
                                 60                 :                :     TupleDesc   attrinfo;       /* The attr info we are set up for */
                                 61                 :                :     int         nattrs;
                                 62                 :                :     PrinttupAttrInfo *myinfo;   /* Cached info about each attr */
                                 63                 :                :     StringInfoData buf;         /* output buffer (*not* in tmpcontext) */
                                 64                 :                :     MemoryContext tmpcontext;   /* Memory context for per-row workspace */
                                 65                 :                : } DR_printtup;
                                 66                 :                : 
                                 67                 :                : /* ----------------
                                 68                 :                :  *      Initialize: create a DestReceiver for printtup
                                 69                 :                :  * ----------------
                                 70                 :                :  */
                                 71                 :                : DestReceiver *
 6176 tgl@sss.pgh.pa.us          72                 :CBC      310869 : printtup_create_DR(CommandDest dest)
                                 73                 :                : {
                                 74                 :         310869 :     DR_printtup *self = (DR_printtup *) palloc0(sizeof(DR_printtup));
                                 75                 :                : 
 5983 bruce@momjian.us           76                 :         310869 :     self->pub.receiveSlot = printtup;    /* might get changed later */
 8119 tgl@sss.pgh.pa.us          77                 :         310869 :     self->pub.rStartup = printtup_startup;
                                 78                 :         310869 :     self->pub.rShutdown = printtup_shutdown;
                                 79                 :         310869 :     self->pub.rDestroy = printtup_destroy;
 8211                            80                 :         310869 :     self->pub.mydest = dest;
                                 81                 :                : 
                                 82                 :                :     /*
                                 83                 :                :      * Send T message automatically if DestRemote, but not if
                                 84                 :                :      * DestRemoteExecute
                                 85                 :                :      */
 7299 alvherre@alvh.no-ip.       86                 :         310869 :     self->sendDescrip = (dest == DestRemote);
                                 87                 :                : 
 9771 tgl@sss.pgh.pa.us          88                 :         310869 :     self->attrinfo = NULL;
                                 89                 :         310869 :     self->nattrs = 0;
                                 90                 :         310869 :     self->myinfo = NULL;
 2416                            91                 :         310869 :     self->buf.data = NULL;
 4377                            92                 :         310869 :     self->tmpcontext = NULL;
                                 93                 :                : 
 9653 bruce@momjian.us           94                 :         310869 :     return (DestReceiver *) self;
                                 95                 :                : }
                                 96                 :                : 
                                 97                 :                : /*
                                 98                 :                :  * Set parameters for a DestRemote (or DestRemoteExecute) receiver
                                 99                 :                :  */
                                100                 :                : void
 6176 tgl@sss.pgh.pa.us         101                 :         310869 : SetRemoteDestReceiverParams(DestReceiver *self, Portal portal)
                                102                 :                : {
                                103                 :         310869 :     DR_printtup *myState = (DR_printtup *) self;
                                104                 :                : 
                                105   [ +  +  -  + ]:         310869 :     Assert(myState->pub.mydest == DestRemote ||
                                106                 :                :            myState->pub.mydest == DestRemoteExecute);
                                107                 :                : 
                                108                 :         310869 :     myState->portal = portal;
                                109                 :         310869 : }
                                110                 :                : 
                                111                 :                : static void
 8209                           112                 :         153607 : printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
                                113                 :                : {
 8212                           114                 :         153607 :     DR_printtup *myState = (DR_printtup *) self;
 8121 bruce@momjian.us          115                 :         153607 :     Portal      portal = myState->portal;
                                116                 :                : 
                                117                 :                :     /*
                                118                 :                :      * Create I/O buffer to be used for all messages.  This cannot be inside
                                119                 :                :      * tmpcontext, since we want to re-use it across rows.
                                120                 :                :      */
 2939 andres@anarazel.de        121                 :         153607 :     initStringInfo(&myState->buf);
                                122                 :                : 
                                123                 :                :     /*
                                124                 :                :      * Create a temporary memory context that we can reset once per row to
                                125                 :                :      * recover palloc'd memory.  This avoids any problems with leaks inside
                                126                 :                :      * datatype output routines, and should be faster than retail pfree's
                                127                 :                :      * anyway.
                                128                 :                :      */
 4377 tgl@sss.pgh.pa.us         129                 :         153607 :     myState->tmpcontext = AllocSetContextCreate(CurrentMemoryContext,
                                130                 :                :                                                 "printtup",
                                131                 :                :                                                 ALLOCSET_DEFAULT_SIZES);
                                132                 :                : 
                                133                 :                :     /*
                                134                 :                :      * If we are supposed to emit row descriptions, then send the tuple
                                135                 :                :      * descriptor of the tuples.
                                136                 :                :      */
 7017                           137         [ +  + ]:         153607 :     if (myState->sendDescrip)
 2939 andres@anarazel.de        138                 :         148871 :         SendRowDescriptionMessage(&myState->buf,
                                139                 :                :                                   typeinfo,
                                140                 :                :                                   FetchPortalTargetList(portal),
                                141                 :                :                                   portal->formats);
                                142                 :                : 
                                143                 :                :     /* ----------------
                                144                 :                :      * We could set up the derived attr info at this time, but we postpone it
                                145                 :                :      * until the first call of printtup, for 2 reasons:
                                146                 :                :      * 1. We don't waste time (compared to the old way) if there are no
                                147                 :                :      *    tuples at all to output.
                                148                 :                :      * 2. Checking in printtup allows us to handle the case that the tuples
                                149                 :                :      *    change type midway through (although this probably can't happen in
                                150                 :                :      *    the current executor).
                                151                 :                :      * ----------------
                                152                 :                :      */
 9771 tgl@sss.pgh.pa.us         153                 :         153607 : }
                                154                 :                : 
                                155                 :                : /*
                                156                 :                :  * SendRowDescriptionMessage --- send a RowDescription message to the frontend
                                157                 :                :  *
                                158                 :                :  * Notes: the TupleDesc has typically been manufactured by ExecTypeFromTL()
                                159                 :                :  * or some similar function; it does not contain a full set of fields.
                                160                 :                :  * The targetlist will be NIL when executing a utility function that does
                                161                 :                :  * not have a plan.  If the targetlist isn't NIL then it is a Query node's
                                162                 :                :  * targetlist; it is up to us to ignore resjunk columns in it.  The formats[]
                                163                 :                :  * array pointer might be NULL (if we are doing Describe on a prepared stmt);
                                164                 :                :  * send zeroes for the format codes in that case.
                                165                 :                :  */
                                166                 :                : void
 2939 andres@anarazel.de        167                 :         153653 : SendRowDescriptionMessage(StringInfo buf, TupleDesc typeinfo,
                                168                 :                :                           List *targetlist, int16 *formats)
                                169                 :                : {
 8212 tgl@sss.pgh.pa.us         170                 :         153653 :     int         natts = typeinfo->natts;
                                171                 :                :     int         i;
 1699 heikki.linnakangas@i      172                 :         153653 :     ListCell   *tlist_item = list_head(targetlist);
                                173                 :                : 
                                174                 :                :     /* tuple descriptor message type */
  468 nathan@postgresql.or      175                 :         153653 :     pq_beginmessage_reuse(buf, PqMsg_RowDescription);
                                176                 :                :     /* # of attrs in tuples */
 2939 andres@anarazel.de        177                 :         153653 :     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                 :                :      */
                                187                 :         153653 :     enlargeStringInfo(buf, (NAMEDATALEN * MAX_CONVERSION_GROWTH /* attname */
                                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                 :                : 
 8212 tgl@sss.pgh.pa.us         196         [ +  + ]:         657508 :     for (i = 0; i < natts; ++i)
                                197                 :                :     {
 2991 andres@anarazel.de        198                 :         503855 :         Form_pg_attribute att = TupleDescAttr(typeinfo, i);
                                199                 :         503855 :         Oid         atttypid = att->atttypid;
                                200                 :         503855 :         int32       atttypmod = att->atttypmod;
                                201                 :                :         Oid         resorigtbl;
                                202                 :                :         AttrNumber  resorigcol;
                                203                 :                :         int16       format;
                                204                 :                : 
                                205                 :                :         /*
                                206                 :                :          * If column is a domain, send the base type and typmod instead.
                                207                 :                :          * Lookup before sending any ints, for efficiency.
                                208                 :                :          */
 2939                           209                 :         503855 :         atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
                                210                 :                : 
                                211                 :                :         /* Do we have a non-resjunk tlist item? */
                                212         [ +  + ]:         503855 :         while (tlist_item &&
                                213         [ -  + ]:         495285 :                ((TargetEntry *) lfirst(tlist_item))->resjunk)
 2297 tgl@sss.pgh.pa.us         214                 :UBC           0 :             tlist_item = lnext(targetlist, tlist_item);
 2939 andres@anarazel.de        215         [ +  + ]:CBC      503855 :         if (tlist_item)
                                216                 :                :         {
                                217                 :         495285 :             TargetEntry *tle = (TargetEntry *) lfirst(tlist_item);
                                218                 :                : 
                                219                 :         495285 :             resorigtbl = tle->resorigtbl;
                                220                 :         495285 :             resorigcol = tle->resorigcol;
 2297 tgl@sss.pgh.pa.us         221                 :         495285 :             tlist_item = lnext(targetlist, tlist_item);
                                222                 :                :         }
                                223                 :                :         else
                                224                 :                :         {
                                225                 :                :             /* No info available, so send zeroes */
 2939 andres@anarazel.de        226                 :           8570 :             resorigtbl = 0;
                                227                 :           8570 :             resorigcol = 0;
                                228                 :                :         }
                                229                 :                : 
                                230         [ +  + ]:         503855 :         if (formats)
                                231                 :         503684 :             format = formats[i];
                                232                 :                :         else
                                233                 :            171 :             format = 0;
                                234                 :                : 
                                235                 :         503855 :         pq_writestring(buf, NameStr(att->attname));
                                236                 :         503855 :         pq_writeint32(buf, resorigtbl);
                                237                 :         503855 :         pq_writeint16(buf, resorigcol);
                                238                 :         503855 :         pq_writeint32(buf, atttypid);
                                239                 :         503855 :         pq_writeint16(buf, att->attlen);
                                240                 :         503855 :         pq_writeint32(buf, atttypmod);
                                241                 :         503855 :         pq_writeint16(buf, format);
                                242                 :                :     }
                                243                 :                : 
 1699 heikki.linnakangas@i      244                 :         153653 :     pq_endmessage_reuse(buf);
 8212 tgl@sss.pgh.pa.us         245                 :         153653 : }
                                246                 :                : 
                                247                 :                : /*
                                248                 :                :  * Get the lookup info that printtup() needs
                                249                 :                :  */
                                250                 :                : static void
 9653 bruce@momjian.us          251                 :         126847 : printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
                                252                 :                : {
 8208 tgl@sss.pgh.pa.us         253                 :         126847 :     int16      *formats = myState->portal->formats;
                                254                 :                :     int         i;
                                255                 :                : 
                                256                 :                :     /* get rid of any old data */
 9771                           257         [ +  + ]:         126847 :     if (myState->myinfo)
 7816                           258                 :            614 :         pfree(myState->myinfo);
 9771                           259                 :         126847 :     myState->myinfo = NULL;
                                260                 :                : 
                                261                 :         126847 :     myState->attrinfo = typeinfo;
                                262                 :         126847 :     myState->nattrs = numAttrs;
                                263         [ +  + ]:         126847 :     if (numAttrs <= 0)
                                264                 :            125 :         return;
                                265                 :                : 
 9653 bruce@momjian.us          266                 :         126722 :     myState->myinfo = (PrinttupAttrInfo *)
 8208 tgl@sss.pgh.pa.us         267                 :         126722 :         palloc0(numAttrs * sizeof(PrinttupAttrInfo));
                                268                 :                : 
 9771                           269         [ +  + ]:         521995 :     for (i = 0; i < numAttrs; i++)
                                270                 :                :     {
 9653 bruce@momjian.us          271                 :         395273 :         PrinttupAttrInfo *thisState = myState->myinfo + i;
 8208 tgl@sss.pgh.pa.us         272         [ +  + ]:         395273 :         int16       format = (formats ? formats[i] : 0);
 2991 andres@anarazel.de        273                 :         395273 :         Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
                                274                 :                : 
 8208 tgl@sss.pgh.pa.us         275                 :         395273 :         thisState->format = format;
                                276         [ +  + ]:         395273 :         if (format == 0)
                                277                 :                :         {
 2991 andres@anarazel.de        278                 :         395234 :             getTypeOutputInfo(attr->atttypid,
                                279                 :                :                               &thisState->typoutput,
                                280                 :                :                               &thisState->typisvarlena);
 9771 tgl@sss.pgh.pa.us         281                 :         395234 :             fmgr_info(thisState->typoutput, &thisState->finfo);
                                282                 :                :         }
 8208                           283         [ +  - ]:             39 :         else if (format == 1)
                                284                 :                :         {
 2991 andres@anarazel.de        285                 :             39 :             getTypeBinaryOutputInfo(attr->atttypid,
                                286                 :                :                                     &thisState->typsend,
                                287                 :                :                                     &thisState->typisvarlena);
 8208 tgl@sss.pgh.pa.us         288                 :             39 :             fmgr_info(thisState->typsend, &thisState->finfo);
                                289                 :                :         }
                                290                 :                :         else
 8135 tgl@sss.pgh.pa.us         291         [ #  # ]:UBC           0 :             ereport(ERROR,
                                292                 :                :                     (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                293                 :                :                      errmsg("unsupported format code: %d", format)));
                                294                 :                :     }
                                295                 :                : }
                                296                 :                : 
                                297                 :                : /* ----------------
                                298                 :                :  *      printtup --- send a tuple to the client
                                299                 :                :  *
                                300                 :                :  * Note: if you change this function, see also serializeAnalyzeReceive
                                301                 :                :  * in explain.c, which is meant to replicate the computations done here.
                                302                 :                :  * ----------------
                                303                 :                :  */
                                304                 :                : static bool
 7531 tgl@sss.pgh.pa.us         305                 :CBC     3728120 : printtup(TupleTableSlot *slot, DestReceiver *self)
                                306                 :                : {
 7318 bruce@momjian.us          307                 :        3728120 :     TupleDesc   typeinfo = slot->tts_tupleDescriptor;
 8209 tgl@sss.pgh.pa.us         308                 :        3728120 :     DR_printtup *myState = (DR_printtup *) self;
                                309                 :                :     MemoryContext oldcontext;
 2939 andres@anarazel.de        310                 :        3728120 :     StringInfo  buf = &myState->buf;
 8191 tgl@sss.pgh.pa.us         311                 :        3728120 :     int         natts = typeinfo->natts;
                                312                 :                :     int         i;
                                313                 :                : 
                                314                 :                :     /* Set or update my derived attribute info, if needed */
 8209                           315   [ +  +  -  + ]:        3728120 :     if (myState->attrinfo != typeinfo || myState->nattrs != natts)
                                316                 :         126847 :         printtup_prepare_info(myState, typeinfo, natts);
                                317                 :                : 
                                318                 :                :     /* Make sure the tuple is fully deconstructed */
 7531                           319                 :        3728120 :     slot_getallattrs(slot);
                                320                 :                : 
                                321                 :                :     /* Switch into per-row context so we can recover memory below */
 4377                           322                 :        3728120 :     oldcontext = MemoryContextSwitchTo(myState->tmpcontext);
                                323                 :                : 
                                324                 :                :     /*
                                325                 :                :      * Prepare a DataRow message (note buffer is in per-query context)
                                326                 :                :      */
  468 nathan@postgresql.or      327                 :        3728120 :     pq_beginmessage_reuse(buf, PqMsg_DataRow);
                                328                 :                : 
 2939 andres@anarazel.de        329                 :        3728120 :     pq_sendint16(buf, natts);
                                330                 :                : 
                                331                 :                :     /*
                                332                 :                :      * send the attributes of this tuple
                                333                 :                :      */
 8209 tgl@sss.pgh.pa.us         334         [ +  + ]:       22074229 :     for (i = 0; i < natts; ++i)
                                335                 :                :     {
                                336                 :       18346109 :         PrinttupAttrInfo *thisState = myState->myinfo + i;
 4377                           337                 :       18346109 :         Datum       attr = slot->tts_values[i];
                                338                 :                : 
 7531                           339         [ +  + ]:       18346109 :         if (slot->tts_isnull[i])
                                340                 :                :         {
 2939 andres@anarazel.de        341                 :        1002733 :             pq_sendint32(buf, -1);
 8209 tgl@sss.pgh.pa.us         342                 :        1002733 :             continue;
                                343                 :                :         }
                                344                 :                : 
                                345                 :                :         /*
                                346                 :                :          * Here we catch undefined bytes in datums that are returned to the
                                347                 :                :          * client without hitting disk; see comments at the related check in
                                348                 :                :          * PageAddItem().  This test is most useful for uncompressed,
                                349                 :                :          * non-external datums, but we're quite likely to see such here when
                                350                 :                :          * testing new C functions.
                                351                 :                :          */
 8208                           352                 :       17343376 :         if (thisState->typisvarlena)
                                353                 :                :             VALGRIND_CHECK_MEM_IS_DEFINED(DatumGetPointer(attr),
                                354                 :                :                                           VARSIZE_ANY(DatumGetPointer(attr)));
                                355                 :                : 
                                356         [ +  + ]:       17343376 :         if (thisState->format == 0)
                                357                 :                :         {
                                358                 :                :             /* Text output */
                                359                 :                :             char       *outputstr;
                                360                 :                : 
 7147                           361                 :       17336359 :             outputstr = OutputFunctionCall(&thisState->finfo, attr);
  603 heikki.linnakangas@i      362                 :       17336359 :             pq_sendcountedtext(buf, outputstr, strlen(outputstr));
                                363                 :                :         }
                                364                 :                :         else
                                365                 :                :         {
                                366                 :                :             /* Binary output */
                                367                 :                :             bytea      *outputbytes;
                                368                 :                : 
 7147 tgl@sss.pgh.pa.us         369                 :           7017 :             outputbytes = SendFunctionCall(&thisState->finfo, attr);
 2939 andres@anarazel.de        370                 :           7017 :             pq_sendint32(buf, VARSIZE(outputbytes) - VARHDRSZ);
                                371                 :           7017 :             pq_sendbytes(buf, VARDATA(outputbytes),
 8208 tgl@sss.pgh.pa.us         372                 :           7017 :                          VARSIZE(outputbytes) - VARHDRSZ);
                                373                 :                :         }
                                374                 :                :     }
                                375                 :                : 
 2939 andres@anarazel.de        376                 :        3728120 :     pq_endmessage_reuse(buf);
                                377                 :                : 
                                378                 :                :     /* Return to caller's context, and flush row's temporary memory */
 4377 tgl@sss.pgh.pa.us         379                 :        3728120 :     MemoryContextSwitchTo(oldcontext);
                                380                 :        3728120 :     MemoryContextReset(myState->tmpcontext);
                                381                 :                : 
 3431 rhaas@postgresql.org      382                 :        3728120 :     return true;
                                383                 :                : }
                                384                 :                : 
                                385                 :                : /* ----------------
                                386                 :                :  *      printtup_shutdown
                                387                 :                :  * ----------------
                                388                 :                :  */
                                389                 :                : static void
 8211 tgl@sss.pgh.pa.us         390                 :         149940 : printtup_shutdown(DestReceiver *self)
                                391                 :                : {
 9653 bruce@momjian.us          392                 :         149940 :     DR_printtup *myState = (DR_printtup *) self;
                                393                 :                : 
 9771 tgl@sss.pgh.pa.us         394         [ +  + ]:         149940 :     if (myState->myinfo)
                                395                 :         126010 :         pfree(myState->myinfo);
 8211                           396                 :         149940 :     myState->myinfo = NULL;
                                397                 :                : 
                                398                 :         149940 :     myState->attrinfo = NULL;
                                399                 :                : 
 2416                           400         [ +  - ]:         149940 :     if (myState->buf.data)
                                401                 :         149940 :         pfree(myState->buf.data);
                                402                 :         149940 :     myState->buf.data = NULL;
                                403                 :                : 
 4377                           404         [ +  - ]:         149940 :     if (myState->tmpcontext)
                                405                 :         149940 :         MemoryContextDelete(myState->tmpcontext);
                                406                 :         149940 :     myState->tmpcontext = NULL;
 8211                           407                 :         149940 : }
                                408                 :                : 
                                409                 :                : /* ----------------
                                410                 :                :  *      printtup_destroy
                                411                 :                :  * ----------------
                                412                 :                :  */
                                413                 :                : static void
                                414                 :         296698 : printtup_destroy(DestReceiver *self)
                                415                 :                : {
                                416                 :         296698 :     pfree(self);
 9771                           417                 :         296698 : }
                                418                 :                : 
                                419                 :                : /* ----------------
                                420                 :                :  *      printatt
                                421                 :                :  * ----------------
                                422                 :                :  */
                                423                 :                : static void
10703 scrappy@hub.org           424                 :            214 : printatt(unsigned attributeId,
                                425                 :                :          Form_pg_attribute attributeP,
                                426                 :                :          char *value)
                                427                 :                : {
10029 bruce@momjian.us          428   [ +  +  +  +  :            214 :     printf("\t%2d: %s%s%s%s\t(typeid = %u, len = %d, typmod = %d, byval = %c)\n",
                                        +  +  +  + ]
                                429                 :                :            attributeId,
                                430                 :                :            NameStr(attributeP->attname),
                                431                 :                :            value != NULL ? " = \"" : "",
                                432                 :                :            value != NULL ? value : "",
                                433                 :                :            value != NULL ? "\"" : "",
                                434                 :                :            (unsigned int) (attributeP->atttypid),
                                435                 :                :            attributeP->attlen,
                                436                 :                :            attributeP->atttypmod,
                                437                 :                :            attributeP->attbyval ? 't' : 'f');
10703 scrappy@hub.org           438                 :            214 : }
                                439                 :                : 
                                440                 :                : /* ----------------
                                441                 :                :  *      debugStartup - prepare to print tuples for an interactive backend
                                442                 :                :  * ----------------
                                443                 :                :  */
                                444                 :                : void
 8209 tgl@sss.pgh.pa.us         445                 :            106 : debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
                                446                 :                : {
                                447                 :            106 :     int         natts = typeinfo->natts;
                                448                 :                :     int         i;
                                449                 :                : 
                                450                 :                :     /*
                                451                 :                :      * show the return type of the tuples
                                452                 :                :      */
                                453         [ +  + ]:            212 :     for (i = 0; i < natts; ++i)
 2991 andres@anarazel.de        454                 :            106 :         printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
 8209 tgl@sss.pgh.pa.us         455                 :            106 :     printf("\t----\n");
 8644                           456                 :            106 : }
                                457                 :                : 
                                458                 :                : /* ----------------
                                459                 :                :  *      debugtup - print one tuple for an interactive backend
                                460                 :                :  * ----------------
                                461                 :                :  */
                                462                 :                : bool
 7531                           463                 :            108 : debugtup(TupleTableSlot *slot, DestReceiver *self)
                                464                 :                : {
                                465                 :            108 :     TupleDesc   typeinfo = slot->tts_tupleDescriptor;
 8191                           466                 :            108 :     int         natts = typeinfo->natts;
                                467                 :                :     int         i;
                                468                 :                :     Datum       attr;
                                469                 :                :     char       *value;
                                470                 :                :     bool        isnull;
                                471                 :                :     Oid         typoutput;
                                472                 :                :     bool        typisvarlena;
                                473                 :                : 
 9097                           474         [ +  + ]:            216 :     for (i = 0; i < natts; ++i)
                                475                 :                :     {
 4377                           476                 :            108 :         attr = slot_getattr(slot, i + 1, &isnull);
 9774                           477         [ -  + ]:            108 :         if (isnull)
 9774 tgl@sss.pgh.pa.us         478                 :UBC           0 :             continue;
 2991 andres@anarazel.de        479                 :CBC         108 :         getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
                                480                 :                :                           &typoutput, &typisvarlena);
                                481                 :                : 
 7147 tgl@sss.pgh.pa.us         482                 :            108 :         value = OidOutputFunctionCall(typoutput, attr);
                                483                 :                : 
 2991 andres@anarazel.de        484                 :            108 :         printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
                                485                 :                :     }
10278 bruce@momjian.us          486                 :            108 :     printf("\t----\n");
                                487                 :                : 
 3431 rhaas@postgresql.org      488                 :            108 :     return true;
                                489                 :                : }
        

Generated by: LCOV version 2.4-beta