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 2254 of file execTuples.c.

2257 {
2258  TupOutputState *tstate;
2259 
2260  tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
2261 
2262  tstate->slot = MakeSingleTupleTableSlot(tupdesc, tts_ops);
2263  tstate->dest = dest;
2264 
2265  tstate->dest->rStartup(tstate->dest, (int) CMD_SELECT, tupdesc);
2266 
2267  return tstate;
2268 }
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1237
void * palloc(Size size)
Definition: mcxt.c:1304
@ CMD_SELECT
Definition: nodes.h:255
TupleTableSlot * slot
Definition: executor.h:506
DestReceiver * dest
Definition: executor.h:507
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 2134 of file execTuples.c.

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

2303 {
2304  Datum values[1];
2305  bool isnull[1] = {false};
2306 
2307  while (*txt)
2308  {
2309  const char *eol;
2310  int len;
2311 
2312  eol = strchr(txt, '\n');
2313  if (eol)
2314  {
2315  len = eol - txt;
2316  eol++;
2317  }
2318  else
2319  {
2320  len = strlen(txt);
2321  eol = txt + len;
2322  }
2323 
2325  do_tup_output(tstate, values, isnull);
2327  txt = eol;
2328  }
2329 }
void do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull)
Definition: execTuples.c:2274
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 2274 of file execTuples.c.

2275 {
2276  TupleTableSlot *slot = tstate->slot;
2277  int natts = slot->tts_tupleDescriptor->natts;
2278 
2279  /* make sure the slot is clear */
2280  ExecClearTuple(slot);
2281 
2282  /* insert data */
2283  memcpy(slot->tts_values, values, natts * sizeof(Datum));
2284  memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
2285 
2286  /* mark slot as containing a virtual tuple */
2287  ExecStoreVirtualTuple(slot);
2288 
2289  /* send the tuple to the receiver */
2290  (void) tstate->dest->receiveSlot(slot, tstate->dest);
2291 
2292  /* clean up */
2293  ExecClearTuple(slot);
2294 }
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1551
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:433

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 2332 of file execTuples.c.

2333 {
2334  tstate->dest->rShutdown(tstate->dest);
2335  /* note that destroying the dest is not ours to do */
2337  pfree(tstate);
2338 }
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1253
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 1170 of file execTuples.c.

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

References lappend(), and MakeTupleTableSlot().

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

◆ ExecCleanTypeFromTL()

TupleDesc ExecCleanTypeFromTL ( List targetList)

Definition at line 1949 of file execTuples.c.

1950 {
1951  return ExecTypeFromTLInternal(targetList, true);
1952 }
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool skipjunk)
Definition: execTuples.c:1955

References ExecTypeFromTLInternal().

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

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 1253 of file execTuples.c.

1254 {
1255  /* This should match ExecResetTupleTable's processing of one slot */
1256  Assert(IsA(slot, TupleTableSlot));
1257  ExecClearTuple(slot);
1258  slot->tts_ops->release(slot);
1259  if (slot->tts_tupleDescriptor)
1261  if (!TTS_FIXED(slot))
1262  {
1263  if (slot->tts_values)
1264  pfree(slot->tts_values);
1265  if (slot->tts_isnull)
1266  pfree(slot->tts_isnull);
1267  }
1268  pfree(slot);
1269 }
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
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 1643 of file execTuples.c.

