PostgreSQL Source Code  git master
execTuples.c File Reference
#include "postgres.h"
#include "access/heaptoast.h"
#include "access/htup_details.h"
#include "access/tupdesc_details.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "nodes/nodeFuncs.h"
#include "storage/bufmgr.h"
#include "utils/builtins.h"
#include "utils/expandeddatum.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 skipjunk)
 
static pg_attribute_always_inline void slot_deform_heap_tuple (TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int natts)
 
static void tts_buffer_heap_store_tuple (TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
 
static void tts_heap_store_tuple (TupleTableSlot *slot, HeapTuple tuple, bool shouldFree)
 
static void tts_virtual_init (TupleTableSlot *slot)
 
static void tts_virtual_release (TupleTableSlot *slot)
 
static void tts_virtual_clear (TupleTableSlot *slot)
 
static void tts_virtual_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_virtual_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static void tts_virtual_materialize (TupleTableSlot *slot)
 
static void tts_virtual_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static HeapTuple tts_virtual_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_virtual_copy_minimal_tuple (TupleTableSlot *slot)
 
static void tts_heap_init (TupleTableSlot *slot)
 
static void tts_heap_release (TupleTableSlot *slot)
 
static void tts_heap_clear (TupleTableSlot *slot)
 
static void tts_heap_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_heap_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static void tts_heap_materialize (TupleTableSlot *slot)
 
static void tts_heap_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static HeapTuple tts_heap_get_heap_tuple (TupleTableSlot *slot)
 
static HeapTuple tts_heap_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_heap_copy_minimal_tuple (TupleTableSlot *slot)
 
static void tts_minimal_init (TupleTableSlot *slot)
 
static void tts_minimal_release (TupleTableSlot *slot)
 
static void tts_minimal_clear (TupleTableSlot *slot)
 
static void tts_minimal_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_minimal_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static void tts_minimal_materialize (TupleTableSlot *slot)
 
static void tts_minimal_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static MinimalTuple tts_minimal_get_minimal_tuple (TupleTableSlot *slot)
 
static HeapTuple tts_minimal_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_minimal_copy_minimal_tuple (TupleTableSlot *slot)
 
static void tts_minimal_store_tuple (TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
 
static void tts_buffer_heap_init (TupleTableSlot *slot)
 
static void tts_buffer_heap_release (TupleTableSlot *slot)
 
static void tts_buffer_heap_clear (TupleTableSlot *slot)
 
static void tts_buffer_heap_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_buffer_heap_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static void tts_buffer_heap_materialize (TupleTableSlot *slot)
 
static void tts_buffer_heap_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static HeapTuple tts_buffer_heap_get_heap_tuple (TupleTableSlot *slot)
 
static HeapTuple tts_buffer_heap_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_buffer_heap_copy_minimal_tuple (TupleTableSlot *slot)
 
TupleTableSlotMakeTupleTableSlot (TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops)
 
TupleTableSlotExecAllocTableSlot (List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops)
 
void ExecResetTupleTable (List *tupleTable, bool shouldFree)
 
TupleTableSlotMakeSingleTupleTableSlot (TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
 
void ExecDropSingleTupleTableSlot (TupleTableSlot *slot)
 
void ExecSetSlotDescriptor (TupleTableSlot *slot, TupleDesc tupdesc)
 
TupleTableSlotExecStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecStoreBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlotExecStorePinnedBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlotExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecStoreVirtualTuple (TupleTableSlot *slot)
 
TupleTableSlotExecStoreAllNullTuple (TupleTableSlot *slot)
 
void ExecStoreHeapTupleDatum (Datum data, TupleTableSlot *slot)
 
HeapTuple ExecFetchSlotHeapTuple (TupleTableSlot *slot, bool materialize, bool *shouldFree)
 
MinimalTuple ExecFetchSlotMinimalTuple (TupleTableSlot *slot, bool *shouldFree)
 
Datum ExecFetchSlotHeapTupleDatum (TupleTableSlot *slot)
 
void ExecInitResultTypeTL (PlanState *planstate)
 
void ExecInitResultSlot (PlanState *planstate, const TupleTableSlotOps *tts_ops)
 
void ExecInitResultTupleSlotTL (PlanState *planstate, const TupleTableSlotOps *tts_ops)
 
void ExecInitScanTupleSlot (EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
 
TupleTableSlotExecInitExtraTupleSlot (EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
 
TupleTableSlotExecInitNullTupleSlot (EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
 
void slot_getmissingattrs (TupleTableSlot *slot, int startAttNum, int lastAttNum)
 
void slot_getsomeattrs_int (TupleTableSlot *slot, int attnum)
 
TupleDesc ExecTypeFromTL (List *targetList)
 
TupleDesc ExecCleanTypeFromTL (List *targetList)
 
TupleDesc ExecTypeFromExprList (List *exprList)
 
void ExecTypeSetColNames (TupleDesc typeInfo, List *namesList)
 
TupleDesc BlessTupleDesc (TupleDesc tupdesc)
 
AttInMetadataTupleDescGetAttInMetadata (TupleDesc tupdesc)
 
HeapTuple BuildTupleFromCStrings (AttInMetadata *attinmeta, char **values)
 
Datum HeapTupleHeaderGetDatum (HeapTupleHeader tuple)
 
TupOutputStatebegin_tup_output_tupdesc (DestReceiver *dest, TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
 
void do_tup_output (TupOutputState *tstate, const Datum *values, const bool *isnull)
 
void do_text_output_multiline (TupOutputState *tstate, const char *txt)
 
void end_tup_output (TupOutputState *tstate)
 

Variables

const TupleTableSlotOps TTSOpsVirtual
 
const TupleTableSlotOps TTSOpsHeapTuple
 
const TupleTableSlotOps TTSOpsMinimalTuple
 
const TupleTableSlotOps TTSOpsBufferHeapTuple
 

Function Documentation

◆ begin_tup_output_tupdesc()

TupOutputState* begin_tup_output_tupdesc ( DestReceiver dest,
TupleDesc  tupdesc,
const TupleTableSlotOps tts_ops 
)

Definition at line 2256 of file execTuples.c.

2259 {
2260  TupOutputState *tstate;
2261 
2262  tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
2263 
2264  tstate->slot = MakeSingleTupleTableSlot(tupdesc, tts_ops);
2265  tstate->dest = dest;
2266 
2267  tstate->dest->rStartup(tstate->dest, (int) CMD_SELECT, tupdesc);
2268 
2269  return tstate;
2270 }
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1239
void * palloc(Size size)
Definition: mcxt.c:1226
@ CMD_SELECT
Definition: nodes.h:276
TupleTableSlot * slot
Definition: executor.h:505
DestReceiver * dest
Definition: executor.h:506
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: dest.h:120

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

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

◆ BlessTupleDesc()

◆ BuildTupleFromCStrings()

HeapTuple BuildTupleFromCStrings ( AttInMetadata attinmeta,
char **  values 
)

Definition at line 2136 of file execTuples.c.

2137 {
2138  TupleDesc tupdesc = attinmeta->tupdesc;
2139  int natts = tupdesc->natts;
2140  Datum *dvalues;
2141  bool *nulls;
2142  int i;
2143  HeapTuple tuple;
2144 
2145  dvalues = (Datum *) palloc(natts * sizeof(Datum));
2146  nulls = (bool *) palloc(natts * sizeof(bool));
2147 
2148  /*
2149  * Call the "in" function for each non-dropped attribute, even for nulls,
2150  * to support domains.
2151  */
2152  for (i = 0; i < natts; i++)
2153  {
2154  if (!TupleDescAttr(tupdesc, i)->attisdropped)
2155  {
2156  /* Non-dropped attributes */
2157  dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
2158  values[i],
2159  attinmeta->attioparams[i],
2160  attinmeta->atttypmods[i]);
2161  if (values[i] != NULL)
2162  nulls[i] = false;
2163  else
2164  nulls[i] = true;
2165  }
2166  else
2167  {
2168  /* Handle dropped attributes by setting to NULL */
2169  dvalues[i] = (Datum) 0;
2170  nulls[i] = true;
2171  }
2172  }
2173 
2174  /*
2175  * Form a tuple
2176  */
2177  tuple = heap_form_tuple(tupdesc, dvalues, nulls);
2178 
2179  /*
2180  * Release locally palloc'd space. XXX would probably be good to pfree
2181  * values of pass-by-reference datums, as well.
2182  */
2183  pfree(dvalues);
2184  pfree(nulls);
2185 
2186  return tuple;
2187 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1513
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1456
uintptr_t Datum
Definition: postgres.h:64
FmgrInfo * attinfuncs
Definition: funcapi.h:41
TupleDesc tupdesc
Definition: funcapi.h:38
Oid * attioparams
Definition: funcapi.h:44
int32 * atttypmods
Definition: funcapi.h:47
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

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

Referenced by bt_metap(), bt_multi_page_stats(), bt_page_stats_internal(), build_pgstattuple_type(), build_tuplestore_recursively(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), libpqrcv_processTuples(), materializeResult(), 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().

◆ do_text_output_multiline()

void do_text_output_multiline ( TupOutputState tstate,
const char *  txt 
)

Definition at line 2304 of file execTuples.c.

2305 {
2306  Datum values[1];
2307  bool isnull[1] = {false};
2308 
2309  while (*txt)
2310  {
2311  const char *eol;
2312  int len;
2313 
2314  eol = strchr(txt, '\n');
2315  if (eol)
2316  {
2317  len = eol - txt;
2318  eol++;
2319  }
2320  else
2321  {
2322  len = strlen(txt);
2323  eol = txt + len;
2324  }
2325 
2327  do_tup_output(tstate, values, isnull);
2329  txt = eol;
2330  }
2331 }
void do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull)
Definition: execTuples.c:2276
const void size_t len
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:196

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

Referenced by ExplainQuery().

◆ do_tup_output()

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

Definition at line 2276 of file execTuples.c.

2277 {
2278  TupleTableSlot *slot = tstate->slot;
2279  int natts = slot->tts_tupleDescriptor->natts;
2280 
2281  /* make sure the slot is clear */
2282  ExecClearTuple(slot);
2283 
2284  /* insert data */
2285  memcpy(slot->tts_values, values, natts * sizeof(Datum));
2286  memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
2287 
2288  /* mark slot as containing a virtual tuple */
2289  ExecStoreVirtualTuple(slot);
2290 
2291  /* send the tuple to the receiver */
2292  (void) tstate->dest->receiveSlot(slot, tstate->dest);
2293 
2294  /* clean up */
2295  ExecClearTuple(slot);
2296 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1553
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
bool * tts_isnull
Definition: tuptable.h:127
Datum * tts_values
Definition: tuptable.h:125
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:117
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:432

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

Referenced by CreateReplicationSlot(), do_text_output_multiline(), IdentifySystem(), ReadReplicationSlot(), SendTablespaceList(), SendXlogRecPtrResult(), ShowAllGUCConfig(), and StartReplication().

◆ end_tup_output()

void end_tup_output ( TupOutputState tstate)

Definition at line 2334 of file execTuples.c.

2335 {
2336  tstate->dest->rShutdown(tstate->dest);
2337  /* note that destroying the dest is not ours to do */
2339  pfree(tstate);
2340 }
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1255
void(* rShutdown)(DestReceiver *self)
Definition: dest.h:123

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

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

◆ ExecAllocTableSlot()

TupleTableSlot* ExecAllocTableSlot ( List **  tupleTable,
TupleDesc  desc,
const TupleTableSlotOps tts_ops 
)

Definition at line 1172 of file execTuples.c.

1174 {
1175  TupleTableSlot *slot = MakeTupleTableSlot(desc, tts_ops);
1176 
1177  *tupleTable = lappend(*tupleTable, slot);
1178 
1179  return slot;
1180 }
TupleTableSlot * MakeTupleTableSlot(TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1113
List * lappend(List *list, void *datum)
Definition: list.c:338

References lappend(), and MakeTupleTableSlot().

Referenced by ExecInitExtraTupleSlot(), ExecInitIndexOnlyScan(), ExecInitResultSlot(), ExecInitScanTupleSlot(), and find_hash_columns().

◆ ExecCleanTypeFromTL()

TupleDesc ExecCleanTypeFromTL ( List targetList)

Definition at line 1951 of file execTuples.c.

1952 {
1953  return ExecTypeFromTLInternal(targetList, true);
1954 }
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool skipjunk)
Definition: execTuples.c:1957

References ExecTypeFromTLInternal().

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

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 1255 of file execTuples.c.

1256 {
1257  /* This should match ExecResetTupleTable's processing of one slot */
1258  Assert(IsA(slot, TupleTableSlot));
1259  ExecClearTuple(slot);
1260  slot->tts_ops->release(slot);
1261  if (slot->tts_tupleDescriptor)
1263  if (!TTS_FIXED(slot))
1264  {
1265  if (slot->tts_values)
1266  pfree(slot->tts_values);
1267  if (slot->tts_isnull)
1268  pfree(slot->tts_isnull);
1269  }
1270  pfree(slot);
1271 }
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
void(* release)(TupleTableSlot *slot)
Definition: tuptable.h:143
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:121
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define TTS_FIXED(slot)
Definition: tuptable.h:108

References Assert(), ExecClearTuple(), IsA, pfree(), TupleTableSlotOps::release, ReleaseTupleDesc, TTS_FIXED, TupleTableSlot::tts_isnull, TupleTableSlot::tts_ops, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by acquire_sample_rows(), AfterTriggerFreeQuery(), afterTriggerInvokeEvents(), AlterDomainNotNull(), ATRewriteTable(), CatalogIndexInsert(), check_default_partition_contents(), check_exclusion_or_unique_constraint(), check_publications(), check_publications_origin(), compute_expr_stats(), compute_index_stats(), CopyMultiInsertBufferCleanup(), copyTemplateDependencies(), DefineTSConfiguration(), DoCopyTo(), end_tup_output(), EnumValuesCreate(), ExecCleanupTupleRouting(), ExecEndIncrementalSort(), ExecEndModifyTable(), fetch_remote_table_info(), fetch_table_list(), freestate_cluster(), get_actual_variable_range(), get_rel_sync_entry(), heap_entry_is_visible(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), hypothetical_dense_rank_final(), IndexCheckExclusion(), InsertPgAttributeTuples(), make_build_data(), MakeConfigurationMapping(), recordMultipleDependencies(), RelationFindReplTupleSeq(), RI_Initial_Check(), RunFromStore(), systable_endscan(), systable_endscan_ordered(), table_index_fetch_tuple_check(), tstoreShutdownReceiver(), validateDomainConstraint(), and validateForeignKeyConstraint().

◆ ExecFetchSlotHeapTuple()

HeapTuple ExecFetchSlotHeapTuple ( TupleTableSlot slot,
bool  materialize,
bool shouldFree 
)

Definition at line 1645 of file execTuples.c.

1646 {
1647  /*
1648  * sanity checks
1649  */
1650  Assert(slot != NULL);
1651  Assert(!TTS_EMPTY(slot));
1652 
1653  /* Materialize the tuple so that the slot "owns" it, if requested. */
1654  if (materialize)
1655  slot->tts_ops->materialize(slot);
1656 
1657  if (slot->tts_ops->get_heap_tuple == NULL)
1658  {
1659  if (shouldFree)
1660  *shouldFree = true;
1661  return slot->tts_ops->copy_heap_tuple(slot);
1662  }
1663  else
1664  {
1665  if (shouldFree)
1666  *shouldFree = false;
1667  return slot->tts_ops->get_heap_tuple(slot);
1668  }
1669 }
HeapTuple(* get_heap_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:187
HeapTuple(* copy_heap_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:205
void(* materialize)(TupleTableSlot *slot)
Definition: tuptable.h:173
#define TTS_EMPTY(slot)
Definition: tuptable.h:96

References Assert(), TupleTableSlotOps::copy_heap_tuple, TupleTableSlotOps::get_heap_tuple, TupleTableSlotOps::materialize, TTS_EMPTY, and TupleTableSlot::tts_ops.

Referenced by AfterTriggerExecute(), apply_returning_filter(), CatalogTuplesMultiInsertWithInfo(), ExecBRDeleteTriggers(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecFetchSlotHeapTupleDatum(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), heap_multi_insert(), heapam_relation_copy_for_cluster(), heapam_tuple_complete_speculative(), heapam_tuple_insert(), heapam_tuple_insert_speculative(), heapam_tuple_update(), systable_getnext(), systable_getnext_ordered(), systable_recheck_tuple(), and validateForeignKeyConstraint().

◆ ExecFetchSlotHeapTupleDatum()

Datum ExecFetchSlotHeapTupleDatum ( TupleTableSlot slot)

Definition at line 1724 of file execTuples.c.

1725 {
1726  HeapTuple tup;
1727  TupleDesc tupdesc;
1728  bool shouldFree;
1729  Datum ret;
1730 
1731  /* Fetch slot's contents in regular-physical-tuple form */
1732  tup = ExecFetchSlotHeapTuple(slot, false, &shouldFree);
1733  tupdesc = slot->tts_tupleDescriptor;
1734 
1735  /* Convert to Datum form */
1736  ret = heap_copy_tuple_as_datum(tup, tupdesc);
1737 
1738  if (shouldFree)
1739  pfree(tup);
1740 
1741  return ret;
1742 }
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
Definition: execTuples.c:1645
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:1081

References ExecFetchSlotHeapTuple(), heap_copy_tuple_as_datum(), pfree(), and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecMakeFunctionResultSet(), and postquel_get_single_result().

◆ ExecFetchSlotMinimalTuple()

MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot,
bool shouldFree 
)

Definition at line 1693 of file execTuples.c.

1695 {
1696  /*
1697  * sanity checks
1698  */
1699  Assert(slot != NULL);
1700  Assert(!TTS_EMPTY(slot));
1701 
1702  if (slot->tts_ops->get_minimal_tuple)
1703  {
1704  if (shouldFree)
1705  *shouldFree = false;
1706  return slot->tts_ops->get_minimal_tuple(slot);
1707  }
1708  else
1709  {
1710  if (shouldFree)
1711  *shouldFree = true;
1712  return slot->tts_ops->copy_minimal_tuple(slot);
1713  }
1714 }
MinimalTuple(* copy_minimal_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:215
MinimalTuple(* get_minimal_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:195

References Assert(), TupleTableSlotOps::copy_minimal_tuple, TupleTableSlotOps::get_minimal_tuple, TTS_EMPTY, and TupleTableSlot::tts_ops.

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

◆ ExecForceStoreHeapTuple()

void ExecForceStoreHeapTuple ( HeapTuple  tuple,
TupleTableSlot slot,
bool  shouldFree 
)

Definition at line 1470 of file execTuples.c.

1473 {
1474  if (TTS_IS_HEAPTUPLE(slot))
1475  {
1476  ExecStoreHeapTuple(tuple, slot, shouldFree);
1477  }
1478  else if (TTS_IS_BUFFERTUPLE(slot))
1479  {
1480  MemoryContext oldContext;
1482 
1483  ExecClearTuple(slot);
1484  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1485  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
1486  bslot->base.tuple = heap_copytuple(tuple);
1487  slot->tts_flags |= TTS_FLAG_SHOULDFREE;
1488  MemoryContextSwitchTo(oldContext);
1489 
1490  if (shouldFree)
1491  pfree(tuple);
1492  }
1493  else
1494  {
1495  ExecClearTuple(slot);
1497  slot->tts_values, slot->tts_isnull);
1498  ExecStoreVirtualTuple(slot);
1499 
1500  if (shouldFree)
1501  {
1502  ExecMaterializeSlot(slot);
1503  pfree(tuple);
1504  }
1505  }
1506 }
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1353
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:777
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1346
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
MemoryContext tts_mcxt
Definition: tuptable.h:128
uint16 tts_flags
Definition: tuptable.h:118
#define TTS_FLAG_EMPTY
Definition: tuptable.h:95
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:99
#define TTS_IS_BUFFERTUPLE(slot)
Definition: tuptable.h:230
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:450
#define TTS_IS_HEAPTUPLE(slot)
Definition: tuptable.h:228

References ExecClearTuple(), ExecMaterializeSlot(), ExecStoreHeapTuple(), ExecStoreVirtualTuple(), heap_copytuple(), heap_deform_tuple(), MemoryContextSwitchTo(), pfree(), TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TTS_IS_BUFFERTUPLE, TTS_IS_HEAPTUPLE, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by agg_retrieve_direct(), ExecARDeleteTriggers(), ExecARUpdateTriggers(), ExecBRDeleteTriggers(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecIRDeleteTriggers(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecModifyTable(), IndexNextWithReorder(), IndexOnlyNext(), and store_returning_result().

◆ ExecForceStoreMinimalTuple()

void ExecForceStoreMinimalTuple ( MinimalTuple  mtup,
TupleTableSlot slot,
bool  shouldFree 
)

Definition at line 1513 of file execTuples.c.

1516 {
1517  if (TTS_IS_MINIMALTUPLE(slot))
1518  {
1519  tts_minimal_store_tuple(slot, mtup, shouldFree);
1520  }
1521  else
1522  {
1523  HeapTupleData htup;
1524 
1525  ExecClearTuple(slot);
1526 
1527  htup.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
1528  htup.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
1530  slot->tts_values, slot->tts_isnull);
1531  ExecStoreVirtualTuple(slot);
1532 
1533  if (shouldFree)
1534  {
1535  ExecMaterializeSlot(slot);
1536  pfree(mtup);
1537  }
1538  }
1539 }
static void tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
Definition: execTuples.c:621
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:617
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
#define TTS_IS_MINIMALTUPLE(slot)
Definition: tuptable.h:229

References ExecClearTuple(), ExecMaterializeSlot(), ExecStoreVirtualTuple(), heap_deform_tuple(), MINIMAL_TUPLE_OFFSET, pfree(), HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, TTS_IS_MINIMALTUPLE, TupleTableSlot::tts_isnull, tts_minimal_store_tuple(), TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by ExecHashJoinGetSavedTuple(), ExecParallelHashJoinNewBatch(), and ExecParallelHashJoinOuterGetTuple().

◆ ExecInitExtraTupleSlot()

TupleTableSlot* ExecInitExtraTupleSlot ( EState estate,
TupleDesc  tupledesc,
const TupleTableSlotOps tts_ops 
)

◆ ExecInitNullTupleSlot()

TupleTableSlot* ExecInitNullTupleSlot ( EState estate,
TupleDesc  tupType,
const TupleTableSlotOps tts_ops 
)

Definition at line 1848 of file execTuples.c.

1850 {
1851  TupleTableSlot *slot = ExecInitExtraTupleSlot(estate, tupType, tts_ops);
1852 
1853  return ExecStoreAllNullTuple(slot);
1854 }
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
Definition: execTuples.c:1577
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1832

References ExecInitExtraTupleSlot(), and ExecStoreAllNullTuple().

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

◆ ExecInitResultSlot()

void ExecInitResultSlot ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

Definition at line 1780 of file execTuples.c.

1781 {
1782  TupleTableSlot *slot;
1783 
1784  slot = ExecAllocTableSlot(&planstate->state->es_tupleTable,
1785  planstate->ps_ResultTupleDesc, tts_ops);
1786  planstate->ps_ResultTupleSlot = slot;
1787 
1788  planstate->resultopsfixed = planstate->ps_ResultTupleDesc != NULL;
1789  planstate->resultops = tts_ops;
1790  planstate->resultopsset = true;
1791 }
const TupleTableSlotOps * resultops
Definition: execnodes.h:1113
bool resultopsset
Definition: execnodes.h:1121
EState * state
Definition: execnodes.h:1038
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1073
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1074
bool resultopsfixed
Definition: execnodes.h:1117

References EState::es_tupleTable, ExecAllocTableSlot(), PlanState::ps_ResultTupleDesc, PlanState::ps_ResultTupleSlot, PlanState::resultops, PlanState::resultopsfixed, PlanState::resultopsset, and PlanState::state.

Referenced by ExecConditionalAssignProjectionInfo(), and ExecInitResultTupleSlotTL().

◆ ExecInitResultTupleSlotTL()

void ExecInitResultTupleSlotTL ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

◆ ExecInitResultTypeTL()

◆ ExecInitScanTupleSlot()

void ExecInitScanTupleSlot ( EState estate,
ScanState scanstate,
TupleDesc  tupledesc,
const TupleTableSlotOps tts_ops 
)

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 1192 of file execTuples.c.

1194 {
1195  ListCell *lc;
1196 
1197  foreach(lc, tupleTable)
1198  {
1200 
1201  /* Always release resources and reset the slot to empty */
1202  ExecClearTuple(slot);
1203  slot->tts_ops->release(slot);
1204  if (slot->tts_tupleDescriptor)
1205  {
1207  slot->tts_tupleDescriptor = NULL;
1208  }
1209 
1210  /* If shouldFree, release memory occupied by the slot itself */
1211  if (shouldFree)
1212  {
1213  if (!TTS_FIXED(slot))
1214  {
1215  if (slot->tts_values)
1216  pfree(slot->tts_values);
1217  if (slot->tts_isnull)
1218  pfree(slot->tts_isnull);
1219  }
1220  pfree(slot);
1221  }
1222  }
1223 
1224  /* If shouldFree, release the list structure */
1225  if (shouldFree)
1226  list_free(tupleTable);
1227 }
void list_free(List *list)
Definition: list.c:1545
#define lfirst_node(type, lc)
Definition: pg_list.h:176

References ExecClearTuple(), lfirst_node, list_free(), pfree(), TupleTableSlotOps::release, ReleaseTupleDesc, TTS_FIXED, TupleTableSlot::tts_isnull, TupleTableSlot::tts_ops, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

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

◆ ExecSetSlotDescriptor()

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 1290 of file execTuples.c.

1292 {
1293  Assert(!TTS_FIXED(slot));
1294 
1295  /* For safety, make sure slot is empty before changing it */
1296  ExecClearTuple(slot);
1297 
1298  /*
1299  * Release any old descriptor. Also release old Datum/isnull arrays if
1300  * present (we don't bother to check if they could be re-used).
1301  */
1302  if (slot->tts_tupleDescriptor)
1304 
1305  if (slot->tts_values)
1306  pfree(slot->tts_values);
1307  if (slot->tts_isnull)
1308  pfree(slot->tts_isnull);
1309 
1310  /*
1311  * Install the new descriptor; if it's refcounted, bump its refcount.
1312  */
1313  slot->tts_tupleDescriptor = tupdesc;
1314  PinTupleDesc(tupdesc);
1315 
1316  /*
1317  * Allocate Datum/isnull arrays of the appropriate size. These must have
1318  * the same lifetime as the slot, so allocate in the slot's own context.
1319  */
1320  slot->tts_values = (Datum *)
1321  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
1322  slot->tts_isnull = (bool *)
1323  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(bool));
1324 }
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1021
#define PinTupleDesc(tupdesc)
Definition: tupdesc.h:116

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

Referenced by ExecAssignScanType(), ExecInitJunkFilter(), and ExecInitJunkFilterConversion().

◆ ExecStoreAllNullTuple()

TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 1577 of file execTuples.c.

1578 {
1579  /*
1580  * sanity checks
1581  */
1582  Assert(slot != NULL);
1583  Assert(slot->tts_tupleDescriptor != NULL);
1584 
1585  /* Clear any old contents */
1586  ExecClearTuple(slot);
1587 
1588  /*
1589  * Fill all the columns of the virtual tuple with nulls
1590  */
1591  MemSet(slot->tts_values, 0,
1592  slot->tts_tupleDescriptor->natts * sizeof(Datum));
1593  memset(slot->tts_isnull, true,
1594  slot->tts_tupleDescriptor->natts * sizeof(bool));
1595 
1596  return ExecStoreVirtualTuple(slot);
1597 }
#define MemSet(start, val, len)
Definition: c.h:1009

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

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

◆ ExecStoreBufferHeapTuple()

TupleTableSlot* ExecStoreBufferHeapTuple ( HeapTuple  tuple,
TupleTableSlot slot,
Buffer  buffer 
)

Definition at line 1393 of file execTuples.c.

1396 {
1397  /*
1398  * sanity checks
1399  */
1400  Assert(tuple != NULL);
1401  Assert(slot != NULL);
1402  Assert(slot->tts_tupleDescriptor != NULL);
1403  Assert(BufferIsValid(buffer));
1404 
1405  if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1406  elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1407  tts_buffer_heap_store_tuple(slot, tuple, buffer, false);
1408 
1409  slot->tts_tableOid = tuple->t_tableOid;
1410 
1411  return slot;
1412 }
static bool BufferIsValid(Buffer bufnum)
Definition: bufmgr.h:301
#define unlikely(x)
Definition: c.h:300
#define ERROR
Definition: elog.h:39
static void tts_buffer_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
Definition: execTuples.c:860
Oid t_tableOid
Definition: htup.h:66
Oid tts_tableOid
Definition: tuptable.h:130

References Assert(), BufferIsValid(), elog(), ERROR, HeapTupleData::t_tableOid, tts_buffer_heap_store_tuple(), TTS_IS_BUFFERTUPLE, TupleTableSlot::tts_tableOid, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by heap_getnextslot(), heap_getnextslot_tidrange(), heapam_index_build_range_scan(), heapam_index_fetch_tuple(), heapam_scan_analyze_next_tuple(), heapam_scan_bitmap_next_tuple(), and heapam_scan_sample_next_tuple().

◆ ExecStoreHeapTuple()

TupleTableSlot* ExecStoreHeapTuple ( HeapTuple  tuple,
TupleTableSlot slot,
bool  shouldFree 
)

Definition at line 1353 of file execTuples.c.

1356 {
1357  /*
1358  * sanity checks
1359  */
1360  Assert(tuple != NULL);
1361  Assert(slot != NULL);
1362  Assert(slot->tts_tupleDescriptor != NULL);
1363 
1364  if (unlikely(!TTS_IS_HEAPTUPLE(slot)))
1365  elog(ERROR, "trying to store a heap tuple into wrong type of slot");
1366  tts_heap_store_tuple(slot, tuple, shouldFree);
1367 
1368  slot->tts_tableOid = tuple->t_tableOid;
1369 
1370  return slot;
1371 }
static void tts_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, bool shouldFree)
Definition: execTuples.c:448

References Assert(), elog(), ERROR, HeapTupleData::t_tableOid, tts_heap_store_tuple(), TTS_IS_HEAPTUPLE, TupleTableSlot::tts_tableOid, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by CatalogIndexInsert(), comparetup_cluster_tiebreak(), compute_expr_stats(), compute_index_stats(), ExecForceStoreHeapTuple(), ExecuteCallStmt(), get_returning_data(), heapam_index_validate_scan(), make_build_data(), pgoutput_change(), postgresIterateForeignScan(), setop_retrieve_direct(), and tts_heap_copyslot().

◆ ExecStoreHeapTupleDatum()

void ExecStoreHeapTupleDatum ( Datum  data,
TupleTableSlot slot 
)

Definition at line 1607 of file execTuples.c.

1608 {
1609  HeapTupleData tuple = {0};
1610  HeapTupleHeader td;
1611 
1613 
1615  tuple.t_self = td->t_ctid;
1616  tuple.t_data = td;
1617 
1618  ExecClearTuple(slot);
1619 
1620  heap_deform_tuple(&tuple, slot->tts_tupleDescriptor,
1621  slot->tts_values, slot->tts_isnull);
1622  ExecStoreVirtualTuple(slot);
1623 }
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
const void * data
ItemPointerData t_self
Definition: htup.h:65
ItemPointerData t_ctid
Definition: htup_details.h:161

References data, DatumGetHeapTupleHeader, ExecClearTuple(), ExecStoreVirtualTuple(), heap_deform_tuple(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by EvalPlanQualFetchRowMark().

◆ ExecStoreMinimalTuple()

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

◆ ExecStorePinnedBufferHeapTuple()

TupleTableSlot* ExecStorePinnedBufferHeapTuple ( HeapTuple  tuple,
TupleTableSlot slot,
Buffer  buffer 
)

Definition at line 1419 of file execTuples.c.

1422 {
1423  /*
1424  * sanity checks
1425  */
1426  Assert(tuple != NULL);
1427  Assert(slot != NULL);
1428  Assert(slot->tts_tupleDescriptor != NULL);
1429  Assert(BufferIsValid(buffer));
1430 
1431  if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1432  elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1433  tts_buffer_heap_store_tuple(slot, tuple, buffer, true);
1434 
1435  slot->tts_tableOid = tuple->t_tableOid;
1436 
1437  return slot;
1438 }

References Assert(), BufferIsValid(), elog(), ERROR, HeapTupleData::t_tableOid, tts_buffer_heap_store_tuple(), TTS_IS_BUFFERTUPLE, TupleTableSlot::tts_tableOid, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by heapam_fetch_row_version(), and heapam_tuple_lock().

◆ ExecStoreVirtualTuple()

TupleTableSlot* ExecStoreVirtualTuple ( TupleTableSlot slot)

Definition at line 1553 of file execTuples.c.

1554 {
1555  /*
1556  * sanity checks
1557  */
1558  Assert(slot != NULL);
1559  Assert(slot->tts_tupleDescriptor != NULL);
1560  Assert(TTS_EMPTY(slot));
1561 
1562  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1563  slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
1564 
1565  return slot;
1566 }
AttrNumber tts_nvalid
Definition: tuptable.h:120

References Assert(), TupleDescData::natts, TTS_EMPTY, TTS_FLAG_EMPTY, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, and TupleTableSlot::tts_tupleDescriptor.

Referenced by agg_retrieve_hash_table_in_memory(), apply_returning_filter(), ATRewriteTable(), CopyFrom(), copyTemplateDependencies(), DefineTSConfiguration(), do_tup_output(), EnumValuesCreate(), ExecComputeStoredGenerated(), ExecEvalAggOrderedTransTuple(), ExecEvalPreOrderedDistinctMulti(), ExecFilterJunk(), ExecForceStoreHeapTuple(), ExecForceStoreMinimalTuple(), ExecProjectSRF(), ExecSort(), ExecStoreAllNullTuple(), ExecStoreHeapTupleDatum(), execute_attr_map_slot(), fileIterateForeignScan(), FunctionNext(), hashagg_spill_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), InsertPgAttributeTuples(), MakeConfigurationMapping(), ordered_set_transition_multi(), pgoutput_row_filter(), prepare_hash_slot(), prepare_probe_slot(), recordMultipleDependencies(), RI_Initial_Check(), RI_PartitionRemove_Check(), slot_modify_data(), slot_store_data(), StoreIndexTuple(), and ValuesNext().

◆ ExecTypeFromExprList()

TupleDesc ExecTypeFromExprList ( List exprList)

Definition at line 1998 of file execTuples.c.

1999 {
2000  TupleDesc typeInfo;
2001  ListCell *lc;
2002  int cur_resno = 1;
2003 
2004  typeInfo = CreateTemplateTupleDesc(list_length(exprList));
2005 
2006  foreach(lc, exprList)
2007  {
2008  Node *e = lfirst(lc);
2009 
2010  TupleDescInitEntry(typeInfo,
2011  cur_resno,
2012  NULL,
2013  exprType(e),
2014  exprTypmod(e),
2015  0);
2016  TupleDescInitEntryCollation(typeInfo,
2017  cur_resno,
2018  exprCollation(e));
2019  cur_resno++;
2020  }
2021 
2022  return typeInfo;
2023 }
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:282
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:786
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
e
Definition: preproc-init.c:82
Definition: nodes.h:129
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:67
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:789
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:605

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

Referenced by ExecInitExprRec(), ExecInitMemoize(), and ExecInitValuesScan().

◆ ExecTypeFromTL()

TupleDesc ExecTypeFromTL ( List targetList)

◆ ExecTypeFromTLInternal()

static TupleDesc ExecTypeFromTLInternal ( List targetList,
bool  skipjunk 
)
static

Definition at line 1957 of file execTuples.c.

1958 {
1959  TupleDesc typeInfo;
1960  ListCell *l;
1961  int len;
1962  int cur_resno = 1;
1963 
1964  if (skipjunk)
1965  len = ExecCleanTargetListLength(targetList);
1966  else
1967  len = ExecTargetListLength(targetList);
1968  typeInfo = CreateTemplateTupleDesc(len);
1969 
1970  foreach(l, targetList)
1971  {
1972  TargetEntry *tle = lfirst(l);
1973 
1974  if (skipjunk && tle->resjunk)
1975  continue;
1976  TupleDescInitEntry(typeInfo,
1977  cur_resno,
1978  tle->resname,
1979  exprType((Node *) tle->expr),
1980  exprTypmod((Node *) tle->expr),
1981  0);
1982  TupleDescInitEntryCollation(typeInfo,
1983  cur_resno,
1984  exprCollation((Node *) tle->expr));
1985  cur_resno++;
1986  }
1987 
1988  return typeInfo;
1989 }
int ExecTargetListLength(List *targetlist)
Definition: execUtils.c:1114
int ExecCleanTargetListLength(List *targetlist)
Definition: execUtils.c:1124
Expr * expr
Definition: primnodes.h:1922

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

Referenced by ExecCleanTypeFromTL(), and ExecTypeFromTL().

◆ ExecTypeSetColNames()

void ExecTypeSetColNames ( TupleDesc  typeInfo,
List namesList 
)

Definition at line 2031 of file execTuples.c.

2032 {
2033  int colno = 0;
2034  ListCell *lc;
2035 
2036  /* It's only OK to change col names in a not-yet-blessed RECORD type */
2037  Assert(typeInfo->tdtypeid == RECORDOID);
2038  Assert(typeInfo->tdtypmod < 0);
2039 
2040  foreach(lc, namesList)
2041  {
2042  char *cname = strVal(lfirst(lc));
2043  Form_pg_attribute attr;
2044 
2045  /* Guard against too-long names list (probably can't happen) */
2046  if (colno >= typeInfo->natts)
2047  break;
2048  attr = TupleDescAttr(typeInfo, colno);
2049  colno++;
2050 
2051  /*
2052  * Do nothing for empty aliases or dropped columns (these cases
2053  * probably can't arise in RECORD types, either)
2054  */
2055  if (cname[0] == '\0' || attr->attisdropped)
2056  continue;
2057 
2058  /* OK, assign the column name */
2059  namestrcpy(&(attr->attname), cname);
2060  }
2061 }
void namestrcpy(Name name, const char *str)
Definition: name.c:233
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
#define strVal(v)
Definition: value.h:82

References Assert(), lfirst, namestrcpy(), TupleDescData::natts, strVal, TupleDescData::tdtypeid, TupleDescData::tdtypmod, and TupleDescAttr.

Referenced by ExecEvalWholeRowVar(), and ExecInitExprRec().

◆ HeapTupleHeaderGetDatum()

Datum HeapTupleHeaderGetDatum ( HeapTupleHeader  tuple)

Definition at line 2225 of file execTuples.c.

2226 {
2227  Datum result;
2228  TupleDesc tupDesc;
2229 
2230  /* No work if there are no external TOAST pointers in the tuple */
2231  if (!HeapTupleHeaderHasExternal(tuple))
2232  return PointerGetDatum(tuple);
2233 
2234  /* Use the type data saved by heap_form_tuple to look up the rowtype */
2236  HeapTupleHeaderGetTypMod(tuple));
2237 
2238  /* And do the flattening */
2239  result = toast_flatten_tuple_to_datum(tuple,
2241  tupDesc);
2242 
2243  ReleaseTupleDesc(tupDesc);
2244 
2245  return result;
2246 }
Datum toast_flatten_tuple_to_datum(HeapTupleHeader tup, uint32 tup_len, TupleDesc tupleDesc)
Definition: heaptoast.c:449
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:466
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderHasExternal(tup)
Definition: htup_details.h:537
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1830

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

Referenced by HeapTupleGetDatum(), populate_composite(), and populate_recordset_record().

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

TupleTableSlot* MakeTupleTableSlot ( TupleDesc  tupleDesc,
const TupleTableSlotOps tts_ops 
)

Definition at line 1113 of file execTuples.c.

1115 {
1116  Size basesz,
1117  allocsz;
1118  TupleTableSlot *slot;
1119 
1120  basesz = tts_ops->base_slot_size;
1121 
1122  /*
1123  * When a fixed descriptor is specified, we can reduce overhead by
1124  * allocating the entire slot in one go.
1125  */
1126  if (tupleDesc)
1127  allocsz = MAXALIGN(basesz) +
1128  MAXALIGN(tupleDesc->natts * sizeof(Datum)) +
1129  MAXALIGN(tupleDesc->natts * sizeof(bool));
1130  else
1131  allocsz = basesz;
1132 
1133  slot = palloc0(allocsz);
1134  /* const for optimization purposes, OK to modify at allocation time */
1135  *((const TupleTableSlotOps **) &slot->tts_ops) = tts_ops;
1136  slot->type = T_TupleTableSlot;
1137  slot->tts_flags |= TTS_FLAG_EMPTY;
1138  if (tupleDesc != NULL)
1139  slot->tts_flags |= TTS_FLAG_FIXED;
1140  slot->tts_tupleDescriptor = tupleDesc;
1142  slot->tts_nvalid = 0;
1143 
1144  if (tupleDesc != NULL)
1145  {
1146  slot->tts_values = (Datum *)
1147  (((char *) slot)
1148  + MAXALIGN(basesz));
1149  slot->tts_isnull = (bool *)
1150  (((char *) slot)
1151  + MAXALIGN(basesz)
1152  + MAXALIGN(tupleDesc->natts * sizeof(Datum)));
1153 
1154  PinTupleDesc(tupleDesc);
1155  }
1156 
1157  /*
1158  * And allow slot type specific initialization.
1159  */
1160  slot->tts_ops->init(slot);
1161 
1162  return slot;
1163 }
#define MAXALIGN(LEN)
Definition: c.h:800
size_t Size
Definition: c.h:594
void * palloc0(Size size)
Definition: mcxt.c:1257
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
size_t base_slot_size
Definition: tuptable.h:137
void(* init)(TupleTableSlot *slot)
Definition: tuptable.h:140
NodeTag type
Definition: tuptable.h:116
#define TTS_FLAG_FIXED
Definition: tuptable.h:107

References TupleTableSlotOps::base_slot_size, CurrentMemoryContext, TupleTableSlotOps::init, MAXALIGN, TupleDescData::natts, palloc0(), PinTupleDesc, TTS_FLAG_EMPTY, TTS_FLAG_FIXED, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_ops, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and TupleTableSlot::type.

Referenced by ExecAllocTableSlot(), ExecConstraints(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), MakeSingleTupleTableSlot(), and pgoutput_change().

◆ slot_deform_heap_tuple()

static pg_attribute_always_inline void slot_deform_heap_tuple ( TupleTableSlot slot,
HeapTuple  tuple,
uint32 offp,
int  natts 
)
static

Definition at line 926 of file execTuples.c.

928 {
929  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
930  Datum *values = slot->tts_values;
931  bool *isnull = slot->tts_isnull;
932  HeapTupleHeader tup = tuple->t_data;
933  bool hasnulls = HeapTupleHasNulls(tuple);
934  int attnum;
935  char *tp; /* ptr to tuple data */
936  uint32 off; /* offset in tuple data */
937  bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
938  bool slow; /* can we use/set attcacheoff? */
939 
940  /* We can only fetch as many attributes as the tuple has. */
941  natts = Min(HeapTupleHeaderGetNatts(tuple->t_data), natts);
942 
943  /*
944  * Check whether the first call for this tuple, and initialize or restore
945  * loop state.
946  */
947  attnum = slot->tts_nvalid;
948  if (attnum == 0)
949  {
950  /* Start from the first attribute */
951  off = 0;
952  slow = false;
953  }
954  else
955  {
956  /* Restore state from previous execution */
957  off = *offp;
958  slow = TTS_SLOW(slot);
959  }
960 
961  tp = (char *) tup + tup->t_hoff;
962 
963  for (; attnum < natts; attnum++)
964  {
965  Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
966 
967  if (hasnulls && att_isnull(attnum, bp))
968  {
969  values[attnum] = (Datum) 0;
970  isnull[attnum] = true;
971  slow = true; /* can't use attcacheoff anymore */
972  continue;
973  }
974 
975  isnull[attnum] = false;
976 
977  if (!slow && thisatt->attcacheoff >= 0)
978  off = thisatt->attcacheoff;
979  else if (thisatt->attlen == -1)
980  {
981  /*
982  * We can only cache the offset for a varlena attribute if the
983  * offset is already suitably aligned, so that there would be no
984  * pad bytes in any case: then the offset will be valid for either
985  * an aligned or unaligned value.
986  */
987  if (!slow &&
988  off == att_align_nominal(off, thisatt->attalign))
989  thisatt->attcacheoff = off;
990  else
991  {
992  off = att_align_pointer(off, thisatt->attalign, -1,
993  tp + off);
994  slow = true;
995  }
996  }
997  else
998  {
999  /* not varlena, so safe to use att_align_nominal */
1000  off = att_align_nominal(off, thisatt->attalign);
1001 
1002  if (!slow)
1003  thisatt->attcacheoff = off;
1004  }
1005 
1006  values[attnum] = fetchatt(thisatt, tp + off);
1007 
1008  off = att_addlength_pointer(off, thisatt->attlen, tp + off);
1009 
1010  if (thisatt->attlen <= 0)
1011  slow = true; /* can't use attcacheoff anymore */
1012  }
1013 
1014  /*
1015  * Save state for next execution
1016  */
1017  slot->tts_nvalid = attnum;
1018  *offp = off;
1019  if (slow)
1020  slot->tts_flags |= TTS_FLAG_SLOW;
1021  else
1022  slot->tts_flags &= ~TTS_FLAG_SLOW;
1023 }
unsigned int uint32
Definition: c.h:495
#define Min(x, y)
Definition: c.h:993
uint8 bits8
Definition: c.h:502
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:529
#define HeapTupleHasNulls(tuple)
Definition: htup_details.h:659
int16 attnum
Definition: pg_attribute.h:74
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]
Definition: htup_details.h:178
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
Definition: tupmacs.h:107
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:129
static bool att_isnull(int ATT, const bits8 *BITS)
Definition: tupmacs.h:26
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:157
#define fetchatt(A, T)
Definition: tupmacs.h:46
#define TTS_FLAG_SLOW
Definition: tuptable.h:103
#define TTS_SLOW(slot)
Definition: tuptable.h:104

References att_addlength_pointer, att_align_nominal, att_align_pointer, att_isnull(), attnum, fetchatt, HeapTupleHasNulls, HeapTupleHeaderGetNatts, Min, HeapTupleHeaderData::t_bits, HeapTupleData::t_data, HeapTupleHeaderData::t_hoff, TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, TTS_SLOW, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescAttr, and values.

Referenced by tts_buffer_heap_getsomeattrs(), tts_heap_getsomeattrs(), and tts_minimal_getsomeattrs().

◆ slot_getmissingattrs()

void slot_getmissingattrs ( TupleTableSlot slot,
int  startAttNum,
int  lastAttNum 
)

Definition at line 1869 of file execTuples.c.

1870 {
1871  AttrMissing *attrmiss = NULL;
1872 
1873  if (slot->tts_tupleDescriptor->constr)
1874  attrmiss = slot->tts_tupleDescriptor->constr->missing;
1875 
1876  if (!attrmiss)
1877  {
1878  /* no missing values array at all, so just fill everything in as NULL */
1879  memset(slot->tts_values + startAttNum, 0,
1880  (lastAttNum - startAttNum) * sizeof(Datum));
1881  memset(slot->tts_isnull + startAttNum, 1,
1882  (lastAttNum - startAttNum) * sizeof(bool));
1883  }
1884  else
1885  {
1886  int missattnum;
1887 
1888  /* if there is a missing values array we must process them one by one */
1889  for (missattnum = startAttNum;
1890  missattnum < lastAttNum;
1891  missattnum++)
1892  {
1893  slot->tts_values[missattnum] = attrmiss[missattnum].am_value;
1894  slot->tts_isnull[missattnum] = !attrmiss[missattnum].am_present;
1895  }
1896  }
1897 }
struct AttrMissing * missing
Definition: tupdesc.h:41
TupleConstr * constr
Definition: tupdesc.h:85

References AttrMissing::am_present, AttrMissing::am_value, TupleDescData::constr, TupleConstr::missing, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by slot_getsomeattrs_int().

◆ slot_getsomeattrs_int()

void slot_getsomeattrs_int ( TupleTableSlot slot,
int  attnum 
)

Definition at line 1903 of file execTuples.c.

1904 {
1905  /* Check for caller errors */
1906  Assert(slot->tts_nvalid < attnum); /* checked in slot_getsomeattrs */
1907  Assert(attnum > 0);
1908 
1909  if (unlikely(attnum > slot->tts_tupleDescriptor->natts))
1910  elog(ERROR, "invalid attribute number %d", attnum);
1911 
1912  /* Fetch as many attributes as possible from the underlying tuple. */
1913  slot->tts_ops->getsomeattrs(slot, attnum);
1914 
1915  /*
1916  * If the underlying tuple doesn't have enough attributes, tuple
1917  * descriptor must have the missing attributes.
1918  */
1919  if (unlikely(slot->tts_nvalid < attnum))
1920  {
1921  slot_getmissingattrs(slot, slot->tts_nvalid, attnum);
1922  slot->tts_nvalid = attnum;
1923  }
1924 }
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
Definition: execTuples.c:1869
void(* getsomeattrs)(TupleTableSlot *slot, int natts)
Definition: tuptable.h:160

References Assert(), attnum, elog(), ERROR, TupleTableSlotOps::getsomeattrs, TupleDescData::natts, slot_getmissingattrs(), TupleTableSlot::tts_nvalid, TupleTableSlot::tts_ops, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by slot_getsomeattrs().

◆ tts_buffer_heap_clear()

static void tts_buffer_heap_clear ( TupleTableSlot slot)
static

Definition at line 660 of file execTuples.c.

661 {
663 
664  /*
665  * Free the memory for heap tuple if allowed. A tuple coming from buffer
666  * can never be freed. But we may have materialized a tuple from buffer.
667  * Such a tuple can be freed.
668  */
669  if (TTS_SHOULDFREE(slot))
670  {
671  /* We should have unpinned the buffer while materializing the tuple. */
672  Assert(!BufferIsValid(bslot->buffer));
673 
674  heap_freetuple(bslot->base.tuple);
675  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
676  }
677 
678  if (BufferIsValid(bslot->buffer))
679  ReleaseBuffer(bslot->buffer);
680 
681  slot->tts_nvalid = 0;
682  slot->tts_flags |= TTS_FLAG_EMPTY;
684  bslot->base.tuple = NULL;
685  bslot->base.off = 0;
686  bslot->buffer = InvalidBuffer;
687 }
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4573
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
ItemPointerData tts_tid
Definition: tuptable.h:129
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:100

References Assert(), BufferHeapTupleTableSlot::buffer, BufferIsValid(), heap_freetuple(), InvalidBuffer, ItemPointerSetInvalid(), ReleaseBuffer(), TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

◆ tts_buffer_heap_copy_heap_tuple()

static HeapTuple tts_buffer_heap_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 834 of file execTuples.c.

835 {
837 
838  Assert(!TTS_EMPTY(slot));
839 
840  if (!bslot->base.tuple)
842 
843  return heap_copytuple(bslot->base.tuple);
844 }
static void tts_buffer_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:720

References Assert(), heap_copytuple(), tts_buffer_heap_materialize(), and TTS_EMPTY.

◆ tts_buffer_heap_copy_minimal_tuple()

static MinimalTuple tts_buffer_heap_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 847 of file execTuples.c.

848 {
850 
851  Assert(!TTS_EMPTY(slot));
852 
853  if (!bslot->base.tuple)
855 
856  return minimal_tuple_from_heap_tuple(bslot->base.tuple);
857 }
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Definition: heaptuple.c:1577

References Assert(), minimal_tuple_from_heap_tuple(), tts_buffer_heap_materialize(), and TTS_EMPTY.

◆ tts_buffer_heap_copyslot()

static void tts_buffer_heap_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 779 of file execTuples.c.

780 {
781  BufferHeapTupleTableSlot *bsrcslot = (BufferHeapTupleTableSlot *) srcslot;
782  BufferHeapTupleTableSlot *bdstslot = (BufferHeapTupleTableSlot *) dstslot;
783 
784  /*
785  * If the source slot is of a different kind, or is a buffer slot that has
786  * been materialized / is virtual, make a new copy of the tuple. Otherwise
787  * make a new reference to the in-buffer tuple.
788  */
789  if (dstslot->tts_ops != srcslot->tts_ops ||
790  TTS_SHOULDFREE(srcslot) ||
791  !bsrcslot->base.tuple)
792  {
793  MemoryContext oldContext;
794 
795  ExecClearTuple(dstslot);
796  dstslot->tts_flags &= ~TTS_FLAG_EMPTY;
797  oldContext = MemoryContextSwitchTo(dstslot->tts_mcxt);
798  bdstslot->base.tuple = ExecCopySlotHeapTuple(srcslot);
799  dstslot->tts_flags |= TTS_FLAG_SHOULDFREE;
800  MemoryContextSwitchTo(oldContext);
801  }
802  else
803  {
804  Assert(BufferIsValid(bsrcslot->buffer));
805 
806  tts_buffer_heap_store_tuple(dstslot, bsrcslot->base.tuple,
807  bsrcslot->buffer, false);
808 
809  /*
810  * The HeapTupleData portion of the source tuple might be shorter
811  * lived than the destination slot. Therefore copy the HeapTuple into
812  * our slot's tupdata, which is guaranteed to live long enough (but
813  * will still point into the buffer).
814  */
815  memcpy(&bdstslot->base.tupdata, bdstslot->base.tuple, sizeof(HeapTupleData));
816  bdstslot->base.tuple = &bdstslot->base.tupdata;
817  }
818 }
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:459

References Assert(), BufferHeapTupleTableSlot::buffer, BufferIsValid(), ExecClearTuple(), ExecCopySlotHeapTuple(), MemoryContextSwitchTo(), tts_buffer_heap_store_tuple(), TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_ops, and TTS_SHOULDFREE.

◆ tts_buffer_heap_get_heap_tuple()

static HeapTuple tts_buffer_heap_get_heap_tuple ( TupleTableSlot slot)
static

Definition at line 821 of file execTuples.c.

822 {
824 
825  Assert(!TTS_EMPTY(slot));
826 
827  if (!bslot->base.tuple)
829 
830  return bslot->base.tuple;
831 }

References Assert(), tts_buffer_heap_materialize(), and TTS_EMPTY.

◆ tts_buffer_heap_getsomeattrs()

static void tts_buffer_heap_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 690 of file execTuples.c.

691 {
693 
694  Assert(!TTS_EMPTY(slot));
695 
696  slot_deform_heap_tuple(slot, bslot->base.tuple, &bslot->base.off, natts);
697 }
static pg_attribute_always_inline void slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int natts)
Definition: execTuples.c:926

References Assert(), slot_deform_heap_tuple(), and TTS_EMPTY.

◆ tts_buffer_heap_getsysattr()

static Datum tts_buffer_heap_getsysattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)
static

Definition at line 700 of file execTuples.c.

701 {
703 
704  Assert(!TTS_EMPTY(slot));
705 
706  /*
707  * In some code paths it's possible to get here with a non-materialized
708  * slot, in which case we can't retrieve system columns.
709  */
710  if (!bslot->base.tuple)
711  ereport(ERROR,
712  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
713  errmsg("cannot retrieve a system column in this context")));
714 
715  return heap_getsysattr(bslot->base.tuple, attnum,
716  slot->tts_tupleDescriptor, isnull);
717 }
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereport(elevel,...)
Definition: elog.h:149
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: heaptuple.c:724

References Assert(), attnum, ereport, errcode(), errmsg(), ERROR, heap_getsysattr(), TTS_EMPTY, and TupleTableSlot::tts_tupleDescriptor.

◆ tts_buffer_heap_init()

static void tts_buffer_heap_init ( TupleTableSlot slot)
static

Definition at line 650 of file execTuples.c.

651 {
652 }

◆ tts_buffer_heap_materialize()

static void tts_buffer_heap_materialize ( TupleTableSlot slot)
static

Definition at line 720 of file execTuples.c.

721 {
723  MemoryContext oldContext;
724 
725  Assert(!TTS_EMPTY(slot));
726 
727  /* If slot has its tuple already materialized, nothing to do. */
728  if (TTS_SHOULDFREE(slot))
729  return;
730 
731  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
732 
733  /*
734  * Have to deform from scratch, otherwise tts_values[] entries could point
735  * into the non-materialized tuple (which might be gone when accessed).
736  */
737  bslot->base.off = 0;
738  slot->tts_nvalid = 0;
739 
740  if (!bslot->base.tuple)
741  {
742  /*
743  * Normally BufferHeapTupleTableSlot should have a tuple + buffer
744  * associated with it, unless it's materialized (which would've
745  * returned above). But when it's useful to allow storing virtual
746  * tuples in a buffer slot, which then also needs to be
747  * materializable.
748  */
749  bslot->base.tuple = heap_form_tuple(slot->tts_tupleDescriptor,
750  slot->tts_values,
751  slot->tts_isnull);
752  }
753  else
754  {
755  bslot->base.tuple = heap_copytuple(bslot->base.tuple);
756 
757  /*
758  * A heap tuple stored in a BufferHeapTupleTableSlot should have a
759  * buffer associated with it, unless it's materialized or virtual.
760  */
761  if (likely(BufferIsValid(bslot->buffer)))
762  ReleaseBuffer(bslot->buffer);
763  bslot->buffer = InvalidBuffer;
764  }
765 
766  /*
767  * We don't set TTS_FLAG_SHOULDFREE until after releasing the buffer, if
768  * any. This avoids having a transient state that would fall foul of our
769  * assertions that a slot with TTS_FLAG_SHOULDFREE doesn't own a buffer.
770  * In the unlikely event that ReleaseBuffer() above errors out, we'd
771  * effectively leak the copied tuple, but that seems fairly harmless.
772  */
774 
775  MemoryContextSwitchTo(oldContext);
776 }
#define likely(x)
Definition: c.h:299

References Assert(), BufferHeapTupleTableSlot::buffer, BufferIsValid(), heap_copytuple(), heap_form_tuple(), InvalidBuffer, likely, MemoryContextSwitchTo(), ReleaseBuffer(), TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by tts_buffer_heap_copy_heap_tuple(), tts_buffer_heap_copy_minimal_tuple(), and tts_buffer_heap_get_heap_tuple().

◆ tts_buffer_heap_release()

static void tts_buffer_heap_release ( TupleTableSlot slot)
static

Definition at line 655 of file execTuples.c.

656 {
657 }

◆ tts_buffer_heap_store_tuple()

static void tts_buffer_heap_store_tuple ( TupleTableSlot slot,
HeapTuple  tuple,
Buffer  buffer,
bool  transfer_pin 
)
inlinestatic

Definition at line 860 of file execTuples.c.

862 {
864 
865  if (TTS_SHOULDFREE(slot))
866  {
867  /* materialized slot shouldn't have a buffer to release */
868  Assert(!BufferIsValid(bslot->buffer));
869 
870  heap_freetuple(bslot->base.tuple);
871  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
872  }
873 
874  slot->tts_flags &= ~TTS_FLAG_EMPTY;
875  slot->tts_nvalid = 0;
876  bslot->base.tuple = tuple;
877  bslot->base.off = 0;
878  slot->tts_tid = tuple->t_self;
879 
880  /*
881  * If tuple is on a disk page, keep the page pinned as long as we hold a
882  * pointer into it. We assume the caller already has such a pin. If
883  * transfer_pin is true, we'll transfer that pin to this slot, if not
884  * we'll pin it again ourselves.
885  *
886  * This is coded to optimize the case where the slot previously held a
887  * tuple on the same disk page: in that case releasing and re-acquiring
888  * the pin is a waste of cycles. This is a common situation during
889  * seqscans, so it's worth troubling over.
890  */
891  if (bslot->buffer != buffer)
892  {
893  if (BufferIsValid(bslot->buffer))
894  ReleaseBuffer(bslot->buffer);
895 
896  bslot->buffer = buffer;
897 
898  if (!transfer_pin && BufferIsValid(buffer))
899  IncrBufferRefCount(buffer);
900  }
901  else if (transfer_pin && BufferIsValid(buffer))
902  {
903  /*
904  * In transfer_pin mode the caller won't know about the same-page
905  * optimization, so we gotta release its pin.
906  */
907  ReleaseBuffer(buffer);
908  }
909 }
void IncrBufferRefCount(Buffer buffer)
Definition: bufmgr.c:4605

References Assert(), BufferHeapTupleTableSlot::buffer, BufferIsValid(), heap_freetuple(), IncrBufferRefCount(), ReleaseBuffer(), HeapTupleData::t_self, TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

Referenced by ExecStoreBufferHeapTuple(), ExecStorePinnedBufferHeapTuple(), and tts_buffer_heap_copyslot().

◆ tts_heap_clear()

static void tts_heap_clear ( TupleTableSlot slot)
static

Definition at line 311 of file execTuples.c.

312 {
313  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
314 
315  /* Free the memory for the heap tuple if it's allowed. */
316  if (TTS_SHOULDFREE(slot))
317  {
318  heap_freetuple(hslot->tuple);
319  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
320  }
321 
322  slot->tts_nvalid = 0;
323  slot->tts_flags |= TTS_FLAG_EMPTY;
325  hslot->off = 0;
326  hslot->tuple = NULL;
327 }
HeapTuple tuple
Definition: tuptable.h:253

References heap_freetuple(), ItemPointerSetInvalid(), HeapTupleTableSlot::off, TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tid, and HeapTupleTableSlot::tuple.

Referenced by tts_heap_store_tuple().

◆ tts_heap_copy_heap_tuple()

static HeapTuple tts_heap_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 425 of file execTuples.c.

426 {
427  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
428 
429  Assert(!TTS_EMPTY(slot));
430  if (!hslot->tuple)
431  tts_heap_materialize(slot);
432 
433  return heap_copytuple(hslot->tuple);
434 }
static void tts_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:360

References Assert(), heap_copytuple(), TTS_EMPTY, tts_heap_materialize(), and HeapTupleTableSlot::tuple.

◆ tts_heap_copy_minimal_tuple()

static MinimalTuple tts_heap_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 437 of file execTuples.c.

438 {
439  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
440 
441  if (!hslot->tuple)
442  tts_heap_materialize(slot);
443 
444  return minimal_tuple_from_heap_tuple(hslot->tuple);
445 }

References minimal_tuple_from_heap_tuple(), tts_heap_materialize(), and HeapTupleTableSlot::tuple.

◆ tts_heap_copyslot()

static void tts_heap_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 400 of file execTuples.c.

401 {
402  HeapTuple tuple;
403  MemoryContext oldcontext;
404 
405  oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt);
406  tuple = ExecCopySlotHeapTuple(srcslot);
407  MemoryContextSwitchTo(oldcontext);
408 
409  ExecStoreHeapTuple(tuple, dstslot, true);
410 }

References ExecCopySlotHeapTuple(), ExecStoreHeapTuple(), MemoryContextSwitchTo(), and TupleTableSlot::tts_mcxt.

◆ tts_heap_get_heap_tuple()

static HeapTuple tts_heap_get_heap_tuple ( TupleTableSlot slot)
static

Definition at line 413 of file execTuples.c.

414 {
415  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
416 
417  Assert(!TTS_EMPTY(slot));
418  if (!hslot->tuple)
419  tts_heap_materialize(slot);
420 
421  return hslot->tuple;
422 }

References Assert(), TTS_EMPTY, tts_heap_materialize(), and HeapTupleTableSlot::tuple.

◆ tts_heap_getsomeattrs()

static void tts_heap_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 330 of file execTuples.c.

331 {
332  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
333 
334  Assert(!TTS_EMPTY(slot));
335 
336  slot_deform_heap_tuple(slot, hslot->tuple, &hslot->off, natts);
337 }

References Assert(), HeapTupleTableSlot::off, slot_deform_heap_tuple(), TTS_EMPTY, and HeapTupleTableSlot::tuple.

◆ tts_heap_getsysattr()

static Datum tts_heap_getsysattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)
static

Definition at line 340 of file execTuples.c.

341 {
342  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
343 
344  Assert(!TTS_EMPTY(slot));
345 
346  /*
347  * In some code paths it's possible to get here with a non-materialized
348  * slot, in which case we can't retrieve system columns.
349  */
350  if (!hslot->tuple)
351  ereport(ERROR,
352  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
353  errmsg("cannot retrieve a system column in this context")));
354 
355  return heap_getsysattr(hslot->tuple, attnum,
356  slot->tts_tupleDescriptor, isnull);
357 }

References Assert(), attnum, ereport, errcode(), errmsg(), ERROR, heap_getsysattr(), TTS_EMPTY, TupleTableSlot::tts_tupleDescriptor, and HeapTupleTableSlot::tuple.

◆ tts_heap_init()

static void tts_heap_init ( TupleTableSlot slot)
static

Definition at line 301 of file execTuples.c.

302 {
303 }

◆ tts_heap_materialize()

static void tts_heap_materialize ( TupleTableSlot slot)
static

Definition at line 360 of file execTuples.c.

361 {
362  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
363  MemoryContext oldContext;
364 
365  Assert(!TTS_EMPTY(slot));
366 
367  /* If slot has its tuple already materialized, nothing to do. */
368  if (TTS_SHOULDFREE(slot))
369  return;
370 
371  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
372 
373  /*
374  * Have to deform from scratch, otherwise tts_values[] entries could point
375  * into the non-materialized tuple (which might be gone when accessed).
376  */
377  slot->tts_nvalid = 0;
378  hslot->off = 0;
379 
380  if (!hslot->tuple)
382  slot->tts_values,
383  slot->tts_isnull);
384  else
385  {
386  /*
387  * The tuple contained in this slot is not allocated in the memory
388  * context of the given slot (else it would have TTS_FLAG_SHOULDFREE
389  * set). Copy the tuple into the given slot's memory context.
390  */
391  hslot->tuple = heap_copytuple(hslot->tuple);
392  }
393 
395 
396  MemoryContextSwitchTo(oldContext);
397 }

