Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

execTuples.c File Reference

#include "postgres.h"
#include "access/htup_details.h"
#include "funcapi.h"
#include "catalog/pg_type.h"
#include "nodes/nodeFuncs.h"
#include "storage/bufmgr.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/typcache.h"
Include dependency graph for execTuples.c:

Go to the source code of this file.

Functions

static TupleDesc ExecTypeFromTLInternal (List *targetList, bool hasoid, bool skipjunk)
TupleTableSlotMakeTupleTableSlot (void)
TupleTableSlotExecAllocTableSlot (List **tupleTable)
void ExecResetTupleTable (List *tupleTable, bool shouldFree)
TupleTableSlotMakeSingleTupleTableSlot (TupleDesc tupdesc)
void ExecDropSingleTupleTableSlot (TupleTableSlot *slot)
void ExecSetSlotDescriptor (TupleTableSlot *slot, TupleDesc tupdesc)
TupleTableSlotExecStoreTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
TupleTableSlotExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
TupleTableSlotExecClearTuple (TupleTableSlot *slot)
TupleTableSlotExecStoreVirtualTuple (TupleTableSlot *slot)
TupleTableSlotExecStoreAllNullTuple (TupleTableSlot *slot)
HeapTuple ExecCopySlotTuple (TupleTableSlot *slot)
MinimalTuple ExecCopySlotMinimalTuple (TupleTableSlot *slot)
HeapTuple ExecFetchSlotTuple (TupleTableSlot *slot)
MinimalTuple ExecFetchSlotMinimalTuple (TupleTableSlot *slot)
Datum ExecFetchSlotTupleDatum (TupleTableSlot *slot)
HeapTuple ExecMaterializeSlot (TupleTableSlot *slot)
TupleTableSlotExecCopySlot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
void ExecInitResultTupleSlot (EState *estate, PlanState *planstate)
void ExecInitScanTupleSlot (EState *estate, ScanState *scanstate)
TupleTableSlotExecInitExtraTupleSlot (EState *estate)
TupleTableSlotExecInitNullTupleSlot (EState *estate, TupleDesc tupType)
TupleDesc ExecTypeFromTL (List *targetList, bool hasoid)
TupleDesc ExecCleanTypeFromTL (List *targetList, bool hasoid)
TupleDesc ExecTypeFromExprList (List *exprList, List *namesList)
TupleDesc BlessTupleDesc (TupleDesc tupdesc)
TupleTableSlotTupleDescGetSlot (TupleDesc tupdesc)
AttInMetadataTupleDescGetAttInMetadata (TupleDesc tupdesc)
HeapTuple BuildTupleFromCStrings (AttInMetadata *attinmeta, char **values)
TupOutputStatebegin_tup_output_tupdesc (DestReceiver *dest, TupleDesc tupdesc)
void do_tup_output (TupOutputState *tstate, Datum *values, bool *isnull)
void do_text_output_multiline (TupOutputState *tstate, char *text)
void end_tup_output (TupOutputState *tstate)

Function Documentation

TupOutputState* begin_tup_output_tupdesc ( DestReceiver dest,
TupleDesc  tupdesc 
)

Definition at line 1142 of file execTuples.c.

References TupOutputState::dest, MakeSingleTupleTableSlot(), palloc(), _DestReceiver::rStartup, and TupOutputState::slot.

Referenced by ExplainQuery(), ShowAllGUCConfig(), and ShowGUCConfigOption().

{
    TupOutputState *tstate;

    tstate = (TupOutputState *) palloc(sizeof(TupOutputState));

    tstate->slot = MakeSingleTupleTableSlot(tupdesc);
    tstate->dest = dest;

    (*tstate->dest->rStartup) (tstate->dest, (int) CMD_SELECT, tupdesc);

    return tstate;
}

TupleDesc BlessTupleDesc ( TupleDesc  tupdesc  ) 
HeapTuple BuildTupleFromCStrings ( AttInMetadata attinmeta,
char **  values 
)

Definition at line 1085 of file execTuples.c.

References AttInMetadata::attinfuncs, AttInMetadata::attioparams, tupleDesc::attrs, AttInMetadata::atttypmods, heap_form_tuple(), i, InputFunctionCall(), tupleDesc::natts, NULL, palloc(), pfree(), and AttInMetadata::tupdesc.

