Hi, A comment in tqueue.c says that the bytes return by shm_mq_receive() "had better be sufficiently aligned", before assigning the pointer to htup.t_data. Then it copies htup and returns the copy (and it did so in the earlier version that had all the remapping stuff, too, but sometimes it deformed it directly so it really did need to be suitably aligned in that case IIUC).
Given that shm_mq.c proudly documents that it avoids copying the data on the receiving side (unless it has to reconstruct a message that was split up), and given that it promises that the pointed-to data remains valid until your next call, it seems that it should be safe to return a pointer to the same HeapTupleData object every time (perhaps a member of the TupleQueueReader struct) and just adjust its t_data and t_len members every time, so that the gather node emits tuples directly from the shared memory queue (and then of course tell the slot not to pfree()). Alternatively, if the value returned by shm_mq_receive() is not really suitably aligned, then the comment is a bit misleading. -- Thomas Munro https://enterprisedb.com