References Assert(), heap_copytuple(), heap_form_tuple(), MemoryContextSwitchTo(), HeapTupleTableSlot::off, TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and HeapTupleTableSlot::tuple.

Referenced by tts_heap_copy_heap_tuple(), tts_heap_copy_minimal_tuple(), and tts_heap_get_heap_tuple().

◆ tts_heap_release()

static void tts_heap_release ( TupleTableSlot slot)
static

Definition at line 306 of file execTuples.c.

307 {
308 }

◆ tts_heap_store_tuple()

static void tts_heap_store_tuple ( TupleTableSlot slot,
HeapTuple  tuple,
bool  shouldFree 
)
static

Definition at line 448 of file execTuples.c.

449 {
450  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
451 
452  tts_heap_clear(slot);
453 
454  slot->tts_nvalid = 0;
455  hslot->tuple = tuple;
456  hslot->off = 0;
458  slot->tts_tid = tuple->t_self;
459 
460  if (shouldFree)
462 }
static void tts_heap_clear(TupleTableSlot *slot)
Definition: execTuples.c:311

References HeapTupleTableSlot::off, HeapTupleData::t_self, TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, tts_heap_clear(), TupleTableSlot::tts_nvalid, TupleTableSlot::tts_tid, and HeapTupleTableSlot::tuple.

