PostgreSQL Source Code  git master
execTuples.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/tuptoaster.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 (TupleDesc tupleDesc)
 
TupleTableSlotExecAllocTableSlot (List **tupleTable, TupleDesc desc)
 
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 ExecInitResultTupleSlotTL (EState *estate, PlanState *planstate)
 
void ExecInitScanTupleSlot (EState *estate, ScanState *scanstate, TupleDesc tupledesc)
 
TupleTableSlotExecInitExtraTupleSlot (EState *estate, TupleDesc tupledesc)
 
TupleTableSlotExecInitNullTupleSlot (EState *estate, TupleDesc tupType)
 
TupleDesc ExecTypeFromTL (List *targetList, bool hasoid)
 
TupleDesc ExecCleanTypeFromTL (List *targetList, bool hasoid)
 
TupleDesc ExecTypeFromExprList (List *exprList)
 
void ExecTypeSetColNames (TupleDesc typeInfo, List *namesList)
 
TupleDesc BlessTupleDesc (TupleDesc tupdesc)
 
TupleTableSlotTupleDescGetSlot (TupleDesc tupdesc)
 
AttInMetadataTupleDescGetAttInMetadata (TupleDesc tupdesc)
 
HeapTuple BuildTupleFromCStrings (AttInMetadata *attinmeta, char **values)
 
Datum HeapTupleHeaderGetDatum (HeapTupleHeader tuple)
 
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, const char *txt)
 
void end_tup_output (TupOutputState *tstate)
 

Function Documentation

◆ begin_tup_output_tupdesc()

TupOutputState* begin_tup_output_tupdesc ( DestReceiver dest,
TupleDesc  tupdesc 
)

Definition at line 1315 of file execTuples.c.

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

Referenced by CreateReplicationSlot(), ExecuteCallStmt(), ExplainQuery(), IdentifySystem(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

1316 {
1317  TupOutputState *tstate;
1318 
1319  tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
1320 
1321  tstate->slot = MakeSingleTupleTableSlot(tupdesc);
1322  tstate->dest = dest;
1323 
1324  tstate->dest->rStartup(tstate->dest, (int) CMD_SELECT, tupdesc);
1325 
1326  return tstate;
1327 }
TupleTableSlot * slot
Definition: executor.h:446
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: dest.h:121
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc)
Definition: execTuples.c:232
void * palloc(Size size)
Definition: mcxt.c:924
DestReceiver * dest
Definition: executor.h:447

◆ BlessTupleDesc()

TupleDesc BlessTupleDesc ( TupleDesc  tupdesc)

Definition at line 1109 of file execTuples.c.

References assign_record_type_typmod(), tupleDesc::tdtypeid, and tupleDesc::tdtypmod.