1644 {
1645  /*
1646  * sanity checks
1647  */
1648  Assert(slot != NULL);
1649  Assert(!TTS_EMPTY(slot));
1650 
1651  /* Materialize the tuple so that the slot "owns" it, if requested. */
1652  if (materialize)
1653  slot->tts_ops->materialize(slot);
1654 
1655  if (slot->tts_ops->get_heap_tuple == NULL)
1656  {
1657  if (shouldFree)
1658  *shouldFree = true;
1659  return slot->tts_ops->copy_heap_tuple(slot);
1660  }
1661  else
1662  {
1663  if (shouldFree)
1664  *shouldFree = false;
1665  return slot->tts_ops->get_heap_tuple(slot);
1666  }
1667 }
HeapTuple(* get_heap_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:188
HeapTuple(* copy_heap_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:206
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 1722 of file execTuples.c.

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

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 1691 of file execTuples.c.

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

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 1468 of file execTuples.c.

1471 {
1472  if (TTS_IS_HEAPTUPLE(slot))
1473  {
1474  ExecStoreHeapTuple(tuple, slot, shouldFree);
1475  }
1476  else if (TTS_IS_BUFFERTUPLE(slot))
1477  {
1478  MemoryContext oldContext;
1480 
1481  ExecClearTuple(slot);
1482  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1483  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
1484  bslot->base.tuple = heap_copytuple(tuple);
1485  slot->tts_flags |= TTS_FLAG_SHOULDFREE;
1486  MemoryContextSwitchTo(oldContext);
1487 
1488  if (shouldFree)
1489  pfree(tuple);
1490  }
1491  else
1492  {
1493  ExecClearTuple(slot);
1495  slot->tts_values, slot->tts_isnull);
1496  ExecStoreVirtualTuple(slot);
1497 
1498  if (shouldFree)
1499  {
1500  ExecMaterializeSlot(slot);
1501  pfree(tuple);
1502  }
1503  }
1504 }
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1351
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:776
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1345
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
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:231
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:451
#define TTS_IS_HEAPTUPLE(slot)
Definition: tuptable.h:229

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(), ExecMergeMatched(), ExecModifyTable(), IndexNextWithReorder(), IndexOnlyNext(), and store_returning_result().

◆ ExecForceStoreMinimalTuple()

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

Definition at line 1511 of file execTuples.c.

1514 {
1515  if (TTS_IS_MINIMALTUPLE(slot))
1516  {
1517  tts_minimal_store_tuple(slot, mtup, shouldFree);
1518  }
1519  else
1520  {
1521  HeapTupleData htup;
1522 
1523  ExecClearTuple(slot);
1524 
1525  htup.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
1526  htup.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
1528  slot->tts_values, slot->tts_isnull);
1529  ExecStoreVirtualTuple(slot);
1530 
1531  if (shouldFree)
1532  {
1533  ExecMaterializeSlot(slot);
1534  pfree(mtup);
1535  }
1536  }
1537 }
static void tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
Definition: execTuples.c:619
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:230

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 1846 of file execTuples.c.

1848 {
1849  TupleTableSlot *slot = ExecInitExtraTupleSlot(estate, tupType, tts_ops);
1850 
1851  return ExecStoreAllNullTuple(slot);
1852 }
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
Definition: execTuples.c:1575
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1830

References ExecInitExtraTupleSlot(), and ExecStoreAllNullTuple().

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

◆ ExecInitResultSlot()

void ExecInitResultSlot ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

Definition at line 1778 of file execTuples.c.

1779 {
1780  TupleTableSlot *slot;
1781 
1782  slot = ExecAllocTableSlot(&planstate->state->es_tupleTable,
1783  planstate->ps_ResultTupleDesc, tts_ops);
1784  planstate->ps_ResultTupleSlot = slot;
1785 
1786  planstate->resultopsfixed = planstate->ps_ResultTupleDesc != NULL;
1787  planstate->resultops = tts_ops;
1788  planstate->resultopsset = true;
1789 }
const TupleTableSlotOps * resultops
Definition: execnodes.h:1120
bool resultopsset
Definition: execnodes.h:1128
EState * state
Definition: execnodes.h:1045
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1080
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1081
bool resultopsfixed
Definition: execnodes.h:1124

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 1190 of file execTuples.c.

1192 {
1193  ListCell *lc;
1194 
1195  foreach(lc, tupleTable)
1196  {
1198 
1199  /* Always release resources and reset the slot to empty */
1200  ExecClearTuple(slot);
1201  slot->tts_ops->release(slot);
1202  if (slot->tts_tupleDescriptor)
1203  {
1205  slot->tts_tupleDescriptor = NULL;
1206  }
1207 
1208  /* If shouldFree, release memory occupied by the slot itself */
1209  if (shouldFree)
1210  {
1211  if (!TTS_FIXED(slot))
1212  {
1213  if (slot->tts_values)
1214  pfree(slot->tts_values);
1215  if (slot->tts_isnull)
1216  pfree(slot->tts_isnull);
1217  }
1218  pfree(slot);
1219  }
1220  }
1221 
1222  /* If shouldFree, release the list structure */
1223  if (shouldFree)
1224  list_free(tupleTable);
1225 }
void list_free(List *list)
Definition: list.c:1546
#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 1288 of file execTuples.c.

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

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

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 1391 of file execTuples.c.

