Honour client's request for binary data transfer.
authorPavan Deolasee <[email protected]>
Thu, 3 Mar 2016 11:40:41 +0000 (17:10 +0530)
committerPavan Deolasee <[email protected]>
Thu, 3 Mar 2016 11:40:41 +0000 (17:10 +0530)
When coordinator gets data from the datanode, it always gets it in TEXT mode.
But if the client has requested binary transfer of the data, then it must not
forward the data received from the datanode as it is. Rather it must send each
column in the desired format.

While this should fix the JDBC or libpq issue with binary data transfer, we
should really see if the coordinator to datanode communication can also use
binary mode for performance reason. But thats a separate patch.

src/backend/access/common/printtup.c

index 199e73fab93fa146fed3a082aaeab748bb478d24..31712da34bc5380bc9bd0abf2b920bd98d4b3fd1 100644 (file)
@@ -326,23 +326,38 @@ printtup(TupleTableSlot *slot, DestReceiver *self)
        StringInfoData buf;
        int                     natts = typeinfo->natts;
        int                     i;
+       bool            binary = false;
+
+       /* Set or update my derived attribute info, if needed */
+       if (myState->attrinfo != typeinfo || myState->nattrs != natts)
+               printtup_prepare_info(myState, typeinfo, natts);
 
 #ifdef PGXC
+       /*
+        * The datanodes would have sent all attributes in TEXT form. But
+        * if the client has asked for any attribute to be sent in a binary format,
+        * then we must decode the datarow and send every attribute in the format
+        * that the client has asked for. Otherwise its ok to just forward the
+        * datarow as it is
+        */
+       for (i = 0; i < natts; ++i)
+       {
+               PrinttupAttrInfo *thisState = myState->myinfo + i;
+               if (thisState->format != 0)
+                       binary = true;
+       }
        /*
         * If we are having DataRow-based tuple we do not have to encode attribute
         * values, just send over the DataRow message as we received it from the
         * Datanode
         */
-       if (slot->tts_datarow)
+       if (slot->tts_datarow && !binary)
        {
                pq_putmessage('D', slot->tts_datarow->msg, slot->tts_datarow->msglen);
                return;
        }
 #endif
 
-       /* Set or update my derived attribute info, if needed */
-       if (myState->attrinfo != typeinfo || myState->nattrs != natts)
-               printtup_prepare_info(myState, typeinfo, natts);
 
        /* Make sure the tuple is fully deconstructed */
        slot_getallattrs(slot);