Referenced by aclexplode(), brin_metapage_info(), each_worker(), each_worker_jsonb(), elements_worker(), elements_worker_jsonb(), exec_eval_datum(), ExecEvalWholeRowVar(), ExecInitExprRec(), ExecInitFunctionScan(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), init_sql_fcache(), pg_buffercache_pages(), pg_control_checkpoint(), pg_control_init(), pg_control_recovery(), pg_control_system(), pg_get_object_address(), pg_identify_object(), pg_identify_object_as_address(), pg_last_committed_xact(), pg_lock_status(), pg_ls_dir_files(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_archiver(), pg_timezone_abbrevs(), pg_timezone_names(), pg_visibility_map_summary(), pg_visibility_tupdesc(), pg_walfile_name_offset(), pgstathashindex(), PLy_output_setup_record(), setup_firstcall(), ssl_extension_info(), test_predtest(), ts_setup_firstcall(), tsvector_unnest(), TupleDescGetAttInMetadata(), and TupleDescGetSlot().

1110 {
1111  if (tupdesc->tdtypeid == RECORDOID &&
1112  tupdesc->tdtypmod < 0)
1113  assign_record_type_typmod(tupdesc);
1114 
1115  return tupdesc; /* just for notational convenience */
1116 }
Oid tdtypeid
Definition: tupdesc.h:83
int32 tdtypmod
Definition: tupdesc.h:84
void assign_record_type_typmod(TupleDesc tupDesc)
Definition: typcache.c:1761

◆ BuildTupleFromCStrings()

HeapTuple BuildTupleFromCStrings ( AttInMetadata attinmeta,
char **  values 
)

Definition at line 1195 of file execTuples.c.

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

Referenced by bt_metap(), bt_page_print_tuples(), bt_page_stats(), build_pgstattuple_type(), build_tuplestore_recursively(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), libpqrcv_processTuples(), materializeQueryResult(), materializeResult(), pg_config(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls_internal(), pgp_armor_headers(), pgrowlocks(), pgstatindex_impl(), pltcl_build_tuple_result(), prs_process_call(), show_all_settings(), storeRow(), ts_process_call(), tt_process_call(), and xpath_table().

1196 {
1197  TupleDesc tupdesc = attinmeta->tupdesc;
1198  int natts = tupdesc->natts;
1199  Datum *dvalues;
1200  bool *nulls;
1201  int i;
1202  HeapTuple tuple;
1203 
1204  dvalues = (Datum *) palloc(natts * sizeof(Datum));
1205  nulls = (bool *) palloc(natts * sizeof(bool));
1206 
1207  /*
1208  * Call the "in" function for each non-dropped attribute, even for nulls,
1209  * to support domains.
1210  */
1211  for (i = 0; i < natts; i++)
1212  {
1213  if (!TupleDescAttr(tupdesc, i)->attisdropped)
1214  {
1215  /* Non-dropped attributes */
1216  dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
1217  values[i],
1218  attinmeta->attioparams[i],
1219  attinmeta->atttypmods[i]);
1220  if (values[i] != NULL)
1221  nulls[i] = false;
1222  else
1223  nulls[i] = true;
1224  }
1225  else
1226  {
1227  /* Handle dropped attributes by setting to NULL */
1228  dvalues[i] = (Datum) 0;
1229  nulls[i] = true;
1230  }
1231  }
1232 
1233  /*
1234  * Form a tuple
1235  */
1236  tuple = heap_form_tuple(tupdesc, dvalues, nulls);
1237 
1238  /*
1239  * Release locally palloc'd space. XXX would probably be good to pfree
1240  * values of pass-by-reference datums, as well.
1241  */
1242  pfree(dvalues);
1243  pfree(nulls);
1244 
1245  return tuple;
1246 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
int32 * atttypmods
Definition: funcapi.h:48
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1074
Oid * attioparams
Definition: funcapi.h:45
int natts
Definition: tupdesc.h:82
void pfree(void *pointer)
Definition: mcxt.c:1031
TupleDesc tupdesc
Definition: funcapi.h:39
uintptr_t Datum
Definition: postgres.h:367
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1709
static Datum values[MAXATTR]
Definition: bootstrap.c:164
void * palloc(Size size)
Definition: mcxt.c:924
int i
FmgrInfo * attinfuncs
Definition: funcapi.h:42

◆ do_text_output_multiline()

void do_text_output_multiline ( TupOutputState tstate,
const char *  txt 
)

Definition at line 1361 of file execTuples.c.

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

Referenced by ExplainQuery().

1362 {
1363  Datum values[1];
1364  bool isnull[1] = {false};
1365 
1366  while (*txt)
1367  {
1368  const char *eol;
1369  int len;
1370 
1371  eol = strchr(txt, '\n');
1372  if (eol)
1373  {
1374  len = eol - txt;
1375  eol++;
1376  }
1377  else
1378  {
1379  len = strlen(txt);
1380  eol = txt + len;
1381  }
1382 
1383  values[0] = PointerGetDatum(cstring_to_text_with_len(txt, len));
1384  do_tup_output(tstate, values, isnull);
1385  pfree(DatumGetPointer(values[0]));
1386  txt = eol;
1387  }
1388 }
#define PointerGetDatum(X)
Definition: postgres.h:541
void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
Definition: execTuples.c:1333
void pfree(void *pointer)
Definition: mcxt.c:1031
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:161
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:534
static Datum values[MAXATTR]
Definition: bootstrap.c:164

◆ do_tup_output()

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

Definition at line 1333 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 CreateReplicationSlot(), do_text_output_multiline(), IdentifySystem(), ShowAllGUCConfig(), and StartReplication().

1334 {
1335  TupleTableSlot *slot = tstate->slot;
1336  int natts = slot->tts_tupleDescriptor->natts;
1337 
1338  /* make sure the slot is clear */
1339  ExecClearTuple(slot);
1340 
1341  /* insert data */
1342  memcpy(slot->tts_values, values, natts * sizeof(Datum));
1343  memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
1344 
1345  /* mark slot as containing a virtual tuple */
1346  ExecStoreVirtualTuple(slot);
1347 
1348  /* send the tuple to the receiver */
1349  (void) tstate->dest->receiveSlot(slot, tstate->dest);
1350 
1351  /* clean up */
1352  ExecClearTuple(slot);
1353 }
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
Datum * tts_values
Definition: tuptable.h:130
TupleTableSlot * slot
Definition: executor.h:446
int natts
Definition: tupdesc.h:82
bool * tts_isnull
Definition: tuptable.h:132
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
static Datum values[MAXATTR]
Definition: bootstrap.c:164
DestReceiver * dest
Definition: executor.h:447
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:524

◆ end_tup_output()

void end_tup_output ( TupOutputState tstate)

Definition at line 1391 of file execTuples.c.

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

Referenced by CreateReplicationSlot(), ExecuteCallStmt(), ExplainQuery(), IdentifySystem(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

1392 {
1393  tstate->dest->rShutdown(tstate->dest);
1394  /* note that destroying the dest is not ours to do */
1396  pfree(tstate);
1397 }
TupleTableSlot * slot
Definition: executor.h:446
void pfree(void *pointer)
Definition: mcxt.c:1031
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:247
void(* rShutdown)(DestReceiver *self)
Definition: dest.h:124
DestReceiver * dest
Definition: executor.h:447

◆ ExecAllocTableSlot()

TupleTableSlot* ExecAllocTableSlot ( List **  tupleTable,
TupleDesc  desc 
)

Definition at line 167 of file execTuples.c.

References lappend(), and MakeTupleTableSlot().

Referenced by ExecInitExtraTupleSlot(), ExecInitResultTupleSlotTL(), ExecInitScanTupleSlot(), and find_hash_columns().

168 {
169  TupleTableSlot *slot = MakeTupleTableSlot(desc);
170 
171  *tupleTable = lappend(*tupleTable, slot);
172 
173  return slot;
174 }
List * lappend(List *list, void *datum)
Definition: list.c:128
TupleTableSlot * MakeTupleTableSlot(TupleDesc tupleDesc)
Definition: execTuples.c:113

◆ ExecCleanTypeFromTL()

TupleDesc ExecCleanTypeFromTL ( List targetList,
bool  hasoid 
)

Definition at line 977 of file execTuples.c.

References ExecTypeFromTLInternal().

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

978 {
979  return ExecTypeFromTLInternal(targetList, hasoid, true);
980 }
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
Definition: execTuples.c:983

◆ ExecClearTuple()

TupleTableSlot* ExecClearTuple ( TupleTableSlot slot)

Definition at line 475 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), InvalidBuffer, 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 agg_retrieve_hash_table(), apply_handle_update(), apply_returning_filter(), begin_partition(), BitmapHeapNext(), buildSubPlanHash(), CteScanNext(), do_tup_output(), eval_windowaggregates(), ExecAppend(), ExecDelete(), ExecDropSingleTupleTableSlot(), ExecEndAgg(), ExecEndBitmapHeapScan(), ExecEndCteScan(), ExecEndCustomScan(), ExecEndForeignScan(), ExecEndFunctionScan(), ExecEndGather(), ExecEndGatherMerge(), ExecEndGroup(), ExecEndHashJoin(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecEndMaterial(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNamedTuplestoreScan(), ExecEndNestLoop(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndTableFuncScan(), ExecEndTidScan(), ExecEndUnique(), ExecEndValuesScan(), ExecEndWindowAgg(), ExecEndWorkTableScan(), ExecEvalAggOrderedTransTuple(), ExecFilterJunk(), ExecFindPartition(), ExecHashJoinGetSavedTuple(), ExecHashSubPlan(), ExecMaterial(), ExecMergeAppend(), ExecParallelHashJoinOuterGetTuple(), ExecProject(), ExecProjectSRF(), ExecReScanAgg(), ExecReScanCteScan(), ExecReScanFunctionScan(), ExecReScanGroup(), ExecReScanMaterial(), ExecReScanMergeJoin(), ExecReScanNamedTuplestoreScan(), ExecReScanSetOp(), ExecReScanSort(), ExecReScanTableFuncScan(), ExecReScanUnique(), ExecReScanValuesScan(), ExecReScanWindowAgg(), ExecReScanWorkTableScan(), ExecResetTupleTable(), ExecScan(), ExecScanFetch(), ExecSetSlotDescriptor(), ExecStoreAllNullTuple(), ExecUnique(), ExecWindowAgg(), fetch_remote_table_info(), fetch_table_list(), fileIterateForeignScan(), FunctionNext(), gather_getnext(), gather_merge_clear_tuples(), gather_merge_init(), get_returning_data(), hypothetical_dense_rank_final(), hypothetical_rank_common(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), lookup_hash_entry(), ordered_set_shutdown(), ordered_set_transition_multi(), per_MultiFuncCall(), postgresIterateDirectModify(), postgresIterateForeignScan(), process_ordered_aggregate_multi(), RunFromStore(), SampleNext(), SeqNext(), setop_retrieve_direct(), setop_retrieve_hash_table(), ShutdownSetExpr(), slot_modify_cstrings(), slot_store_cstrings(), StoreIndexTuple(), tfuncLoadRows(), TidNext(), tuplesort_gettupleslot(), tuplestore_gettupleslot(), update_frameheadpos(), update_frametailpos(), update_grouptailpos(), ValuesNext(), and WinRowsArePeers().

476 {
477  /*
478  * sanity checks
479  */
480  Assert(slot != NULL);
481 
482  /*
483  * Free the old physical tuple if necessary.
484  */
485  if (slot->tts_shouldFree)
486  heap_freetuple(slot->tts_tuple);
487  if (slot->tts_shouldFreeMin)
489 
490  slot->tts_tuple = NULL;
491  slot->tts_mintuple = NULL;
492  slot->tts_shouldFree = false;
493  slot->tts_shouldFreeMin = false;
494 
495  /*
496  * Drop the pin on the referenced buffer, if there is one.
497  */
498  if (BufferIsValid(slot->tts_buffer))
499  ReleaseBuffer(slot->tts_buffer);
500 
501  slot->tts_buffer = InvalidBuffer;
502 
503  /*
504  * Mark it empty.
505  */
506  slot->tts_isempty = true;
507  slot->tts_nvalid = 0;
508 
509  return slot;
510 }
bool tts_isempty
Definition: tuptable.h:116
#define InvalidBuffer
Definition: buf.h:25
bool tts_shouldFreeMin
Definition: tuptable.h:118
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1773
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1868
bool tts_shouldFree
Definition: tuptable.h:117
#define Assert(condition)
Definition: c.h:699
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:133
HeapTuple tts_tuple
Definition: tuptable.h:122
Buffer tts_buffer
Definition: tuptable.h:126

◆ ExecCopySlot()

TupleTableSlot* ExecCopySlot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)

Definition at line 851 of file execTuples.c.

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

Referenced by begin_partition(), CteScanNext(), ExecGroup(), ExecUnique(), ExecWindowAgg(), postgresRecheckForeignScan(), spool_tuples(), update_frameheadpos(), and update_frametailpos().

852 {
853  HeapTuple newTuple;
854  MemoryContext oldContext;
855 
856  /*
857  * There might be ways to optimize this when the source is virtual, but
858  * for now just always build a physical copy. Make sure it is in the
859  * right context.
860  */
861  oldContext = MemoryContextSwitchTo(dstslot->tts_mcxt);
862  newTuple = ExecCopySlotTuple(srcslot);
863  MemoryContextSwitchTo(oldContext);
864 
865  return ExecStoreTuple(newTuple, dstslot, InvalidBuffer, true);
866 }
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:356
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define InvalidBuffer
Definition: buf.h:25
MemoryContext tts_mcxt
Definition: tuptable.h:125
HeapTuple ExecCopySlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:581

◆ ExecCopySlotMinimalTuple()

MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot slot)

Definition at line 613 of file execTuples.c.

References Assert, heap_copy_minimal_tuple(), heap_form_minimal_tuple(), HeapTupleHeaderGetNatts, minimal_expand_tuple(), minimal_tuple_from_heap_tuple(), tupleDesc::natts, HeapTupleData::t_data, 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().

614 {
615  /*
616  * sanity checks
617  */
618  Assert(slot != NULL);
619  Assert(!slot->tts_isempty);
620 
621  /*
622  * If we have a physical tuple then just copy it. Prefer to copy
623  * tts_mintuple since that's a tad cheaper.
624  */
625  if (slot->tts_mintuple)
627  if (slot->tts_tuple)
628  {
630  < slot->tts_tupleDescriptor->natts)
631  return minimal_expand_tuple(slot->tts_tuple,
632  slot->tts_tupleDescriptor);
633  else
635  }
636 
637  /*
638  * Otherwise we need to build a tuple from the Datum array.
639  */
641  slot->tts_values,
642  slot->tts_isnull);
643 }
bool tts_isempty
Definition: tuptable.h:116
Datum * tts_values
Definition: tuptable.h:130
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1880
int natts
Definition: tupdesc.h:82
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:544
MinimalTuple minimal_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc)
Definition: heaptuple.c:1011
bool * tts_isnull
Definition: tuptable.h:132
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1791
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:699
MinimalTuple tts_mintuple
Definition: tuptable.h:133
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Definition: heaptuple.c:1921
HeapTuple tts_tuple
Definition: tuptable.h:122