1394 {
1395  /*
1396  * sanity checks
1397  */
1398  Assert(tuple != NULL);
1399  Assert(slot != NULL);
1400  Assert(slot->tts_tupleDescriptor != NULL);
1401  Assert(BufferIsValid(buffer));
1402 
1403  if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1404  elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1405  tts_buffer_heap_store_tuple(slot, tuple, buffer, false);
1406 
1407  slot->tts_tableOid = tuple->t_tableOid;
1408 
1409  return slot;
1410 }
static bool BufferIsValid(Buffer bufnum)
Definition: bufmgr.h:301
#define unlikely(x)
Definition: c.h:298
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
static void tts_buffer_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
Definition: execTuples.c:858
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 1351 of file execTuples.c.

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

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 1605 of file execTuples.c.

1606 {
1607  HeapTupleData tuple = {0};
1608  HeapTupleHeader td;
1609 
1611 
1613  tuple.t_self = td->t_ctid;
1614  tuple.t_data = td;
1615 
1616  ExecClearTuple(slot);
1617 
1618  heap_deform_tuple(&tuple, slot->tts_tupleDescriptor,
1619  slot->tts_values, slot->tts_isnull);
1620  ExecStoreVirtualTuple(slot);
1621 }
#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 1417 of file execTuples.c.

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

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 1551 of file execTuples.c.

1552 {
1553  /*
1554  * sanity checks
1555  */
1556  Assert(slot != NULL);
1557  Assert(slot->tts_tupleDescriptor != NULL);
1558  Assert(TTS_EMPTY(slot));
1559 
1560  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1561  slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
1562 
1563  return slot;
1564 }
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 1996 of file execTuples.c.

1997 {
1998  TupleDesc typeInfo;
1999  ListCell *lc;
2000  int cur_resno = 1;
2001 
2002  typeInfo = CreateTemplateTupleDesc(list_length(exprList));
2003 
2004  foreach(lc, exprList)
2005  {
2006  Node *e = lfirst(lc);
2007 
2008  TupleDescInitEntry(typeInfo,
2009  cur_resno,
2010  NULL,
2011  exprType(e),
2012  exprTypmod(e),
2013  0);
2014  TupleDescInitEntryCollation(typeInfo,
2015  cur_resno,
2016  exprCollation(e));
2017  cur_resno++;
2018  }
2019 
2020  return typeInfo;
2021 }
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:284
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:788
#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:833
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:651

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 1955 of file execTuples.c.

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

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 2029 of file execTuples.c.

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

2224 {
2225  Datum result;
2226  TupleDesc tupDesc;
2227 
2228  /* No work if there are no external TOAST pointers in the tuple */
2229  if (!HeapTupleHeaderHasExternal(tuple))
2230  return PointerGetDatum(tuple);
2231 
2232  /* Use the type data saved by heap_form_tuple to look up the rowtype */
2234  HeapTupleHeaderGetTypMod(tuple));
2235 
2236  /* And do the flattening */
2237  result = toast_flatten_tuple_to_datum(tuple,
2239  tupDesc);
2240 
2241  ReleaseTupleDesc(tupDesc);
2242 
2243  return result;
2244 }
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:1833

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 1111 of file execTuples.c.

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

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

1868 {
1869  AttrMissing *attrmiss = NULL;
1870 
1871  if (slot->tts_tupleDescriptor->constr)
1872  attrmiss = slot->tts_tupleDescriptor->constr->missing;
1873 
1874  if (!attrmiss)
1875  {
1876  /* no missing values array at all, so just fill everything in as NULL */
1877  memset(slot->tts_values + startAttNum, 0,
1878  (lastAttNum - startAttNum) * sizeof(Datum));
1879  memset(slot->tts_isnull + startAttNum, 1,
1880  (lastAttNum - startAttNum) * sizeof(bool));
1881  }
1882  else
1883  {
1884  int missattnum;
1885 
1886  /* if there is a missing values array we must process them one by one */
1887  for (missattnum = startAttNum;
1888  missattnum < lastAttNum;
1889  missattnum++)
1890  {
1891  slot->tts_values[missattnum] = attrmiss[missattnum].am_value;
1892  slot->tts_isnull[missattnum] = !attrmiss[missattnum].am_present;
1893  }
1894  }
1895 }
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 1901 of file execTuples.c.

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