Referenced by ExecStoreHeapTuple().

◆ tts_minimal_clear()

static void tts_minimal_clear ( TupleTableSlot slot)
static

Definition at line 487 of file execTuples.c.

488 {
490 
491  if (TTS_SHOULDFREE(slot))
492  {
494  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
495  }
496 
497  slot->tts_nvalid = 0;
498  slot->tts_flags |= TTS_FLAG_EMPTY;
500  mslot->off = 0;
501  mslot->mintuple = NULL;
502 }
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1524
MinimalTuple mintuple
Definition: tuptable.h:290

References heap_free_minimal_tuple(), ItemPointerSetInvalid(), MinimalTupleTableSlot::mintuple, MinimalTupleTableSlot::off, TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

Referenced by tts_minimal_store_tuple().

◆ tts_minimal_copy_heap_tuple()

static HeapTuple tts_minimal_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 599 of file execTuples.c.

600 {
602 
603  if (!mslot->mintuple)
605 
607 }
static void tts_minimal_materialize(TupleTableSlot *slot)
Definition: execTuples.c:527
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1555

References heap_tuple_from_minimal_tuple(), MinimalTupleTableSlot::mintuple, and tts_minimal_materialize().

◆ tts_minimal_copy_minimal_tuple()

static MinimalTuple tts_minimal_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 610 of file execTuples.c.