◆ ExecCopySlotTuple()

HeapTuple ExecCopySlotTuple ( TupleTableSlot slot)

Definition at line 581 of file execTuples.c.

References Assert, heap_copytuple(), heap_form_tuple(), heap_tuple_from_minimal_tuple(), 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().

582 {
583  /*
584  * sanity checks
585  */
586  Assert(slot != NULL);
587  Assert(!slot->tts_isempty);
588 
589  /*
590  * If we have a physical tuple (either format) then just copy it.
591  */
592  if (TTS_HAS_PHYSICAL_TUPLE(slot))
593  return heap_copytuple(slot->tts_tuple);
594  if (slot->tts_mintuple)
596 
597  /*
598  * Otherwise we need to build a tuple from the Datum array.
599  */
601  slot->tts_values,
602  slot->tts_isnull);
603 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:722
bool tts_isempty
Definition: tuptable.h:116
Datum * tts_values
Definition: tuptable.h:130
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1074
bool * tts_isnull
Definition: tuptable.h:132
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1899
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:699
MinimalTuple tts_mintuple
Definition: tuptable.h:133
HeapTuple tts_tuple
Definition: tuptable.h:122
#define TTS_HAS_PHYSICAL_TUPLE(slot)
Definition: tuptable.h:140

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 247 of file execTuples.c.

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

Referenced by afterTriggerInvokeEvents(), ATRewriteTable(), CatalogIndexInsert(), check_default_partition_contents(), check_exclusion_or_unique_constraint(), compute_index_stats(), end_tup_output(), ExecCleanupTupleRouting(), fetch_remote_table_info(), fetch_table_list(), get_actual_variable_range(), hypothetical_dense_rank_final(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), ProjIndexIsUnchanged(), RunFromStore(), tuplesort_end(), unique_key_recheck(), validate_index_heapscan(), and validateCheckConstraint().

248 {
249  /* This should match ExecResetTupleTable's processing of one slot */
250  Assert(IsA(slot, TupleTableSlot));
251  ExecClearTuple(slot);
252  if (slot->tts_tupleDescriptor)
254  if (!slot->tts_fixedTupleDescriptor)
255  {
256  if (slot->tts_values)
257  pfree(slot->tts_values);
258  if (slot->tts_isnull)
259  pfree(slot->tts_isnull);
260  }
261  pfree(slot);
262 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:567
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
Datum * tts_values
Definition: tuptable.h:130
void pfree(void *pointer)
Definition: mcxt.c:1031
bool * tts_isnull
Definition: tuptable.h:132
bool tts_fixedTupleDescriptor
Definition: tuptable.h:137
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:699
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:124

◆ ExecFetchSlotMinimalTuple()

MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot)

