static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo) { DR_printtup *myState = (DR_printtup *) self; Portal portal = myState->portal; /* create buffer to be used for all messages */ initStringInfo(&myState->buf); /* * Create a temporary memory context that we can reset once per row to * recover palloc'd memory. This avoids any problems with leaks inside * datatype output routines, and should be faster than retail pfree's * anyway. */ myState->tmpcontext = AllocSetContextCreate(CurrentMemoryContext, "printtup", ALLOCSET_DEFAULT_SIZES); if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3) { /* * Send portal name to frontend (obsolete cruft, gone in proto 3.0) * * If portal name not specified, use "blank" portal. */ const char *portalName = portal->name; if (portalName == NULL || portalName[0] == '\0') portalName = "blank"; pq_puttextmessage('P', portalName); } /* * If we are supposed to emit row descriptions, then send the tuple * descriptor of the tuples. */ if (myState->sendDescrip) SendRowDescriptionMessage(&myState->buf, typeinfo, FetchPortalTargetList(portal), portal->formats); /* ---------------- * We could set up the derived attr info at this time, but we postpone it * until the first call of printtup, for 2 reasons: * 1. We don't waste time (compared to the old way) if there are no * tuples at all to output. * 2. Checking in printtup allows us to handle the case that the tuples * change type midway through (although this probably can't happen in * the current executor). * ---------------- */ }
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo) { DR_printtup *myState = (DR_printtup *) self; Portal portal = myState->portal; if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3) { /* * Send portal name to frontend (obsolete cruft, gone in proto 3.0) * * If portal name not specified, use "blank" portal. */ const char *portalName = portal->name; if (portalName == NULL || portalName[0] == '\0') portalName = "blank"; pq_puttextmessage('P', portalName); } /* * If we are supposed to emit row descriptions, then send the tuple * descriptor of the tuples. */ if (myState->sendDescrip) SendRowDescriptionMessage(typeinfo, FetchPortalTargetList(portal), portal->formats); /* ---------------- * We could set up the derived attr info at this time, but we postpone it * until the first call of printtup, for 2 reasons: * 1. We don't waste time (compared to the old way) if there are no * tuples at all to output. * 2. Checking in printtup allows us to handle the case that the tuples * change type midway through (although this probably can't happen in * the current executor). * ---------------- */ }