MemTuple ExecCopySlotMemTupleTo(TupleTableSlot *slot, MemoryContext pctxt, char *dest, unsigned int *len) { uint32 dumlen; MemTuple mtup = NULL; Assert(!TupIsNull(slot)); Assert(slot->tts_mt_bind); if(!len) len = &dumlen; if (TupHasMemTuple(slot)) { mtup = memtuple_copy_to(slot->PRIVATE_tts_memtuple, slot->tts_mt_bind, (MemTuple) dest, len); if(mtup || !pctxt) return mtup; mtup = (MemTuple) ctxt_alloc(pctxt, *len); mtup = memtuple_copy_to(slot->PRIVATE_tts_memtuple, slot->tts_mt_bind, mtup, len); Assert(mtup); return mtup; } slot_getallattrs(slot); mtup = memtuple_form_to(slot->tts_mt_bind, slot_get_values(slot), slot_get_isnull(slot), (MemTuple) dest, len, false); if(mtup || !pctxt) return mtup; mtup = (MemTuple) ctxt_alloc(pctxt, *len); mtup = memtuple_form_to(slot->tts_mt_bind, slot_get_values(slot), slot_get_isnull(slot), mtup, len, false); Assert(mtup); return mtup; }
/* * tuplestore_gettupleslot - exported function to fetch a tuple into a slot * * If successful, put tuple in slot and return TRUE; else, clear the slot * and return FALSE. * * If copy is TRUE, the slot receives a copied tuple (allocated in current * memory context) that will stay valid regardless of future manipulations of * the tuplestore's state. If copy is FALSE, the slot may just receive a * pointer to a tuple held within the tuplestore. The latter is more * efficient but the slot contents may be corrupted if additional writes to * the tuplestore occur. (If using tuplestore_trim, see comments therein.) */ bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot) { GenericTuple tuple; bool should_free; tuple = tuplestore_gettuple(state, forward, &should_free); if (tuple) { if (copy && !should_free) { if (is_memtuple(tuple)) tuple = (GenericTuple) memtuple_copy_to((MemTuple) tuple, NULL, NULL); else tuple = (GenericTuple) heap_copytuple((HeapTuple) tuple); should_free = true; } ExecStoreGenericTuple(tuple, slot, should_free); return true; } else { ExecClearTuple(slot); return false; } }
static void * copytup_heap(Tuplestorestate *state, TuplestorePos *pos, void *tup) { if(!is_heaptuple_memtuple((HeapTuple) tup)) return heaptuple_copy_to((HeapTuple) tup, NULL, NULL); return memtuple_copy_to((MemTuple) tup, NULL, NULL, NULL); }
static void * copytup_heap(Tuplestorestate *state, void *tup) { if (!is_memtuple((GenericTuple) tup)) return heaptuple_copy_to((HeapTuple) tup, NULL, NULL); else return memtuple_copy_to((MemTuple) tup, NULL, NULL); }
/* -------------------------------- * ExecCopySlotMinimalTuple * Obtain a copy of a slot's minimal physical tuple. The copy is * palloc'd in the current memory context. * -------------------------------- */ MemTuple ExecCopySlotMemTuple(TupleTableSlot *slot) { /* * sanity checks */ Assert(!TupIsNull(slot)); Assert(slot->tts_mt_bind); /* * If we have a physical tuple then just copy it. */ if (slot->PRIVATE_tts_memtuple) return memtuple_copy_to(slot->PRIVATE_tts_memtuple, slot->tts_mt_bind, NULL, NULL); slot_getallattrs(slot); /* * Otherwise we need to build a tuple from the Datum array. */ return memtuple_form_to(slot->tts_mt_bind, slot_get_values(slot), slot_get_isnull(slot), NULL, 0, false); }