#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"
Go to the source code of this file.
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; }
Definition at line 1001 of file execTuples.c.
References assign_record_type_typmod(), RECORDOID, tupleDesc::tdtypeid, and tupleDesc::tdtypmod.
Referenced by aclexplode(), each_worker(), exec_eval_datum(), exec_get_datum_type(), exec_get_datum_type_info(), ExecInitExpr(), ExecInitFunctionScan(), init_sql_fcache(), json_array_elements(), json_populate_recordset(), pg_buffercache_pages(), pg_identify_object(), pg_lock_status(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_activity(), pg_timezone_abbrevs(), pg_timezone_names(), pg_xlogfile_name_offset(), PLy_output_record_funcs(), setup_firstcall(), ts_setup_firstcall(), TupleDescGetAttInMetadata(), and TupleDescGetSlot().
{ if (tupdesc->tdtypeid == RECORDOID && tupdesc->tdtypmod < 0) assign_record_type_typmod(tupdesc); return tupdesc; /* just for notational convenience */ }
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().
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; }
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 | ) |
Definition at line 554 of file execTuples.c.
References Assert, heap_copytuple(), heap_form_tuple(), heap_tuple_from_minimal_tuple(), NULL, TTS_HAS_PHYSICAL_TUPLE, TupleTableSlot::tts_isempty, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.
Referenced by agg_retrieve_direct(), ExecCopySlot(), ExecMaterializeSlot(), ExecScanSubPlan(), ExecSetParamPlan(), setop_retrieve_direct(), and spi_printtup().
{ /* * sanity checks */ Assert(slot != NULL); Assert(!slot->tts_isempty); /* * If we have a physical tuple (either format) then just copy it. */ if (TTS_HAS_PHYSICAL_TUPLE(slot)) return heap_copytuple(slot->tts_tuple); if (slot->tts_mintuple) return heap_tuple_from_minimal_tuple(slot->tts_mintuple); /* * Otherwise we need to build a tuple from the Datum array. */ return heap_form_tuple(slot->tts_tupleDescriptor, slot->tts_values, slot->tts_isnull); }
void ExecDropSingleTupleTableSlot | ( | TupleTableSlot * | slot | ) |
Definition at line 225 of file execTuples.c.
References Assert, ExecClearTuple(), IsA, pfree(), ReleaseTupleDesc, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.
Referenced by ATRewriteTable(), CatalogIndexInsert(), check_exclusion_constraint(), compute_index_stats(), end_tup_output(), get_actual_variable_range(), IndexBuildHeapScan(), IndexCheckExclusion(), RunFromStore(), tuplesort_end(), validate_index_heapscan(), and validateCheckConstraint().
{ /* This should match ExecResetTupleTable's processing of one slot */ Assert(IsA(slot, TupleTableSlot)); ExecClearTuple(slot); if (slot->tts_tupleDescriptor) ReleaseTupleDesc(slot->tts_tupleDescriptor); if (slot->tts_values) pfree(slot->tts_values); if (slot->tts_isnull) pfree(slot->tts_isnull); pfree(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 | ) |
Definition at line 867 of file execTuples.c.
References EState::es_tupleTable, and ExecAllocTableSlot().
Referenced by CopyFrom(), ExecEvalWholeRowVar(), ExecInitAgg(), ExecInitHashJoin(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNullTupleSlot(), ExecInitSubPlan(), ExecInitWindowAgg(), InitPlan(), and TriggerEnabled().
{ return ExecAllocTableSlot(&estate->es_tupleTable); }
TupleTableSlot* ExecInitNullTupleSlot | ( | EState * | estate, | |
TupleDesc | tupType | |||
) |
Definition at line 881 of file execTuples.c.
References ExecInitExtraTupleSlot(), ExecSetSlotDescriptor(), and ExecStoreAllNullTuple().
Referenced by ExecInitHashJoin(), ExecInitMergeJoin(), and ExecInitNestLoop().
{ TupleTableSlot *slot = ExecInitExtraTupleSlot(estate); ExecSetSlotDescriptor(slot, tupType); return ExecStoreAllNullTuple(slot); }
Definition at line 847 of file execTuples.c.
References EState::es_tupleTable, ExecAllocTableSlot(), and PlanState::ps_ResultTupleSlot.
Referenced by ExecInitAgg(), ExecInitAppend(), ExecInitBitmapHeapScan(), ExecInitCteScan(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInitGroup(), ExecInitHash(), ExecInitHashJoin(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitLimit(), ExecInitLockRows(), ExecInitMaterial(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNestLoop(), ExecInitRecursiveUnion(), ExecInitResult(), ExecInitSeqScan(), ExecInitSetOp(), ExecInitSort(), ExecInitSubqueryScan(), ExecInitTidScan(), ExecInitUnique(), ExecInitValuesScan(), ExecInitWindowAgg(), and ExecInitWorkTableScan().
{ planstate->ps_ResultTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable); }
Definition at line 857 of file execTuples.c.
References EState::es_tupleTable, ExecAllocTableSlot(), and ScanState::ss_ScanTupleSlot.
Referenced by ExecInitAgg(), ExecInitBitmapHeapScan(), ExecInitCteScan(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInitGroup(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitMaterial(), ExecInitSeqScan(), ExecInitSort(), ExecInitSubqueryScan(), ExecInitTidScan(), ExecInitValuesScan(), ExecInitWindowAgg(), and ExecInitWorkTableScan().
{ scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable); }
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; }
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 | ) |
Definition at line 497 of file execTuples.c.
References Assert, tupleDesc::natts, NULL, TupleTableSlot::tts_isempty, TupleTableSlot::tts_nvalid, and TupleTableSlot::tts_tupleDescriptor.
Referenced by do_tup_output(), ExecFilterJunk(), ExecProject(), ExecStoreAllNullTuple(), fileIterateForeignScan(), StoreIndexTuple(), and ValuesNext().
{ /* * sanity checks */ Assert(slot != NULL); Assert(slot->tts_tupleDescriptor != NULL); Assert(slot->tts_isempty); slot->tts_isempty = false; slot->tts_nvalid = slot->tts_tupleDescriptor->natts; return slot; }
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; }
Definition at line 903 of file execTuples.c.
References ExecTypeFromTLInternal().
Referenced by ExecAssignResultTypeFromTL(), ExecInitAgg(), ExecInitIndexOnlyScan(), ExecInitModifyTable(), and ExecInitSubPlan().
{ return ExecTypeFromTLInternal(targetList, hasoid, false); }
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 | ) |
Definition at line 208 of file execTuples.c.
References ExecSetSlotDescriptor(), and MakeTupleTableSlot().
Referenced by ATRewriteTable(), begin_tup_output_tupdesc(), CatalogIndexInsert(), check_exclusion_constraint(), compute_index_stats(), ExecInitJunkFilter(), ExecInitJunkFilterConversion(), ExecPrepareTuplestoreResult(), get_actual_variable_range(), IndexBuildHeapScan(), IndexCheckExclusion(), LookupTupleHashEntry(), RunFromStore(), TupleDescGetSlot(), tuplesort_begin_cluster(), validate_index_heapscan(), and validateCheckConstraint().
{ TupleTableSlot *slot = MakeTupleTableSlot(); ExecSetSlotDescriptor(slot, tupdesc); return slot; }
TupleTableSlot* MakeTupleTableSlot | ( | void | ) |
Definition at line 117 of file execTuples.c.
References CurrentMemoryContext, makeNode, TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.
Referenced by ExecAllocTableSlot(), and MakeSingleTupleTableSlot().
{ TupleTableSlot *slot = makeNode(TupleTableSlot); slot->tts_isempty = true; slot->tts_shouldFree = false; slot->tts_shouldFreeMin = false; slot->tts_tuple = NULL; slot->tts_tupleDescriptor = NULL; slot->tts_mcxt = CurrentMemoryContext; slot->tts_buffer = InvalidBuffer; slot->tts_nvalid = 0; slot->tts_values = NULL; slot->tts_isnull = NULL; slot->tts_mintuple = NULL; return slot; }
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; }