611 {
613 
614  if (!mslot->mintuple)
616 
617  return heap_copy_minimal_tuple(mslot->mintuple);
618 }
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1536

References heap_copy_minimal_tuple(), MinimalTupleTableSlot::mintuple, and tts_minimal_materialize().

◆ tts_minimal_copyslot()

static void tts_minimal_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 575 of file execTuples.c.

576 {
577  MemoryContext oldcontext;
578  MinimalTuple mintuple;
579 
580  oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt);
581  mintuple = ExecCopySlotMinimalTuple(srcslot);
582  MemoryContextSwitchTo(oldcontext);
583 
584  ExecStoreMinimalTuple(mintuple, dstslot, true);
585 }
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1447
static MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition: tuptable.h:470

References ExecCopySlotMinimalTuple(), ExecStoreMinimalTuple(), MemoryContextSwitchTo(), and TupleTableSlot::tts_mcxt.

◆ tts_minimal_get_minimal_tuple()

static MinimalTuple tts_minimal_get_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 588 of file execTuples.c.

589 {
591 
592  if (!mslot->mintuple)
594 
595  return mslot->mintuple;
596 }

References MinimalTupleTableSlot::mintuple, and tts_minimal_materialize().

◆ tts_minimal_getsomeattrs()

static void tts_minimal_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 505 of file execTuples.c.