659 {
661 
662  /*
663  * Free the memory for heap tuple if allowed. A tuple coming from buffer
664  * can never be freed. But we may have materialized a tuple from buffer.
665  * Such a tuple can be freed.
666  */
667  if (TTS_SHOULDFREE(slot))
668  {
669  /* We should have unpinned the buffer while materializing the tuple. */
670  Assert(!BufferIsValid(bslot->buffer));
671 
672  heap_freetuple(bslot->base.tuple);
673  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
674  }
675 
676  if (BufferIsValid(bslot->buffer))
677  ReleaseBuffer(bslot->buffer);
678 
679  slot->tts_nvalid = 0;
680  slot->tts_flags |= TTS_FLAG_EMPTY;
682  bslot->base.tuple = NULL;
683  bslot->base.off = 0;
684  bslot->buffer = InvalidBuffer;
685 }
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4560
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1434
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 832 of file execTuples.c.

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

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 845 of file execTuples.c.

846 {
848 
849  Assert(!TTS_EMPTY(slot));
850 
851  if (!bslot->base.tuple)
853 
854  return minimal_tuple_from_heap_tuple(bslot->base.tuple);
855 }
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Definition: heaptuple.c:1576

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 777 of file execTuples.c.

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

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 819 of file execTuples.c.

820 {
822 
823  Assert(!TTS_EMPTY(slot));
824 
825  if (!bslot->base.tuple)
827 
828  return bslot->base.tuple;
829 }

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 688 of file execTuples.c.

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

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 698 of file execTuples.c.

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

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 648 of file execTuples.c.

649 {
650 }

◆ tts_buffer_heap_materialize()

static void tts_buffer_heap_materialize ( TupleTableSlot slot)
static

Definition at line 718 of file execTuples.c.

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

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 653 of file execTuples.c.

654 {
655 }

◆ 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 858 of file execTuples.c.

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

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 309 of file execTuples.c.

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

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 423 of file execTuples.c.

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

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 435 of file execTuples.c.

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

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 398 of file execTuples.c.

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

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 411 of file execTuples.c.

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

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 328 of file execTuples.c.

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

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 338 of file execTuples.c.

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

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 299 of file execTuples.c.

300 {
301 }

◆ tts_heap_materialize()

static void tts_heap_materialize ( TupleTableSlot slot)
static

Definition at line 358 of file execTuples.c.

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

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 304 of file execTuples.c.

305 {
306 }

◆ tts_heap_store_tuple()

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

Definition at line 446 of file execTuples.c.

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

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 485 of file execTuples.c.

486 {
488 
489  if (TTS_SHOULDFREE(slot))
490  {
492  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
493  }
494 
495  slot->tts_nvalid = 0;
496  slot->tts_flags |= TTS_FLAG_EMPTY;
498  mslot->off = 0;
499  mslot->mintuple = NULL;
500 }
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1523
MinimalTuple mintuple
Definition: tuptable.h:291

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 597 of file execTuples.c.

598 {
600 
601  if (!mslot->mintuple)
603 
605 }
static void tts_minimal_materialize(TupleTableSlot *slot)
Definition: execTuples.c:525
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1554

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 608 of file execTuples.c.

609 {
611 
612  if (!mslot->mintuple)
614 
615  return heap_copy_minimal_tuple(mslot->mintuple);
616 }
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1535

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 573 of file execTuples.c.

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

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 586 of file execTuples.c.

587 {
589 
590  if (!mslot->mintuple)
592 
593  return mslot->mintuple;
594 }

References MinimalTupleTableSlot::mintuple, and tts_minimal_materialize().

◆ tts_minimal_getsomeattrs()

static void tts_minimal_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 503 of file execTuples.c.

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

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 513 of file execTuples.c.

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

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

◆ tts_minimal_init()