Referenced by bt_metap(), bt_page_items(), bt_page_stats(), build_pgstattuple_type(), build_tuplestore_recursively(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), materializeQueryResult(), materializeResult(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls(), pgrowlocks(), pgstatindex(), prs_process_call(), show_all_settings(), storeRow(), ts_process_call(), tt_process_call(), and xpath_table().

{
    TupleDesc   tupdesc = attinmeta->tupdesc;
    int         natts = tupdesc->natts;
    Datum      *dvalues;
    bool       *nulls;
    int         i;
    HeapTuple   tuple;

    dvalues = (Datum *) palloc(natts * sizeof(Datum));
    nulls = (bool *) palloc(natts * sizeof(bool));

    /* Call the "in" function for each non-dropped attribute */
    for (i = 0; i < natts; i++)
    {
        if (!tupdesc->attrs[i]->attisdropped)
        {
            /* Non-dropped attributes */
            dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
                                           values[i],
                                           attinmeta->attioparams[i],
                                           attinmeta->atttypmods[i]);
            if (values[i] != NULL)
                nulls[i] = false;
            else
                nulls[i] = true;
        }
        else
        {
            /* Handle dropped attributes by setting to NULL */
            dvalues[i] = (Datum) 0;
            nulls[i] = true;
        }
    }

    /*
     * Form a tuple
     */
    tuple = heap_form_tuple(tupdesc, dvalues, nulls);

    /*
     * Release locally palloc'd space.  XXX would probably be good to pfree
     * values of pass-by-reference datums, as well.
     */
    pfree(dvalues);
    pfree(nulls);

    return tuple;
}

void do_text_output_multiline ( TupOutputState tstate,
char *  text 
)

Definition at line 1188 of file execTuples.c.

References cstring_to_text_with_len(), DatumGetPointer, do_tup_output(), pfree(), PointerGetDatum, and values.

Referenced by ExplainQuery().

{
    Datum       values[1];
    bool        isnull[1] = {false};

    while (*text)
    {
        char       *eol;
        int         len;

        eol = strchr(text, '\n');
        if (eol)
        {
            len = eol - text;

            eol++;
        }
        else
        {
            len = strlen(text);
            eol += len;
        }

        values[0] = PointerGetDatum(cstring_to_text_with_len(text, len));
        do_tup_output(tstate, values, isnull);
        pfree(DatumGetPointer(values[0]));
        text = eol;
    }
}

void do_tup_output ( TupOutputState tstate,
Datum values,
bool isnull 
)

Definition at line 1160 of file execTuples.c.

References TupOutputState::dest, ExecClearTuple(), ExecStoreVirtualTuple(), tupleDesc::natts, _DestReceiver::receiveSlot, TupOutputState::slot, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by do_text_output_multiline(), and ShowAllGUCConfig().

{
    TupleTableSlot *slot = tstate->slot;
    int         natts = slot->tts_tupleDescriptor->natts;

    /* make sure the slot is clear */
    ExecClearTuple(slot);

    /* insert data */
    memcpy(slot->tts_values, values, natts * sizeof(Datum));
    memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));

    /* mark slot as containing a virtual tuple */
    ExecStoreVirtualTuple(slot);

    /* send the tuple to the receiver */
    (*tstate->dest->receiveSlot) (slot, tstate->dest);

    /* clean up */
    ExecClearTuple(slot);
}

void end_tup_output ( TupOutputState tstate  ) 

Definition at line 1219 of file execTuples.c.

References TupOutputState::dest, ExecDropSingleTupleTableSlot(), pfree(), _DestReceiver::rShutdown, and TupOutputState::slot.

Referenced by ExplainQuery(), ShowAllGUCConfig(), and ShowGUCConfigOption().

{
    (*tstate->dest->rShutdown) (tstate->dest);
    /* note that destroying the dest is not ours to do */
    ExecDropSingleTupleTableSlot(tstate->slot);
    pfree(tstate);
}

TupleTableSlot* ExecAllocTableSlot ( List **  tupleTable  ) 

Definition at line 143 of file execTuples.c.

References lappend(), and MakeTupleTableSlot().

Referenced by ExecInitExtraTupleSlot(), ExecInitResultTupleSlot(), and ExecInitScanTupleSlot().