506 {
508 
509  Assert(!TTS_EMPTY(slot));
510 
511  slot_deform_heap_tuple(slot, mslot->tuple, &mslot->off, natts);
512 }

References Assert(), MinimalTupleTableSlot::off, slot_deform_heap_tuple(), TTS_EMPTY, and MinimalTupleTableSlot::tuple.

◆ tts_minimal_getsysattr()

static Datum tts_minimal_getsysattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)
static

Definition at line 515 of file execTuples.c.

516 {
517  Assert(!TTS_EMPTY(slot));
518 
519  ereport(ERROR,
520  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
521  errmsg("cannot retrieve a system column in this context")));
522 
523  return 0; /* silence compiler warnings */
524 }

References Assert(), ereport, errcode(), errmsg(), ERROR, and TTS_EMPTY.

◆ tts_minimal_init()

static void tts_minimal_init ( TupleTableSlot slot)
static

Definition at line 470 of file execTuples.c.

471 {
473 
474  /*
475  * Initialize the heap tuple pointer to access attributes of the minimal
476  * tuple contained in the slot as if its a heap tuple.
477  */
478  mslot->tuple = &mslot->minhdr;
479 }
HeapTupleData minhdr
Definition: tuptable.h:291

References MinimalTupleTableSlot::minhdr, and MinimalTupleTableSlot::tuple.