static void tts_minimal_init ( TupleTableSlot slot)
static

Definition at line 468 of file execTuples.c.

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

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

◆ tts_minimal_materialize()

static void tts_minimal_materialize ( TupleTableSlot slot)
static

Definition at line 525 of file execTuples.c.

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

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 480 of file execTuples.c.

481 {
482 }

◆ tts_minimal_store_tuple()

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

Definition at line 619 of file execTuples.c.

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

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 274 of file execTuples.c.

275 {
276  Assert(!TTS_EMPTY(slot));
277 
279  slot->tts_values,
280  slot->tts_isnull);
281 }

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  tts_virtual_clear(dstslot);
257 
258  slot_getallattrs(srcslot);
259 
260  for (int natt = 0; natt < srcdesc->natts; natt++)
261  {
262  dstslot->tts_values[natt] = srcslot->tts_values[natt];
263  dstslot->tts_isnull[natt] = srcslot->tts_isnull[natt];
264  }
265 
266  dstslot->tts_nvalid = srcdesc->natts;
267  dstslot->tts_flags &= ~TTS_FLAG_EMPTY;
268 
269  /* make sure storage doesn't depend on external memory */
270  tts_virtual_materialize(dstslot);
271 }
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:362

References 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 2085 of file execTuples.c.

2086 {
2087  int natts = tupdesc->natts;
2088  int i;
2089  Oid atttypeid;
2090  Oid attinfuncid;
2091  FmgrInfo *attinfuncinfo;
2092  Oid *attioparams;
2093  int32 *atttypmods;
2094  AttInMetadata *attinmeta;
2095 
2096  attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
2097 
2098  /* "Bless" the tupledesc so that we can make rowtype datums with it */
2099  attinmeta->tupdesc = BlessTupleDesc(tupdesc);
2100 
2101  /*
2102  * Gather info needed later to call the "in" function for each attribute
2103  */
2104  attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
2105  attioparams = (Oid *) palloc0(natts * sizeof(Oid));
2106  atttypmods = (int32 *) palloc0(natts * sizeof(int32));
2107 
2108  for (i = 0; i < natts; i++)
2109  {
2110  Form_pg_attribute att = TupleDescAttr(tupdesc, i);
2111 
2112  /* Ignore dropped attributes */
2113  if (!att->attisdropped)
2114  {
2115  atttypeid = att->atttypid;
2116  getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
2117  fmgr_info(attinfuncid, &attinfuncinfo[i]);
2118  atttypmods[i] = att->atttypmod;
2119  }
2120  }
2121  attinmeta->attinfuncs = attinfuncinfo;
2122  attinmeta->attioparams = attioparams;
2123  attinmeta->atttypmods = atttypmods;
2124 
2125  return attinmeta;
2126 }
signed int int32
Definition: c.h:481
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2070
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2830
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_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:777
static HeapTuple tts_buffer_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:832
static void tts_buffer_heap_clear(TupleTableSlot *slot)
Definition: execTuples.c:658
static Datum tts_buffer_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:698
static HeapTuple tts_buffer_heap_get_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:819
static void tts_buffer_heap_release(TupleTableSlot *slot)
Definition: execTuples.c:653
static MinimalTuple tts_buffer_heap_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:845
static void tts_buffer_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:688
static void tts_buffer_heap_init(TupleTableSlot *slot)
Definition: execTuples.c:648
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:338
static MinimalTuple tts_heap_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:435
static void tts_heap_init(TupleTableSlot *slot)
Definition: execTuples.c:299
static HeapTuple tts_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:423
static HeapTuple tts_heap_get_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:411
static void tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:398
static void tts_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:328
static void tts_heap_release(TupleTableSlot *slot)
Definition: execTuples.c:304
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:597
static void tts_minimal_init(TupleTableSlot *slot)
Definition: execTuples.c:468
static MinimalTuple tts_minimal_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:608
static MinimalTuple tts_minimal_get_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:586
static void tts_minimal_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:573
static void tts_minimal_release(TupleTableSlot *slot)
Definition: execTuples.c:480
static Datum tts_minimal_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:513
static void tts_minimal_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:503
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(), slot_compile_deform(), synchronize_slots(), and validate_remote_info().

◆ 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:274
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:284
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().