Definition at line 708 of file execTuples.c.

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

Referenced by ExecHashJoinImpl(), ExecHashSkewTableInsert(), ExecHashTableInsert(), ExecParallelHashJoinPartitionOuter(), ExecParallelHashTableInsert(), and ExecParallelHashTableInsertCurrentBatch().

709 {
710  MemoryContext oldContext;
711 
712  /*
713  * sanity checks
714  */
715  Assert(slot != NULL);
716  Assert(!slot->tts_isempty);
717 
718  /*
719  * If we have a minimal physical tuple (local or not) then just return it.
720  */
721  if (slot->tts_mintuple)
722  return slot->tts_mintuple;
723 
724  /*
725  * Otherwise, copy or build a minimal tuple, and store it into the slot.
726  *
727  * We may be called in a context that is shorter-lived than the tuple
728  * slot, but we have to ensure that the materialized tuple will survive
729  * anyway.
730  */
731  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
733  slot->tts_shouldFreeMin = true;
734  MemoryContextSwitchTo(oldContext);
735 
736  /*
737  * Note: we may now have a situation where we have a local minimal tuple
738  * attached to a virtual or non-local physical tuple. There seems no harm
739  * in that at the moment, but if any materializes, we should change this
740  * function to force the slot into minimal-tuple-only state.
741  */
742 
743  return slot->tts_mintuple;
744 }
bool tts_isempty
Definition: tuptable.h:116
MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition: execTuples.c:613
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool tts_shouldFreeMin
Definition: tuptable.h:118
MemoryContext tts_mcxt
Definition: tuptable.h:125
#define Assert(condition)
Definition: c.h:699
MinimalTuple tts_mintuple
Definition: tuptable.h:133

◆ ExecFetchSlotTuple()

HeapTuple ExecFetchSlotTuple ( TupleTableSlot slot)

Definition at line 661 of file execTuples.c.

References Assert, ExecMaterializeSlot(), ExecStoreTuple(), heap_expand_tuple(), HeapTupleHeaderGetNatts, InvalidBuffer, MemoryContextSwitchTo(), tupleDesc::natts, HeapTupleData::t_data, TTS_HAS_PHYSICAL_TUPLE, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecConstraints(), ExecFetchSlotTupleDatum(), ExecFindPartition(), ExecPartitionCheckEmitError(), and ExecWithCheckOptions().

662 {
663  /*
664  * sanity checks
665  */
666  Assert(slot != NULL);
667  Assert(!slot->tts_isempty);
668 
669  /*
670  * If we have a regular physical tuple then just return it.
671  */
672  if (TTS_HAS_PHYSICAL_TUPLE(slot))
673  {
675  slot->tts_tupleDescriptor->natts)
676  {
677  HeapTuple tuple;
678  MemoryContext oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
679 
680  tuple = heap_expand_tuple(slot->tts_tuple,
681  slot->tts_tupleDescriptor);
682  MemoryContextSwitchTo(oldContext);
683  slot = ExecStoreTuple(tuple, slot, InvalidBuffer, true);
684  }
685  return slot->tts_tuple;
686  }
687 
688  /*
689  * Otherwise materialize the slot...
690  */
691  return ExecMaterializeSlot(slot);
692 }
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:356
bool tts_isempty
Definition: tuptable.h:116
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define InvalidBuffer
Definition: buf.h:25
MemoryContext tts_mcxt
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:82
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:544
HeapTuple heap_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc)
Definition: heaptuple.c:1023
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:699
HeapTuple ExecMaterializeSlot(TupleTableSlot *slot)
Definition: execTuples.c:781
HeapTuple tts_tuple
Definition: tuptable.h:122
#define TTS_HAS_PHYSICAL_TUPLE(slot)
Definition: tuptable.h:140

◆ ExecFetchSlotTupleDatum()

Datum ExecFetchSlotTupleDatum ( TupleTableSlot slot)

Definition at line 754 of file execTuples.c.

References ExecFetchSlotTuple(), heap_copy_tuple_as_datum(), and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecMakeFunctionResultSet(), and postquel_get_single_result().

755 {
756  HeapTuple tup;
757  TupleDesc tupdesc;
758 
759  /* Fetch slot's contents in regular-physical-tuple form */
760  tup = ExecFetchSlotTuple(slot);
761  tupdesc = slot->tts_tupleDescriptor;
762 
763  /* Convert to Datum form */
764  return heap_copy_tuple_as_datum(tup, tupdesc);
765 }
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:1038
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
HeapTuple ExecFetchSlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:661

◆ ExecInitExtraTupleSlot()

◆ ExecInitNullTupleSlot()

TupleTableSlot* ExecInitNullTupleSlot ( EState estate,
TupleDesc  tupType 
)

Definition at line 945 of file execTuples.c.

References ExecInitExtraTupleSlot(), and ExecStoreAllNullTuple().

Referenced by ExecInitHashJoin(), ExecInitMergeJoin(), and ExecInitNestLoop().

946 {
947  TupleTableSlot *slot = ExecInitExtraTupleSlot(estate, tupType);
948 
949  return ExecStoreAllNullTuple(slot);
950 }
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
Definition: execTuples.c:548
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc)
Definition: execTuples.c:931

◆ ExecInitResultTupleSlotTL()

void ExecInitResultTupleSlotTL ( EState estate,
PlanState planstate 
)

Definition at line 890 of file execTuples.c.

References EState::es_tupleTable, ExecAllocTableSlot(), ExecContextForcesOids(), ExecTypeFromTL(), PlanState::plan, PlanState::ps_ResultTupleSlot, and Plan::targetlist.