◆ tts_minimal_materialize()

static void tts_minimal_materialize ( TupleTableSlot slot)
static

Definition at line 527 of file execTuples.c.

528 {
530  MemoryContext oldContext;
531 
532  Assert(!TTS_EMPTY(slot));
533 
534  /* If slot has its tuple already materialized, nothing to do. */
535  if (TTS_SHOULDFREE(slot))
536  return;
537 
538  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
539 
540  /*
541  * Have to deform from scratch, otherwise tts_values[] entries could point
542  * into the non-materialized tuple (which might be gone when accessed).
543  */
544  slot->tts_nvalid = 0;
545  mslot->off = 0;
546 
547  if (!mslot->mintuple)
548  {
550  slot->tts_values,
551  slot->tts_isnull);
552  }
553  else
554  {
555  /*
556  * The minimal tuple contained in this slot is not allocated in the
557  * memory context of the given slot (else it would have
558  * TTS_FLAG_SHOULDFREE set). Copy the minimal tuple into the given
559  * slot's memory context.
560  */
561  mslot->mintuple = heap_copy_minimal_tuple(mslot->mintuple);
562  }
563 
565 
566  Assert(mslot->tuple == &mslot->minhdr);
567 
568  mslot->minhdr.t_len = mslot->mintuple->t_len + MINIMAL_TUPLE_OFFSET;
569  mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mslot->mintuple - MINIMAL_TUPLE_OFFSET);
570 
571  MemoryContextSwitchTo(oldContext);
572 }
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1453