{
    TupleTableSlot *slot = MakeTupleTableSlot();

    *tupleTable = lappend(*tupleTable, slot);

    return slot;
}

TupleDesc ExecCleanTypeFromTL ( List targetList,
bool  hasoid 
)

Definition at line 915 of file execTuples.c.

References ExecTypeFromTLInternal().

Referenced by ExecInitJunkFilter(), PlanCacheComputeResultDesc(), and PortalStart().

{
    return ExecTypeFromTLInternal(targetList, hasoid, true);
}

TupleTableSlot* ExecClearTuple ( TupleTableSlot slot  ) 

Definition at line 448 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), NULL, ReleaseBuffer(), TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, and TupleTableSlot::tts_tuple.

Referenced by begin_partition(), BitmapHeapNext(), buildSubPlanHash(), CteScanNext(), do_tup_output(), eval_windowaggregates(), ExecAppend(), ExecDelete(), ExecDropSingleTupleTableSlot(), ExecEndAgg(), ExecEndBitmapHeapScan(), ExecEndCteScan(), ExecEndForeignScan(), ExecEndFunctionScan(), ExecEndGroup(), ExecEndHashJoin(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecEndMaterial(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNestLoop(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSeqScan(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndTidScan(), ExecEndUnique(), ExecEndValuesScan(), ExecEndWindowAgg(), ExecEndWorkTableScan(), ExecFilterJunk(), ExecHashJoinGetSavedTuple(), ExecHashSubPlan(), ExecMaterial(), ExecMergeAppend(), ExecProject(), ExecReScanCteScan(), ExecReScanFunctionScan(), ExecReScanGroup(), ExecReScanMaterial(), ExecReScanMergeJoin(), ExecReScanSetOp(), ExecReScanSort(), ExecReScanUnique(), ExecReScanValuesScan(), ExecReScanWindowAgg(), ExecReScanWorkTableScan(), ExecResetTupleTable(), ExecScan(), ExecScanFetch(), ExecSeqRestrPos(), ExecSetSlotDescriptor(), ExecStoreAllNullTuple(), ExecUnique(), fileIterateForeignScan(), IndexNext(), IndexOnlyNext(), per_MultiFuncCall(), postgresIterateForeignScan(), process_ordered_aggregate_multi(), RunFromStore(), SeqNext(), setop_retrieve_direct(), setop_retrieve_hash_table(), ShutdownFuncExpr(), StoreIndexTuple(), TidNext(), tuplesort_gettupleslot(), tuplestore_gettupleslot(), ValuesNext(), and WinRowsArePeers().

{
    /*
     * sanity checks
     */
    Assert(slot != NULL);

    /*
     * Free the old physical tuple if necessary.
     */
    if (slot->tts_shouldFree)
        heap_freetuple(slot->tts_tuple);
    if (slot->tts_shouldFreeMin)
        heap_free_minimal_tuple(slot->tts_mintuple);

    slot->tts_tuple = NULL;
    slot->tts_mintuple = NULL;
    slot->tts_shouldFree = false;
    slot->tts_shouldFreeMin = false;

    /*
     * Drop the pin on the referenced buffer, if there is one.
     */
    if (BufferIsValid(slot->tts_buffer))
        ReleaseBuffer(slot->tts_buffer);

    slot->tts_buffer = InvalidBuffer;

    /*
     * Mark it empty.
     */
    slot->tts_isempty = true;
    slot->tts_nvalid = 0;

    return slot;
}

TupleTableSlot* ExecCopySlot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)

Definition at line 810 of file execTuples.c.

References ExecCopySlotTuple(), ExecStoreTuple(), InvalidBuffer, MemoryContextSwitchTo(), and TupleTableSlot::tts_mcxt.

Referenced by begin_partition(), CteScanNext(), ExecGroup(), ExecUnique(), and spool_tuples().

{
    HeapTuple   newTuple;
    MemoryContext oldContext;

    /*
     * There might be ways to optimize this when the source is virtual, but
     * for now just always build a physical copy.  Make sure it is in the
     * right context.
     */
    oldContext = MemoryContextSwitchTo(dstslot->tts_mcxt);
    newTuple = ExecCopySlotTuple(srcslot);
    MemoryContextSwitchTo(oldContext);

    return ExecStoreTuple(newTuple, dstslot, InvalidBuffer, true);
}

MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot slot  ) 

Definition at line 586 of file execTuples.c.

References Assert, heap_copy_minimal_tuple(), heap_form_minimal_tuple(), minimal_tuple_from_heap_tuple(), NULL, TupleTableSlot::tts_isempty, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by copytup_heap(), ExecFetchSlotMinimalTuple(), LookupTupleHashEntry(), and tuplestore_puttupleslot().

{
    /*
     * sanity checks
     */
    Assert(slot != NULL);
    Assert(!slot->tts_isempty);

    /*
     * If we have a physical tuple then just copy it.  Prefer to copy
     * tts_mintuple since that's a tad cheaper.
     */
    if (slot->tts_mintuple)
        return heap_copy_minimal_tuple(slot->tts_mintuple);
    if (slot->tts_tuple)
        return minimal_tuple_from_heap_tuple(slot->tts_tuple);

    /*
     * Otherwise we need to build a tuple from the Datum array.
     */
    return heap_form_minimal_tuple(slot->tts_tupleDescriptor,
                                   slot->tts_values,
                                   slot->tts_isnull);
}

HeapTuple ExecCopySlotTuple ( TupleTableSlot slot  ) 
void ExecDropSingleTupleTableSlot ( TupleTableSlot slot  ) 
MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot  ) 

Definition at line 661 of file execTuples.c.

References Assert, ExecCopySlotMinimalTuple(), MemoryContextSwitchTo(), NULL, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_mintuple, and TupleTableSlot::tts_shouldFreeMin.

Referenced by ExecHashJoin(), ExecHashSkewTableInsert(), and ExecHashTableInsert().

{
    MemoryContext oldContext;

    /*
     * sanity checks
     */
    Assert(slot != NULL);
    Assert(!slot->tts_isempty);

    /*
     * If we have a minimal physical tuple (local or not) then just return it.
     */
    if (slot->tts_mintuple)
        return slot->tts_mintuple;

    /*
     * Otherwise, copy or build a minimal tuple, and store it into the slot.
     *
     * We may be called in a context that is shorter-lived than the tuple
     * slot, but we have to ensure that the materialized tuple will survive
     * anyway.
     */
    oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
    slot->tts_mintuple = ExecCopySlotMinimalTuple(slot);
    slot->tts_shouldFreeMin = true;
    MemoryContextSwitchTo(oldContext);

    /*
     * Note: we may now have a situation where we have a local minimal tuple
     * attached to a virtual or non-local physical tuple.  There seems no harm
     * in that at the moment, but if any materializes, we should change this
     * function to force the slot into minimal-tuple-only state.
     */

    return slot->tts_mintuple;
}

HeapTuple ExecFetchSlotTuple ( TupleTableSlot slot  ) 

Definition at line 627 of file execTuples.c.

References Assert, ExecMaterializeSlot(), NULL, TTS_HAS_PHYSICAL_TUPLE, TupleTableSlot::tts_isempty, and TupleTableSlot::tts_tuple.

Referenced by ExecEvalWholeRowFast(), and ExecEvalWholeRowSlow().

{
    /*
     * sanity checks
     */
    Assert(slot != NULL);
    Assert(!slot->tts_isempty);

    /*
     * If we have a regular physical tuple then just return it.
     */
    if (TTS_HAS_PHYSICAL_TUPLE(slot))
        return slot->tts_tuple;

    /*
     * Otherwise materialize the slot...
     */
    return ExecMaterializeSlot(slot);
}

Datum ExecFetchSlotTupleDatum ( TupleTableSlot slot  ) 

Definition at line 709 of file execTuples.c.

References ExecMaterializeSlot(), HeapTupleHeaderSetDatumLength, HeapTupleHeaderSetTypeId, HeapTupleHeaderSetTypMod, PointerGetDatum, HeapTupleData::t_data, HeapTupleData::t_len, tupleDesc::tdtypeid, tupleDesc::tdtypmod, and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecMakeFunctionResult(), and postquel_get_single_result().

{
    HeapTuple   tup;
    HeapTupleHeader td;
    TupleDesc   tupdesc;

    /* Make sure we can scribble on the slot contents ... */
    tup = ExecMaterializeSlot(slot);
    /* ... and set up the composite-Datum header fields, in case not done */
    td = tup->t_data;
    tupdesc = slot->tts_tupleDescriptor;
    HeapTupleHeaderSetDatumLength(td, tup->t_len);
    HeapTupleHeaderSetTypeId(td, tupdesc->tdtypeid);
    HeapTupleHeaderSetTypMod(td, tupdesc->tdtypmod);
    return PointerGetDatum(td);
}

TupleTableSlot* ExecInitExtraTupleSlot ( EState estate  ) 
TupleTableSlot* ExecInitNullTupleSlot ( EState estate,
TupleDesc  tupType 
)
void ExecInitResultTupleSlot ( EState estate,
PlanState planstate 
)
void ExecInitScanTupleSlot ( EState estate,
ScanState scanstate 
)
HeapTuple ExecMaterializeSlot ( TupleTableSlot slot  ) 

Definition at line 740 of file execTuples.c.

References Assert, BufferIsValid, ExecCopySlotTuple(), MemoryContextSwitchTo(), NULL, ReleaseBuffer(), TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, and TupleTableSlot::tts_tuple.

Referenced by CopyFrom(), EvalPlanQual(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecFetchSlotTuple(), ExecFetchSlotTupleDatum(), ExecInsert(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecUpdate(), ForeignNext(), intorel_receive(), and transientrel_receive().

{
    MemoryContext oldContext;

    /*
     * sanity checks
     */
    Assert(slot != NULL);
    Assert(!slot->tts_isempty);

    /*
     * If we have a regular physical tuple, and it's locally palloc'd, we have
     * nothing to do.
     */
    if (slot->tts_tuple && slot->tts_shouldFree)
        return slot->tts_tuple;

    /*
     * Otherwise, copy or build a physical tuple, and store it into the slot.
     *
     * We may be called in a context that is shorter-lived than the tuple
     * slot, but we have to ensure that the materialized tuple will survive
     * anyway.
     */
    oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
    slot->tts_tuple = ExecCopySlotTuple(slot);
    slot->tts_shouldFree = true;
    MemoryContextSwitchTo(oldContext);

    /*
     * Drop the pin on the referenced buffer, if there is one.
     */
    if (BufferIsValid(slot->tts_buffer))
        ReleaseBuffer(slot->tts_buffer);

    slot->tts_buffer = InvalidBuffer;

    /*
     * Mark extracted state invalid.  This is important because the slot is
     * not supposed to depend any more on the previous external data; we
     * mustn't leave any dangling pass-by-reference datums in tts_values.
     * However, we have not actually invalidated any such datums, if there
     * happen to be any previously fetched from the slot.  (Note in particular
     * that we have not pfree'd tts_mintuple, if there is one.)
     */
    slot->tts_nvalid = 0;

    /*
     * On the same principle of not depending on previous remote storage,
     * forget the mintuple if it's not local storage.  (If it is local
     * storage, we must not pfree it now, since callers might have already
     * fetched datum pointers referencing it.)
     */
    if (!slot->tts_shouldFreeMin)
        slot->tts_mintuple = NULL;

    return slot->tts_tuple;
}

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 162 of file execTuples.c.

References Assert, ExecClearTuple(), IsA, lfirst, list_free(), pfree(), ReleaseTupleDesc, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by CopyFrom(), EvalPlanQualEnd(), and ExecEndPlan().

{
    ListCell   *lc;

    foreach(lc, tupleTable)
    {
        TupleTableSlot *slot = (TupleTableSlot *) lfirst(lc);

        /* Sanity checks */
        Assert(IsA(slot, TupleTableSlot));

        /* Always release resources and reset the slot to empty */
        ExecClearTuple(slot);
        if (slot->tts_tupleDescriptor)
        {
            ReleaseTupleDesc(slot->tts_tupleDescriptor);
            slot->tts_tupleDescriptor = NULL;
        }

        /* If shouldFree, release memory occupied by the slot itself */
        if (shouldFree)
        {
            if (slot->tts_values)
                pfree(slot->tts_values);
            if (slot->tts_isnull)
                pfree(slot->tts_isnull);
            pfree(slot);
        }
    }

    /* If shouldFree, release the list structure */
    if (shouldFree)
        list_free(tupleTable);
}

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 256 of file execTuples.c.

References ExecClearTuple(), MemoryContextAlloc(), tupleDesc::natts, pfree(), PinTupleDesc, ReleaseTupleDesc, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by CopyFrom(), ExecAssignResultType(), ExecAssignScanType(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecInitAgg(), ExecInitHashJoin(), ExecInitJunkFilter(), ExecInitJunkFilterConversion(), ExecInitMergeJoin(), ExecInitNullTupleSlot(), ExecInitSubPlan(), ExecInitWindowAgg(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), lookup_hash_entry(), MakeSingleTupleTableSlot(), and TriggerEnabled().

{
    /* For safety, make sure slot is empty before changing it */
    ExecClearTuple(slot);

    /*
     * Release any old descriptor.  Also release old Datum/isnull arrays if
     * present (we don't bother to check if they could be re-used).
     */
    if (slot->tts_tupleDescriptor)
        ReleaseTupleDesc(slot->tts_tupleDescriptor);

    if (slot->tts_values)
        pfree(slot->tts_values);
    if (slot->tts_isnull)
        pfree(slot->tts_isnull);

    /*
     * Install the new descriptor; if it's refcounted, bump its refcount.
     */
    slot->tts_tupleDescriptor = tupdesc;
    PinTupleDesc(tupdesc);

    /*
     * Allocate Datum/isnull arrays of the appropriate size.  These must have
     * the same lifetime as the slot, so allocate in the slot's own context.
     */
    slot->tts_values = (Datum *)
        MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
    slot->tts_isnull = (bool *)
        MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(bool));
}

TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot  ) 

Definition at line 521 of file execTuples.c.

References Assert, ExecClearTuple(), ExecStoreVirtualTuple(), MemSet, tupleDesc::natts, NULL, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by ExecInitNullTupleSlot(), and lookup_hash_entry().

{
    /*
     * sanity checks
     */
    Assert(slot != NULL);
    Assert(slot->tts_tupleDescriptor != NULL);

    /* Clear any old contents */
    ExecClearTuple(slot);

    /*
     * Fill all the columns of the virtual tuple with nulls
     */
    MemSet(slot->tts_values, 0,
           slot->tts_tupleDescriptor->natts * sizeof(Datum));
    memset(slot->tts_isnull, true,
           slot->tts_tupleDescriptor->natts * sizeof(bool));

    return ExecStoreVirtualTuple(slot);
}

TupleTableSlot* ExecStoreMinimalTuple ( MinimalTuple  mtup,
TupleTableSlot slot,
bool  shouldFree 
)

Definition at line 393 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), NULL, ReleaseBuffer(), HeapTupleData::t_data, MinimalTupleData::t_len, HeapTupleData::t_len, TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_minhdr, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by agg_retrieve_hash_table(), ExecHashJoinGetSavedTuple(), ExecScanHashBucket(), ExecScanHashTableForUnmatched(), findPartialMatch(), setop_retrieve_hash_table(), TupleHashTableHash(), TupleHashTableMatch(), tuplesort_gettupleslot(), and tuplestore_gettupleslot().

{
    /*
     * sanity checks
     */
    Assert(mtup != NULL);
    Assert(slot != NULL);
    Assert(slot->tts_tupleDescriptor != NULL);

    /*
     * Free any old physical tuple belonging to the slot.
     */
    if (slot->tts_shouldFree)
        heap_freetuple(slot->tts_tuple);
    if (slot->tts_shouldFreeMin)
        heap_free_minimal_tuple(slot->tts_mintuple);

    /*
     * Drop the pin on the referenced buffer, if there is one.
     */
    if (BufferIsValid(slot->tts_buffer))
        ReleaseBuffer(slot->tts_buffer);

    slot->tts_buffer = InvalidBuffer;

    /*
     * Store the new tuple into the specified slot.
     */
    slot->tts_isempty = false;
    slot->tts_shouldFree = false;
    slot->tts_shouldFreeMin = shouldFree;
    slot->tts_tuple = &slot->tts_minhdr;
    slot->tts_mintuple = mtup;

    slot->tts_minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
    slot->tts_minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
    /* no need to set t_self or t_tableOid since we won't allow access */

    /* Mark extracted state invalid */
    slot->tts_nvalid = 0;

    return slot;
}

TupleTableSlot* ExecStoreTuple ( HeapTuple  tuple,
TupleTableSlot slot,
Buffer  buffer,
bool  shouldFree 
)

Definition at line 329 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), IncrBufferRefCount(), NULL, ReleaseBuffer(), TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by agg_retrieve_direct(), ATRewriteTable(), BitmapHeapNext(), CatalogIndexInsert(), check_exclusion_constraint(), comparetup_cluster(), compute_index_stats(), CopyFrom(), CopyFromInsertBatch(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecCopySlot(), ExecDelete(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecScanFetch(), get_actual_variable_range(), IndexBuildHeapScan(), IndexCheckExclusion(), IndexNext(), postgresIterateForeignScan(), SeqNext(), setop_retrieve_direct(), store_returning_result(), TidNext(), TriggerEnabled(), validate_index_heapscan(), and validateCheckConstraint().

{
    /*
     * sanity checks
     */
    Assert(tuple != NULL);
    Assert(slot != NULL);
    Assert(slot->tts_tupleDescriptor != NULL);
    /* passing shouldFree=true for a tuple on a disk page is not sane */
    Assert(BufferIsValid(buffer) ? (!shouldFree) : true);

    /*
     * Free any old physical tuple belonging to the slot.
     */
    if (slot->tts_shouldFree)
        heap_freetuple(slot->tts_tuple);
    if (slot->tts_shouldFreeMin)
        heap_free_minimal_tuple(slot->tts_mintuple);

    /*
     * Store the new tuple into the specified slot.
     */
    slot->tts_isempty = false;
    slot->tts_shouldFree = shouldFree;
    slot->tts_shouldFreeMin = false;
    slot->tts_tuple = tuple;
    slot->tts_mintuple = NULL;

    /* Mark extracted state invalid */
    slot->tts_nvalid = 0;

    /*
     * If tuple is on a disk page, keep the page pinned as long as we hold a
     * pointer into it.  We assume the caller already has such a pin.
     *
     * This is coded to optimize the case where the slot previously held a
     * tuple on the same disk page: in that case releasing and re-acquiring
     * the pin is a waste of cycles.  This is a common situation during
     * seqscans, so it's worth troubling over.
     */
    if (slot->tts_buffer != buffer)
    {
        if (BufferIsValid(slot->tts_buffer))
            ReleaseBuffer(slot->tts_buffer);
        slot->tts_buffer = buffer;
        if (BufferIsValid(buffer))
            IncrBufferRefCount(buffer);
    }

    return slot;
}

TupleTableSlot* ExecStoreVirtualTuple ( TupleTableSlot slot  ) 
TupleDesc ExecTypeFromExprList ( List exprList,
List namesList 
)

Definition at line 961 of file execTuples.c.

References Assert, CreateTemplateTupleDesc(), exprCollation(), exprType(), exprTypmod(), forboth, lfirst, list_length(), strVal, TupleDescInitEntry(), and TupleDescInitEntryCollation().

Referenced by ExecInitExpr(), and ExecInitValuesScan().

{
    TupleDesc   typeInfo;
    ListCell   *le;
    ListCell   *ln;
    int         cur_resno = 1;

    Assert(list_length(exprList) == list_length(namesList));

    typeInfo = CreateTemplateTupleDesc(list_length(exprList), false);

    forboth(le, exprList, ln, namesList)
    {
        Node       *e = lfirst(le);
        char       *n = strVal(lfirst(ln));

        TupleDescInitEntry(typeInfo,
                           cur_resno,
                           n,
                           exprType(e),
                           exprTypmod(e),
                           0);
        TupleDescInitEntryCollation(typeInfo,
                                    cur_resno,
                                    exprCollation(e));
        cur_resno++;
    }

    return typeInfo;
}

TupleDesc ExecTypeFromTL ( List targetList,
bool  hasoid 
)

Definition at line 903 of file execTuples.c.

References ExecTypeFromTLInternal().

Referenced by ExecAssignResultTypeFromTL(), ExecInitAgg(), ExecInitIndexOnlyScan(), ExecInitModifyTable(), and ExecInitSubPlan().

{
    return ExecTypeFromTLInternal(targetList, hasoid, false);
}

static TupleDesc ExecTypeFromTLInternal ( List targetList,
bool  hasoid,
bool  skipjunk 
) [static]

Definition at line 921 of file execTuples.c.

References CreateTemplateTupleDesc(), ExecCleanTargetListLength(), ExecTargetListLength(), TargetEntry::expr, exprCollation(), exprType(), exprTypmod(), lfirst, TargetEntry::resjunk, TargetEntry::resname, TupleDescInitEntry(), and TupleDescInitEntryCollation().

Referenced by ExecCleanTypeFromTL(), and ExecTypeFromTL().

{
    TupleDesc   typeInfo;
    ListCell   *l;
    int         len;
    int         cur_resno = 1;

    if (skipjunk)
        len = ExecCleanTargetListLength(targetList);
    else
        len = ExecTargetListLength(targetList);
    typeInfo = CreateTemplateTupleDesc(len, hasoid);

    foreach(l, targetList)
    {
        TargetEntry *tle = lfirst(l);

        if (skipjunk && tle->resjunk)
            continue;
        TupleDescInitEntry(typeInfo,
                           cur_resno,
                           tle->resname,
                           exprType((Node *) tle->expr),
                           exprTypmod((Node *) tle->expr),
                           0);
        TupleDescInitEntryCollation(typeInfo,
                                    cur_resno,
                                    exprCollation((Node *) tle->expr));
        cur_resno++;
    }

    return typeInfo;
}

TupleTableSlot* MakeSingleTupleTableSlot ( TupleDesc  tupdesc  ) 
TupleTableSlot* MakeTupleTableSlot ( void   ) 
AttInMetadata* TupleDescGetAttInMetadata ( TupleDesc  tupdesc  ) 

Definition at line 1038 of file execTuples.c.

References AttInMetadata::attinfuncs, AttInMetadata::attioparams, tupleDesc::attrs, AttInMetadata::atttypmods, BlessTupleDesc(), fmgr_info(), getTypeInputInfo(), i, tupleDesc::natts, palloc(), palloc0(), and AttInMetadata::tupdesc.

Referenced by bt_metap(), bt_page_items(), bt_page_stats(), build_pgstattuple_type(), connectby_text(), connectby_text_serial(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), materializeQueryResult(), materializeResult(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls(), pgrowlocks(), pgstatindex(), postgresAcquireSampleRowsFunc(), postgresBeginForeignModify(), postgresBeginForeignScan(), prs_setup_firstcall(), show_all_settings(), storeRow(), ts_setup_firstcall(), tt_setup_firstcall(), and xpath_table().

{
    int         natts = tupdesc->natts;
    int         i;
    Oid         atttypeid;
    Oid         attinfuncid;
    FmgrInfo   *attinfuncinfo;
    Oid        *attioparams;
    int32      *atttypmods;
    AttInMetadata *attinmeta;

    attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));

    /* "Bless" the tupledesc so that we can make rowtype datums with it */
    attinmeta->tupdesc = BlessTupleDesc(tupdesc);

    /*
     * Gather info needed later to call the "in" function for each attribute
     */
    attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
    attioparams = (Oid *) palloc0(natts * sizeof(Oid));
    atttypmods = (int32 *) palloc0(natts * sizeof(int32));

    for (i = 0; i < natts; i++)
    {
        /* Ignore dropped attributes */
        if (!tupdesc->attrs[i]->attisdropped)
        {
            atttypeid = tupdesc->attrs[i]->atttypid;
            getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
            fmgr_info(attinfuncid, &attinfuncinfo[i]);
            atttypmods[i] = tupdesc->attrs[i]->atttypmod;
        }
    }
    attinmeta->attinfuncs = attinfuncinfo;
    attinmeta->attioparams = attioparams;
    attinmeta->atttypmods = atttypmods;

    return attinmeta;
}

TupleTableSlot* TupleDescGetSlot ( TupleDesc  tupdesc  ) 

Definition at line 1018 of file execTuples.c.

References BlessTupleDesc(), and MakeSingleTupleTableSlot().

{
    TupleTableSlot *slot;

    /* The useful work is here */
    BlessTupleDesc(tupdesc);

    /* Make a standalone slot */
    slot = MakeSingleTupleTableSlot(tupdesc);

    /* Return the slot */
    return slot;
}