Referenced by ExecInitAgg(), ExecInitAppend(), ExecInitBitmapHeapScan(), ExecInitCteScan(), ExecInitCustomScan(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInitGather(), ExecInitGatherMerge(), ExecInitGroup(), ExecInitHash(), ExecInitHashJoin(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitLimit(), ExecInitLockRows(), ExecInitMaterial(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNamedTuplestoreScan(), ExecInitNestLoop(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitResult(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitSetOp(), ExecInitSort(), ExecInitSubqueryScan(), ExecInitTableFuncScan(), ExecInitTidScan(), ExecInitUnique(), ExecInitValuesScan(), ExecInitWindowAgg(), and ExecInitWorkTableScan().

891 {
892  bool hasoid;
893  TupleDesc tupDesc;
894 
895  if (ExecContextForcesOids(planstate, &hasoid))
896  {
897  /* context forces OID choice; hasoid is now set correctly */
898  }
899  else
900  {
901  /* given free choice, don't leave space for OIDs in result tuples */
902  hasoid = false;
903  }
904 
905  tupDesc = ExecTypeFromTL(planstate->plan->targetlist, hasoid);
906 
907  planstate->ps_ResultTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable, tupDesc);
908 }
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:946
TupleTableSlot * ExecAllocTableSlot(List **tupleTable, TupleDesc desc)
Definition: execTuples.c:167
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:965
List * es_tupleTable
Definition: execnodes.h:525
Plan * plan
Definition: execnodes.h:912
List * targetlist
Definition: plannodes.h:147
bool ExecContextForcesOids(PlanState *planstate, bool *hasoids)
Definition: execMain.c:1521

◆ ExecInitScanTupleSlot()

void ExecInitScanTupleSlot ( EState estate,
ScanState scanstate,
TupleDesc  tupledesc 
)

◆ ExecMaterializeSlot()

HeapTuple ExecMaterializeSlot ( TupleTableSlot slot)

Definition at line 781 of file execTuples.c.

References Assert, BufferIsValid, ExecCopySlotTuple(), InvalidBuffer, MemoryContextSwitchTo(), 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 AfterTriggerExecute(), apply_returning_filter(), CopyFrom(), EvalPlanQual(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecFetchSlotTuple(), ExecInsert(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecPrepareTupleRouting(), ExecProcessReturning(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), ExecUpdate(), ForeignNext(), intorel_receive(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), tqueueReceiveSlot(), and transientrel_receive().

782 {
783  MemoryContext oldContext;
784 
785  /*
786  * sanity checks
787  */
788  Assert(slot != NULL);
789  Assert(!slot->tts_isempty);
790 
791  /*
792  * If we have a regular physical tuple, and it's locally palloc'd, we have
793  * nothing to do.
794  */
795  if (slot->tts_tuple && slot->tts_shouldFree)
796  return slot->tts_tuple;
797 
798  /*
799  * Otherwise, copy or build a physical tuple, and store it into the slot.
800  *
801  * We may be called in a context that is shorter-lived than the tuple
802  * slot, but we have to ensure that the materialized tuple will survive
803  * anyway.
804  */
805  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
806  slot->tts_tuple = ExecCopySlotTuple(slot);
807  slot->tts_shouldFree = true;
808  MemoryContextSwitchTo(oldContext);
809 
810  /*
811  * Drop the pin on the referenced buffer, if there is one.
812  */
813  if (BufferIsValid(slot->tts_buffer))
814  ReleaseBuffer(slot->tts_buffer);
815 
816  slot->tts_buffer = InvalidBuffer;
817 
818  /*
819  * Mark extracted state invalid. This is important because the slot is
820  * not supposed to depend any more on the previous external data; we
821  * mustn't leave any dangling pass-by-reference datums in tts_values.
822  * However, we have not actually invalidated any such datums, if there
823  * happen to be any previously fetched from the slot. (Note in particular
824  * that we have not pfree'd tts_mintuple, if there is one.)
825  */
826  slot->tts_nvalid = 0;
827 
828  /*
829  * On the same principle of not depending on previous remote storage,
830  * forget the mintuple if it's not local storage. (If it is local
831  * storage, we must not pfree it now, since callers might have already
832  * fetched datum pointers referencing it.)
833  */
834  if (!slot->tts_shouldFreeMin)
835  slot->tts_mintuple = NULL;
836 
837  return slot->tts_tuple;
838 }
bool tts_isempty
Definition: tuptable.h:116
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define InvalidBuffer
Definition: buf.h:25
bool tts_shouldFreeMin
Definition: tuptable.h:118
MemoryContext tts_mcxt
Definition: tuptable.h:125
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
bool tts_shouldFree
Definition: tuptable.h:117
HeapTuple ExecCopySlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:581
#define Assert(condition)
Definition: c.h:699
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:133
HeapTuple tts_tuple
Definition: tuptable.h:122
Buffer tts_buffer
Definition: tuptable.h:126

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 186 of file execTuples.c.

References ExecClearTuple(), lfirst_node, list_free(), pfree(), ReleaseTupleDesc, TupleTableSlot::tts_fixedTupleDescriptor, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by apply_handle_delete(), apply_handle_insert(), apply_handle_update(), CopyFrom(), EvalPlanQualEnd(), and ExecEndPlan().

188 {
189  ListCell *lc;
190 
191  foreach(lc, tupleTable)
192  {
194 
195  /* Always release resources and reset the slot to empty */
196  ExecClearTuple(slot);
197  if (slot->tts_tupleDescriptor)
198  {
200  slot->tts_tupleDescriptor = NULL;
201  }
202 
203  /* If shouldFree, release memory occupied by the slot itself */
204  if (shouldFree)
205  {
206  if (!slot->tts_fixedTupleDescriptor)
207  {
208  if (slot->tts_values)
209  pfree(slot->tts_values);
210  if (slot->tts_isnull)
211  pfree(slot->tts_isnull);
212  }
213  pfree(slot);
214  }
215  }
216 
217  /* If shouldFree, release the list structure */
218  if (shouldFree)
219  list_free(tupleTable);
220 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
Datum * tts_values
Definition: tuptable.h:130
void pfree(void *pointer)
Definition: mcxt.c:1031
#define lfirst_node(type, lc)
Definition: pg_list.h:109
bool * tts_isnull
Definition: tuptable.h:132
bool tts_fixedTupleDescriptor
Definition: tuptable.h:137
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void list_free(List *list)
Definition: list.c:1133
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:124

◆ ExecSetSlotDescriptor()

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 281 of file execTuples.c.

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

Referenced by apply_returning_filter(), ConvertPartitionTupleSlot(), ExecAssignScanType(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecConstraints(), ExecDelete(), ExecInitJunkFilter(), ExecInitJunkFilterConversion(), ExecInitPartitionInfo(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecPartitionCheckEmitError(), ExecPrepareTupleRouting(), ExecWithCheckOptions(), and TriggerEnabled().

283 {
285 
286  /* For safety, make sure slot is empty before changing it */
287  ExecClearTuple(slot);
288 
289  /*
290  * Release any old descriptor. Also release old Datum/isnull arrays if
291  * present (we don't bother to check if they could be re-used).
292  */
293  if (slot->tts_tupleDescriptor)
295 
296  if (slot->tts_values)
297  pfree(slot->tts_values);
298  if (slot->tts_isnull)
299  pfree(slot->tts_isnull);
300 
301  /*
302  * Install the new descriptor; if it's refcounted, bump its refcount.
303  */
304  slot->tts_tupleDescriptor = tupdesc;
305  PinTupleDesc(tupdesc);
306 
307  /*
308  * Allocate Datum/isnull arrays of the appropriate size. These must have
309  * the same lifetime as the slot, so allocate in the slot's own context.
310  */
311  slot->tts_values = (Datum *)
312  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
313  slot->tts_isnull = (bool *)
314  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(bool));
315 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
MemoryContext tts_mcxt
Definition: tuptable.h:125
Datum * tts_values
Definition: tuptable.h:130
int natts
Definition: tupdesc.h:82
void pfree(void *pointer)
Definition: mcxt.c:1031
bool * tts_isnull
Definition: tuptable.h:132
bool tts_fixedTupleDescriptor
Definition: tuptable.h:137
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:699
#define PinTupleDesc(tupdesc)
Definition: tupdesc.h:118
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:124

◆ ExecStoreAllNullTuple()

TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 548 of file execTuples.c.

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

Referenced by BitmapHeapNext(), ExecDelete(), ExecInitNullTupleSlot(), get_returning_data(), and prepare_projection_slot().

549 {
550  /*
551  * sanity checks
552  */
553  Assert(slot != NULL);
554  Assert(slot->tts_tupleDescriptor != NULL);
555 
556  /* Clear any old contents */
557  ExecClearTuple(slot);
558 
559  /*
560  * Fill all the columns of the virtual tuple with nulls
561  */
562  MemSet(slot->tts_values, 0,
563  slot->tts_tupleDescriptor->natts * sizeof(Datum));
564  memset(slot->tts_isnull, true,
565  slot->tts_tupleDescriptor->natts * sizeof(bool));
566 
567  return ExecStoreVirtualTuple(slot);
568 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
#define MemSet(start, val, len)
Definition: c.h:908
Datum * tts_values
Definition: tuptable.h:130
int natts
Definition: tupdesc.h:82
bool * tts_isnull
Definition: tuptable.h:132
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:699
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:524

◆ ExecStoreMinimalTuple()

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

Definition at line 420 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), InvalidBuffer, MINIMAL_TUPLE_OFFSET, ReleaseBuffer(), HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::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(), ExecParallelHashJoinNewBatch(), ExecParallelHashJoinOuterGetTuple(), ExecParallelScanHashBucket(), ExecScanHashBucket(), ExecScanHashTableForUnmatched(), findPartialMatch(), setop_retrieve_hash_table(), TupleHashTableHash(), TupleHashTableMatch(), tuplesort_gettupleslot(), and tuplestore_gettupleslot().

423 {
424  /*
425  * sanity checks
426  */
427  Assert(mtup != NULL);
428  Assert(slot != NULL);
429  Assert(slot->tts_tupleDescriptor != NULL);
430 
431  /*
432  * Free any old physical tuple belonging to the slot.
433  */
434  if (slot->tts_shouldFree)
435  heap_freetuple(slot->tts_tuple);
436  if (slot->tts_shouldFreeMin)
438 
439  /*
440  * Drop the pin on the referenced buffer, if there is one.
441  */
442  if (BufferIsValid(slot->tts_buffer))
443  ReleaseBuffer(slot->tts_buffer);
444 
445  slot->tts_buffer = InvalidBuffer;
446 
447  /*
448  * Store the new tuple into the specified slot.
449  */
450  slot->tts_isempty = false;
451  slot->tts_shouldFree = false;
452  slot->tts_shouldFreeMin = shouldFree;
453  slot->tts_tuple = &slot->tts_minhdr;
454  slot->tts_mintuple = mtup;
455 
456  slot->tts_minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
457  slot->tts_minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
458  /* no need to set t_self or t_tableOid since we won't allow access */
459 
460  /* Mark extracted state invalid */
461  slot->tts_nvalid = 0;
462 
463  return slot;
464 }
bool tts_isempty
Definition: tuptable.h:116
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define InvalidBuffer
Definition: buf.h:25
bool tts_shouldFreeMin
Definition: tuptable.h:118
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1773
HeapTupleHeader t_data
Definition: htup.h:68
HeapTupleData tts_minhdr
Definition: tuptable.h:134
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1868
uint32 t_len
Definition: htup.h:64
bool tts_shouldFree
Definition: tuptable.h:117
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:699
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:133
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:632
HeapTuple tts_tuple
Definition: tuptable.h:122
Buffer tts_buffer
Definition: tuptable.h:126

◆ ExecStoreTuple()

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

Definition at line 356 of file execTuples.c.

References Assert, buffer, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), IncrBufferRefCount(), 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(), apply_handle_update(), ATRewriteTable(), BitmapHeapNext(), CatalogIndexInsert(), check_default_partition_contents(), check_exclusion_or_unique_constraint(), comparetup_cluster(), compute_index_stats(), ConvertPartitionTupleSlot(), CopyFrom(), CopyFromInsertBatch(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecConstraints(), ExecCopySlot(), ExecDelete(), ExecFetchSlotTuple(), ExecFindPartition(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecOnConflictUpdate(), ExecPartitionCheckEmitError(), ExecScanFetch(), ExecuteCallStmt(), ExecWithCheckOptions(), gather_getnext(), gather_merge_readnext(), get_actual_variable_range(), get_returning_data(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), postgresIterateForeignScan(), ProjIndexIsUnchanged(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), SampleNext(), SeqNext(), setop_retrieve_direct(), store_returning_result(), TidNext(), TriggerEnabled(), unique_key_recheck(), validate_index_heapscan(), and validateCheckConstraint().

360 {
361  /*
362  * sanity checks
363  */
364  Assert(tuple != NULL);
365  Assert(slot != NULL);
366  Assert(slot->tts_tupleDescriptor != NULL);
367  /* passing shouldFree=true for a tuple on a disk page is not sane */
368  Assert(BufferIsValid(buffer) ? (!shouldFree) : true);
369 
370  /*
371  * Free any old physical tuple belonging to the slot.
372  */
373  if (slot->tts_shouldFree)
374  heap_freetuple(slot->tts_tuple);
375  if (slot->tts_shouldFreeMin)
377 
378  /*
379  * Store the new tuple into the specified slot.
380  */
381  slot->tts_isempty = false;
382  slot->tts_shouldFree = shouldFree;
383  slot->tts_shouldFreeMin = false;
384  slot->tts_tuple = tuple;
385  slot->tts_mintuple = NULL;
386 
387  /* Mark extracted state invalid */
388  slot->tts_nvalid = 0;
389 
390  /*
391  * If tuple is on a disk page, keep the page pinned as long as we hold a
392  * pointer into it. We assume the caller already has such a pin.
393  *
394  * This is coded to optimize the case where the slot previously held a
395  * tuple on the same disk page: in that case releasing and re-acquiring
396  * the pin is a waste of cycles. This is a common situation during
397  * seqscans, so it's worth troubling over.
398  */
399  if (slot->tts_buffer != buffer)
400  {
401  if (BufferIsValid(slot->tts_buffer))
402  ReleaseBuffer(slot->tts_buffer);
403  slot->tts_buffer = buffer;
404  if (BufferIsValid(buffer))
406  }
407 
408  return slot;
409 }
bool tts_isempty
Definition: tuptable.h:116
bool tts_shouldFreeMin
Definition: tuptable.h:118
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1773
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1868
bool tts_shouldFree
Definition: tuptable.h:117
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:699
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:133
HeapTuple tts_tuple
Definition: tuptable.h:122
Buffer tts_buffer
Definition: tuptable.h:126
void IncrBufferRefCount(Buffer buffer)
Definition: bufmgr.c:3347

◆ ExecStoreVirtualTuple()

◆ ExecTypeFromExprList()

TupleDesc ExecTypeFromExprList ( List exprList)

Definition at line 1024 of file execTuples.c.

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

Referenced by ExecInitExprRec(), and ExecInitValuesScan().

1025 {
1026  TupleDesc typeInfo;
1027  ListCell *lc;
1028  int cur_resno = 1;
1029 
1030  typeInfo = CreateTemplateTupleDesc(list_length(exprList), false);
1031 
1032  foreach(lc, exprList)
1033  {
1034  Node *e = lfirst(lc);
1035 
1036  TupleDescInitEntry(typeInfo,
1037  cur_resno,
1038  NULL,
1039  exprType(e),
1040  exprTypmod(e),
1041  0);
1042  TupleDescInitEntryCollation(typeInfo,
1043  cur_resno,
1044  exprCollation(e));
1045  cur_resno++;
1046  }
1047 
1048  return typeInfo;
1049 }
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:276
Definition: nodes.h:516
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:761
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:600
#define lfirst(lc)
Definition: pg_list.h:106
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:89
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:720
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:45
e
Definition: preproc-init.c:82

◆ ExecTypeFromTL()

TupleDesc ExecTypeFromTL ( List targetList,
bool  hasoid 
)

Definition at line 965 of file execTuples.c.

References ExecTypeFromTLInternal().

Referenced by build_pertrans_for_aggref(), ExecInitCustomScan(), ExecInitForeignScan(), ExecInitIndexOnlyScan(), ExecInitModifyTable(), ExecInitPartitionInfo(), ExecInitResultTupleSlotTL(), ExecInitSubPlan(), find_hash_columns(), and ordered_set_startup().

966 {
967  return ExecTypeFromTLInternal(targetList, hasoid, false);
968 }
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
Definition: execTuples.c:983

◆ ExecTypeFromTLInternal()

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

Definition at line 983 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().

984 {
985  TupleDesc typeInfo;
986  ListCell *l;
987  int len;
988  int cur_resno = 1;
989 
990  if (skipjunk)
991  len = ExecCleanTargetListLength(targetList);
992  else
993  len = ExecTargetListLength(targetList);
994  typeInfo = CreateTemplateTupleDesc(len, hasoid);
995 
996  foreach(l, targetList)
997  {
998  TargetEntry *tle = lfirst(l);
999 
1000  if (skipjunk && tle->resjunk)
1001  continue;
1002  TupleDescInitEntry(typeInfo,
1003  cur_resno,
1004  tle->resname,
1005  exprType((Node *) tle->expr),
1006  exprTypmod((Node *) tle->expr),
1007  0);
1008  TupleDescInitEntryCollation(typeInfo,
1009  cur_resno,
1010  exprCollation((Node *) tle->expr));
1011  cur_resno++;
1012  }
1013 
1014  return typeInfo;
1015 }
int ExecTargetListLength(List *targetlist)
Definition: execUtils.c:1039
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:276
Definition: nodes.h:516
char * resname
Definition: primnodes.h:1377
bool resjunk
Definition: primnodes.h:1382
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:761
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:600
int ExecCleanTargetListLength(List *targetlist)
Definition: execUtils.c:1049
#define lfirst(lc)
Definition: pg_list.h:106
Expr * expr
Definition: primnodes.h:1375
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:720
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:45

◆ ExecTypeSetColNames()

void ExecTypeSetColNames ( TupleDesc  typeInfo,
List namesList 
)

Definition at line 1063 of file execTuples.c.

References lfirst, NameStr, namestrcpy(), tupleDesc::natts, strVal, tupleDesc::tdtypeid, tupleDesc::tdtypmod, and TupleDescAttr.

Referenced by ExecEvalWholeRowVar(), and ExecInitExprRec().

1064 {
1065  bool modified = false;
1066  int colno = 0;
1067  ListCell *lc;
1068 
1069  foreach(lc, namesList)
1070  {
1071  char *cname = strVal(lfirst(lc));
1072  Form_pg_attribute attr;
1073 
1074  /* Guard against too-long names list */
1075  if (colno >= typeInfo->natts)
1076  break;
1077  attr = TupleDescAttr(typeInfo, colno);
1078  colno++;
1079 
1080  /* Ignore empty aliases (these must be for dropped columns) */
1081  if (cname[0] == '\0')
1082  continue;
1083 
1084  /* Change tupdesc only if alias is actually different */
1085  if (strcmp(cname, NameStr(attr->attname)) != 0)
1086  {
1087  namestrcpy(&(attr->attname), cname);
1088  modified = true;
1089  }
1090  }
1091 
1092  /* If we modified the tupdesc, it's now a new record type */
1093  if (modified)
1094  {
1095  typeInfo->tdtypeid = RECORDOID;
1096  typeInfo->tdtypmod = -1;
1097  }
1098 }
Oid tdtypeid
Definition: tupdesc.h:83
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
#define strVal(v)
Definition: value.h:54
int namestrcpy(Name name, const char *str)
Definition: name.c:216
int natts
Definition: tupdesc.h:82
int32 tdtypmod
Definition: tupdesc.h:84
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:197
#define lfirst(lc)
Definition: pg_list.h:106
#define NameStr(name)
Definition: c.h:576

◆ HeapTupleHeaderGetDatum()

Datum HeapTupleHeaderGetDatum ( HeapTupleHeader  tuple)

Definition at line 1284 of file execTuples.c.

References HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, HeapTupleHeaderHasExternal, lookup_rowtype_tupdesc(), PointerGetDatum, ReleaseTupleDesc, and toast_flatten_tuple_to_datum().

Referenced by populate_composite(), and populate_recordset_record().

1285 {
1286  Datum result;
1287  TupleDesc tupDesc;
1288 
1289  /* No work if there are no external TOAST pointers in the tuple */
1290  if (!HeapTupleHeaderHasExternal(tuple))
1291  return PointerGetDatum(tuple);
1292 
1293  /* Use the type data saved by heap_form_tuple to look up the rowtype */
1295  HeapTupleHeaderGetTypMod(tuple));
1296 
1297  /* And do the flattening */
1298  result = toast_flatten_tuple_to_datum(tuple,
1300  tupDesc);
1301 
1302  ReleaseTupleDesc(tupDesc);
1303 
1304  return result;
1305 }
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1641
#define PointerGetDatum(X)
Definition: postgres.h:541
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:467
Datum toast_flatten_tuple_to_datum(HeapTupleHeader tup, uint32 tup_len, TupleDesc tupleDesc)
Definition: tuptoaster.c:1187
uintptr_t Datum
Definition: postgres.h:367
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:457
#define HeapTupleHeaderHasExternal(tup)
Definition: htup_details.h:552
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:124
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

TupleTableSlot* MakeTupleTableSlot ( TupleDesc  tupleDesc)

Definition at line 113 of file execTuples.c.

References CurrentMemoryContext, InvalidBuffer, MAXALIGN, tupleDesc::natts, palloc0(), PinTupleDesc, T_TupleTableSlot, TupleTableSlot::tts_buffer, TupleTableSlot::tts_fixedTupleDescriptor, 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, TupleTableSlot::tts_values, and TupleTableSlot::type.

Referenced by ExecAllocTableSlot(), ExecSetupPartitionTupleRouting(), and MakeSingleTupleTableSlot().

114 {
115  Size sz;
116  TupleTableSlot *slot;
117 
118  /*
119  * When a fixed descriptor is specified, we can reduce overhead by
120  * allocating the entire slot in one go.
121  */
122  if (tupleDesc)
123  sz = MAXALIGN(sizeof(TupleTableSlot)) +
124  MAXALIGN(tupleDesc->natts * sizeof(Datum)) +
125  MAXALIGN(tupleDesc->natts * sizeof(bool));
126  else
127  sz = sizeof(TupleTableSlot);
128 
129  slot = palloc0(sz);
130  slot->type = T_TupleTableSlot;
131  slot->tts_isempty = true;
132  slot->tts_shouldFree = false;
133  slot->tts_shouldFreeMin = false;
134  slot->tts_tuple = NULL;
135  slot->tts_fixedTupleDescriptor = tupleDesc != NULL;
136  slot->tts_tupleDescriptor = tupleDesc;
138  slot->tts_buffer = InvalidBuffer;
139  slot->tts_nvalid = 0;
140  slot->tts_values = NULL;
141  slot->tts_isnull = NULL;
142  slot->tts_mintuple = NULL;
143 
144  if (tupleDesc != NULL)
145  {
146  slot->tts_values = (Datum *)
147  (((char *) slot)
148  + MAXALIGN(sizeof(TupleTableSlot)));
149  slot->tts_isnull = (bool *)
150  (((char *) slot)
151  + MAXALIGN(sizeof(TupleTableSlot))
152  + MAXALIGN(tupleDesc->natts * sizeof(Datum)));
153 
154  PinTupleDesc(tupleDesc);
155  }
156 
157  return slot;
158 }
bool tts_isempty
Definition: tuptable.h:116
#define InvalidBuffer
Definition: buf.h:25
bool tts_shouldFreeMin
Definition: tuptable.h:118
MemoryContext tts_mcxt
Definition: tuptable.h:125
Datum * tts_values
Definition: tuptable.h:130
int natts
Definition: tupdesc.h:82
NodeTag type
Definition: tuptable.h:115
bool * tts_isnull
Definition: tuptable.h:132
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
bool tts_shouldFree
Definition: tuptable.h:117
bool tts_fixedTupleDescriptor
Definition: tuptable.h:137
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void * palloc0(Size size)
Definition: mcxt.c:955
uintptr_t Datum
Definition: postgres.h:367
struct TupleTableSlot TupleTableSlot
size_t Size
Definition: c.h:433
#define MAXALIGN(LEN)
Definition: c.h:652
MinimalTuple tts_mintuple
Definition: tuptable.h:133
#define PinTupleDesc(tupdesc)
Definition: tupdesc.h:118
HeapTuple tts_tuple
Definition: tuptable.h:122
Buffer tts_buffer
Definition: tuptable.h:126

◆ TupleDescGetAttInMetadata()

AttInMetadata* TupleDescGetAttInMetadata ( TupleDesc  tupdesc)

Definition at line 1146 of file execTuples.c.

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

Referenced by bt_metap(), bt_page_items(), bt_page_items_bytea(), bt_page_stats(), build_pgstattuple_type(), connectby_text(), connectby_text_serial(), create_foreign_modify(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), hash_page_items(), libpqrcv_processTuples(), materializeQueryResult(), materializeResult(), pg_config(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls_internal(), pgp_armor_headers(), pgrowlocks(), pgstatindex_impl(), pltcl_build_tuple_result(), pltcl_func_handler(), pltcl_init_tuple_store(), postgresAcquireSampleRowsFunc(), postgresBeginDirectModify(), postgresBeginForeignScan(), prs_setup_firstcall(), show_all_settings(), storeRow(), ts_setup_firstcall(), tt_setup_firstcall(), and xpath_table().

1147 {
1148  int natts = tupdesc->natts;
1149  int i;
1150  Oid atttypeid;
1151  Oid attinfuncid;
1152  FmgrInfo *attinfuncinfo;
1153  Oid *attioparams;
1154  int32 *atttypmods;
1155  AttInMetadata *attinmeta;
1156 
1157  attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
1158 
1159  /* "Bless" the tupledesc so that we can make rowtype datums with it */
1160  attinmeta->tupdesc = BlessTupleDesc(tupdesc);
1161 
1162  /*
1163  * Gather info needed later to call the "in" function for each attribute
1164  */
1165  attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
1166  attioparams = (Oid *) palloc0(natts * sizeof(Oid));
1167  atttypmods = (int32 *) palloc0(natts * sizeof(int32));
1168 
1169  for (i = 0; i < natts; i++)
1170  {
1171  Form_pg_attribute att = TupleDescAttr(tupdesc, i);
1172 
1173  /* Ignore dropped attributes */
1174  if (!att->attisdropped)
1175  {
1176  atttypeid = att->atttypid;
1177  getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
1178  fmgr_info(attinfuncid, &attinfuncinfo[i]);
1179  atttypmods[i] = att->atttypmod;
1180  }
1181  }
1182  attinmeta->attinfuncs = attinfuncinfo;
1183  attinmeta->attioparams = attioparams;
1184  attinmeta->atttypmods = atttypmods;
1185 
1186  return attinmeta;
1187 }
Definition: fmgr.h:56
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
int32 * atttypmods
Definition: funcapi.h:48
unsigned int Oid
Definition: postgres_ext.h:31
Oid * attioparams
Definition: funcapi.h:45
int natts
Definition: tupdesc.h:82
signed int int32
Definition: c.h:313
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:124
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1109
TupleDesc tupdesc
Definition: funcapi.h:39
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:197
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2617
void * palloc0(Size size)
Definition: mcxt.c:955
void * palloc(Size size)
Definition: mcxt.c:924
int i
FmgrInfo * attinfuncs
Definition: funcapi.h:42

◆ TupleDescGetSlot()

TupleTableSlot* TupleDescGetSlot ( TupleDesc  tupdesc)

Definition at line 1126 of file execTuples.c.

References BlessTupleDesc(), and MakeSingleTupleTableSlot().

1127 {
1128  TupleTableSlot *slot;
1129 
1130  /* The useful work is here */
1131  BlessTupleDesc(tupdesc);
1132 
1133  /* Make a standalone slot */
1134  slot = MakeSingleTupleTableSlot(tupdesc);
1135 
1136  /* Return the slot */
1137  return slot;
1138 }
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1109
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc)
Definition: execTuples.c:232