References Assert(), heap_copy_minimal_tuple(), heap_form_minimal_tuple(), MemoryContextSwitchTo(), MinimalTupleTableSlot::minhdr, MINIMAL_TUPLE_OFFSET, MinimalTupleTableSlot::mintuple, MinimalTupleTableSlot::off, HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and MinimalTupleTableSlot::tuple.

Referenced by tts_minimal_copy_heap_tuple(), tts_minimal_copy_minimal_tuple(), and tts_minimal_get_minimal_tuple().

◆ tts_minimal_release()

static void tts_minimal_release ( TupleTableSlot slot)
static

Definition at line 482 of file execTuples.c.

483 {
484 }

◆ tts_minimal_store_tuple()

static void tts_minimal_store_tuple ( TupleTableSlot slot,
MinimalTuple  mtup,
bool  shouldFree 
)
static

Definition at line 621 of file execTuples.c.

622 {
624 
625  tts_minimal_clear(slot);
626 
627  Assert(!TTS_SHOULDFREE(slot));
628  Assert(TTS_EMPTY(slot));
629 
630  slot->tts_flags &= ~TTS_FLAG_EMPTY;
631  slot->tts_nvalid = 0;
632  mslot->off = 0;
633 
634  mslot->mintuple = mtup;
635  Assert(mslot->tuple == &mslot->minhdr);
636  mslot->minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
637  mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
638  /* no need to set t_self or t_tableOid since we won't allow access */
639 
640  if (shouldFree)
642 }
static void tts_minimal_clear(TupleTableSlot *slot)
Definition: execTuples.c:487

References Assert(), MinimalTupleTableSlot::minhdr, MINIMAL_TUPLE_OFFSET, MinimalTupleTableSlot::mintuple, MinimalTupleTableSlot::off, HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, TTS_EMPTY, TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, tts_minimal_clear(), TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and MinimalTupleTableSlot::tuple.

Referenced by ExecForceStoreMinimalTuple(), and ExecStoreMinimalTuple().

◆ tts_virtual_clear()

static void tts_virtual_clear ( TupleTableSlot slot)
static

Definition at line 107 of file execTuples.c.

108 {
109  if (unlikely(TTS_SHOULDFREE(slot)))
110  {
112 
113  pfree(vslot->data);
114  vslot->data = NULL;
115 
116  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
117  }
118 
119  slot->tts_nvalid = 0;
120  slot->tts_flags |= TTS_FLAG_EMPTY;
122 }

References VirtualTupleTableSlot::data, ItemPointerSetInvalid(), pfree(), TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tid, and unlikely.

Referenced by tts_virtual_copyslot().

◆ tts_virtual_copy_heap_tuple()

static HeapTuple tts_virtual_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 276 of file execTuples.c.

277 {
278  Assert(!TTS_EMPTY(slot));
279 
281  slot->tts_values,
282  slot->tts_isnull);
283 }

References Assert(), heap_form_tuple(), TTS_EMPTY, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

◆ tts_virtual_copy_minimal_tuple()

static MinimalTuple tts_virtual_copy_minimal_tuple ( TupleTableSlot slot)
static

◆ tts_virtual_copyslot()

static void tts_virtual_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 252 of file execTuples.c.

253 {
254  TupleDesc srcdesc = srcslot->tts_tupleDescriptor;
255 
256  Assert(srcdesc->natts <= dstslot->tts_tupleDescriptor->natts);
257 
258  tts_virtual_clear(dstslot);
259 
260  slot_getallattrs(srcslot);
261 
262  for (int natt = 0; natt < srcdesc->natts; natt++)
263  {
264  dstslot->tts_values[natt] = srcslot->tts_values[natt];
265  dstslot->tts_isnull[natt] = srcslot->tts_isnull[natt];
266  }
267 
268  dstslot->tts_nvalid = srcdesc->natts;
269  dstslot->tts_flags &= ~TTS_FLAG_EMPTY;
270 
271  /* make sure storage doesn't depend on external memory */
272  tts_virtual_materialize(dstslot);
273 }
static void tts_virtual_clear(TupleTableSlot *slot)
Definition: execTuples.c:107
static void tts_virtual_materialize(TupleTableSlot *slot)
Definition: execTuples.c:159
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:361

References Assert(), TupleDescData::natts, slot_getallattrs(), TTS_FLAG_EMPTY, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, tts_virtual_clear(), and tts_virtual_materialize().

◆ tts_virtual_getsomeattrs()

static void tts_virtual_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 129 of file execTuples.c.

130 {
131  elog(ERROR, "getsomeattrs is not required to be called on a virtual tuple table slot");
132 }

References elog(), and ERROR.

◆ tts_virtual_getsysattr()

static Datum tts_virtual_getsysattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)
static

Definition at line 140 of file execTuples.c.

141 {
142  Assert(!TTS_EMPTY(slot));
143 
144  ereport(ERROR,
145  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146  errmsg("cannot retrieve a system column in this context")));
147 
148  return 0; /* silence compiler warnings */
149 }

References Assert(), ereport, errcode(), errmsg(), ERROR, and TTS_EMPTY.

◆ tts_virtual_init()

static void tts_virtual_init ( TupleTableSlot slot)
static

Definition at line 97 of file execTuples.c.

98 {
99 }

◆ tts_virtual_materialize()

static void tts_virtual_materialize ( TupleTableSlot slot)
static

Definition at line 159 of file execTuples.c.

160 {
162  TupleDesc desc = slot->tts_tupleDescriptor;
163  Size sz = 0;
164  char *data;
165 
166  /* already materialized */
167  if (TTS_SHOULDFREE(slot))
168  return;
169 
170  /* compute size of memory required */
171  for (int natt = 0; natt < desc->natts; natt++)
172  {
173  Form_pg_attribute att = TupleDescAttr(desc, natt);
174  Datum val;
175 
176  if (att->attbyval || slot->tts_isnull[natt])
177  continue;
178 
179  val = slot->tts_values[natt];
180 
181  if (att->attlen == -1 &&
183  {
184  /*
185  * We want to flatten the expanded value so that the materialized
186  * slot doesn't depend on it.
187  */
188  sz = att_align_nominal(sz, att->attalign);
190  }
191  else
192  {
193  sz = att_align_nominal(sz, att->attalign);
194  sz = att_addlength_datum(sz, att->attlen, val);
195  }
196  }
197 
198  /* all data is byval */
199  if (sz == 0)
200  return;
201 
202  /* allocate memory */
203  vslot->data = data = MemoryContextAlloc(slot->tts_mcxt, sz);
205 
206  /* and copy all attributes into the pre-allocated space */
207  for (int natt = 0; natt < desc->natts; natt++)
208  {
209  Form_pg_attribute att = TupleDescAttr(desc, natt);
210  Datum val;
211 
212  if (att->attbyval || slot->tts_isnull[natt])
213  continue;
214 
215  val = slot->tts_values[natt];
216 
217  if (att->attlen == -1 &&
219  {
220  Size data_length;
221 
222  /*
223  * We want to flatten the expanded value so that the materialized
224  * slot doesn't depend on it.
225  */
227 
228  data = (char *) att_align_nominal(data,
229  att->attalign);
230  data_length = EOH_get_flat_size(eoh);
231  EOH_flatten_into(eoh, data, data_length);
232 
233  slot->tts_values[natt] = PointerGetDatum(data);
234  data += data_length;
235  }
236  else
237  {
238  Size data_length = 0;
239 
240  data = (char *) att_align_nominal(data, att->attalign);
241  data_length = att_addlength_datum(data_length, att->attlen, val);
242 
243  memcpy(data, DatumGetPointer(val), data_length);
244 
245  slot->tts_values[natt] = PointerGetDatum(data);
246  data += data_length;
247  }
248  }
249 }
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
Definition: expandeddatum.c:81
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
Definition: expandeddatum.c:75
long val
Definition: informix.c:664
#define att_addlength_datum(cur_offset, attlen, attdatum)
Definition: tupmacs.h:145
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: varatt.h:298

References att_addlength_datum, att_align_nominal, VirtualTupleTableSlot::data, data, DatumGetEOHP(), DatumGetPointer(), EOH_flatten_into(), EOH_get_flat_size(), MemoryContextAlloc(), TupleDescData::natts, PointerGetDatum(), TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescAttr, val, and VARATT_IS_EXTERNAL_EXPANDED.

Referenced by tts_virtual_copyslot().

◆ tts_virtual_release()

static void tts_virtual_release ( TupleTableSlot slot)
static

Definition at line 102 of file execTuples.c.

103 {
104 }

◆ TupleDescGetAttInMetadata()

AttInMetadata* TupleDescGetAttInMetadata ( TupleDesc  tupdesc)

Definition at line 2087 of file execTuples.c.

2088 {
2089  int natts = tupdesc->natts;
2090  int i;
2091  Oid atttypeid;
2092  Oid attinfuncid;
2093  FmgrInfo *attinfuncinfo;
2094  Oid *attioparams;
2095  int32 *atttypmods;
2096  AttInMetadata *attinmeta;
2097 
2098  attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
2099 
2100  /* "Bless" the tupledesc so that we can make rowtype datums with it */
2101  attinmeta->tupdesc = BlessTupleDesc(tupdesc);
2102 
2103  /*
2104  * Gather info needed later to call the "in" function for each attribute
2105  */
2106  attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
2107  attioparams = (Oid *) palloc0(natts * sizeof(Oid));
2108  atttypmods = (int32 *) palloc0(natts * sizeof(int32));
2109 
2110  for (i = 0; i < natts; i++)
2111  {
2112  Form_pg_attribute att = TupleDescAttr(tupdesc, i);
2113 
2114  /* Ignore dropped attributes */
2115  if (!att->attisdropped)
2116  {
2117  atttypeid = att->atttypid;
2118  getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
2119  fmgr_info(attinfuncid, &attinfuncinfo[i]);
2120  atttypmods[i] = att->atttypmod;
2121  }
2122  }
2123  attinmeta->attinfuncs = attinfuncinfo;
2124  attinmeta->attioparams = attioparams;
2125  attinmeta->atttypmods = atttypmods;
2126 
2127  return attinmeta;
2128 }
signed int int32
Definition: c.h:483
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2072
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2856
unsigned int Oid
Definition: postgres_ext.h:31
Definition: fmgr.h:57

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

Referenced by bt_metap(), bt_multi_page_stats(), bt_page_stats_internal(), build_pgstattuple_type(), connectby_text(), connectby_text_serial(), create_foreign_modify(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), hash_page_items(), libpqrcv_processTuples(), materializeResult(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls_internal(), pg_stats_ext_mcvlist_items(), 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().

Variable Documentation

◆ TTSOpsBufferHeapTuple

const TupleTableSlotOps TTSOpsBufferHeapTuple
Initial value:
= {
.base_slot_size = sizeof(BufferHeapTupleTableSlot),
.get_heap_tuple = tts_buffer_heap_get_heap_tuple,
.get_minimal_tuple = NULL,
.copy_heap_tuple = tts_buffer_heap_copy_heap_tuple,
.copy_minimal_tuple = tts_buffer_heap_copy_minimal_tuple
}
static void tts_buffer_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:779
static HeapTuple tts_buffer_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:834
static void tts_buffer_heap_clear(TupleTableSlot *slot)
Definition: execTuples.c:660
static Datum tts_buffer_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:700
static HeapTuple tts_buffer_heap_get_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:821
static void tts_buffer_heap_release(TupleTableSlot *slot)
Definition: execTuples.c:655
static MinimalTuple tts_buffer_heap_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:847
static void tts_buffer_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:690
static void tts_buffer_heap_init(TupleTableSlot *slot)
Definition: execTuples.c:650
int init
Definition: isn.c:75
struct BufferHeapTupleTableSlot BufferHeapTupleTableSlot

Definition at line 86 of file execTuples.c.

Referenced by CheckOpSlotCompatibility(), heapam_slot_callbacks(), and slot_compile_deform().

◆ TTSOpsHeapTuple

const TupleTableSlotOps TTSOpsHeapTuple
Initial value:
= {
.base_slot_size = sizeof(HeapTupleTableSlot),
.release = tts_heap_release,
.clear = tts_heap_clear,
.getsomeattrs = tts_heap_getsomeattrs,
.getsysattr = tts_heap_getsysattr,
.materialize = tts_heap_materialize,
.copyslot = tts_heap_copyslot,
.get_heap_tuple = tts_heap_get_heap_tuple,
.get_minimal_tuple = NULL,
.copy_heap_tuple = tts_heap_copy_heap_tuple,
.copy_minimal_tuple = tts_heap_copy_minimal_tuple
}
static Datum tts_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:340
static MinimalTuple tts_heap_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:437
static void tts_heap_init(TupleTableSlot *slot)
Definition: execTuples.c:301
static HeapTuple tts_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:425
static HeapTuple tts_heap_get_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:413
static void tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:400
static void tts_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:330
static void tts_heap_release(TupleTableSlot *slot)
Definition: execTuples.c:306
struct HeapTupleTableSlot HeapTupleTableSlot

Definition at line 84 of file execTuples.c.

Referenced by CatalogIndexInsert(), CheckOpSlotCompatibility(), compute_expr_stats(), compute_index_stats(), copyTemplateDependencies(), DefineTSConfiguration(), EnumValuesCreate(), ExecInitForeignScan(), ExecInitSetOp(), ExecuteCallStmt(), heapam_index_validate_scan(), init_tuple_slot(), InsertPgAttributeTuples(), make_build_data(), MakeConfigurationMapping(), recordMultipleDependencies(), slot_compile_deform(), table_slot_callbacks(), and tuplesort_begin_cluster().

◆ TTSOpsMinimalTuple

const TupleTableSlotOps TTSOpsMinimalTuple
Initial value:
= {
.base_slot_size = sizeof(MinimalTupleTableSlot),
.release = tts_minimal_release,
.getsomeattrs = tts_minimal_getsomeattrs,
.getsysattr = tts_minimal_getsysattr,
.materialize = tts_minimal_materialize,
.copyslot = tts_minimal_copyslot,
.get_heap_tuple = NULL,
.get_minimal_tuple = tts_minimal_get_minimal_tuple,
.copy_heap_tuple = tts_minimal_copy_heap_tuple,
.copy_minimal_tuple = tts_minimal_copy_minimal_tuple
}
static HeapTuple tts_minimal_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:599
static void tts_minimal_init(TupleTableSlot *slot)
Definition: execTuples.c:470
static MinimalTuple tts_minimal_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:610
static MinimalTuple tts_minimal_get_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:588
static void tts_minimal_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:575
static void tts_minimal_release(TupleTableSlot *slot)
Definition: execTuples.c:482
static Datum tts_minimal_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:515
static void tts_minimal_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:505
struct MinimalTupleTableSlot MinimalTupleTableSlot

Definition at line 85 of file execTuples.c.

Referenced by afterTriggerInvokeEvents(), build_pertrans_for_aggref(), BuildTupleHashTableExt(), check_publications(), check_publications_origin(), ExecInitAgg(), ExecInitCteScan(), ExecInitFunctionScan(), ExecInitGather(), ExecInitHash(), ExecInitIncrementalSort(), ExecInitMaterial(), ExecInitMemoize(), ExecInitNamedTuplestoreScan(), ExecInitSetOp(), ExecInitSort(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitUnique(), ExecInitWindowAgg(), ExecInitWorkTableScan(), ExecPrepareTuplestoreResult(), fetch_remote_table_info(), fetch_table_list(), find_hash_columns(), gather_merge_setup(), hashagg_recompile_expressions(), hypothetical_dense_rank_final(), init_sql_fcache(), ordered_set_startup(), RunFromStore(), and slot_compile_deform().

◆ TTSOpsVirtual

const TupleTableSlotOps TTSOpsVirtual
Initial value:
= {
.base_slot_size = sizeof(VirtualTupleTableSlot),
.release = tts_virtual_release,
.getsomeattrs = tts_virtual_getsomeattrs,
.getsysattr = tts_virtual_getsysattr,
.materialize = tts_virtual_materialize,
.copyslot = tts_virtual_copyslot,
.get_heap_tuple = NULL,
.get_minimal_tuple = NULL,
.copy_heap_tuple = tts_virtual_copy_heap_tuple,
.copy_minimal_tuple = tts_virtual_copy_minimal_tuple
}
static HeapTuple tts_virtual_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:276
static void tts_virtual_release(TupleTableSlot *slot)
Definition: execTuples.c:102
static void tts_virtual_init(TupleTableSlot *slot)
Definition: execTuples.c:97
static void tts_virtual_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:252
static void tts_virtual_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:129
static MinimalTuple tts_virtual_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:286
static Datum tts_virtual_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:140
struct VirtualTupleTableSlot VirtualTupleTableSlot

Definition at line 83 of file execTuples.c.

Referenced by apply_handle_delete(), apply_handle_insert(), apply_handle_update(), CheckOpSlotCompatibility(), CreateReplicationSlot(), ExecComputeSlotInfo(), ExecConditionalAssignProjectionInfo(), ExecConstraints(), ExecGetResultSlotOps(), ExecInitAgg(), ExecInitAppend(), ExecInitCustomScan(), ExecInitGroup(), ExecInitHashJoin(), ExecInitIndexOnlyScan(), ExecInitJunkFilter(), ExecInitJunkFilterConversion(), ExecInitMemoize(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNestLoop(), ExecInitPartitionDispatchInfo(), ExecInitProjectSet(), ExecInitResult(), ExecInitSort(), ExecInitSubPlan(), ExecInitValuesScan(), ExecInitWholeRowVar(), ExecInitWindowAgg(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), ExplainQuery(), GetAfterTriggersStoreSlot(), IdentifySystem(), InitPlan(), pgoutput_change(), pgoutput_row_filter(), ReadReplicationSlot(), RI_Initial_Check(), RI_PartitionRemove_Check(), SendTablespaceList(), SendXlogRecPtrResult(), ShowAllGUCConfig(), ShowGUCConfigOption(), slot_compile_deform(), StartReplication(), table_slot_callbacks(), and tstoreStartupReceiver().