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, Datum *values, 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 2266 of file execTuples.c.

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

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

2269 {
2270  TupOutputState *tstate;
2271 
2272  tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
2273 
2274  tstate->slot = MakeSingleTupleTableSlot(tupdesc, tts_ops);
2275  tstate->dest = dest;
2276 
2277  tstate->dest->rStartup(tstate->dest, (int) CMD_SELECT, tupdesc);
2278 
2279  return tstate;
2280 }
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1238
TupleTableSlot * slot
Definition: executor.h:488
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: dest.h:122
void * palloc(Size size)
Definition: mcxt.c:1062
DestReceiver * dest
Definition: executor.h:489

◆ BlessTupleDesc()

TupleDesc BlessTupleDesc ( TupleDesc  tupdesc)

Definition at line 2082 of file execTuples.c.

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

Referenced by aclexplode(), brin_metapage_info(), bt_page_items_bytea(), bt_page_items_internal(), each_worker(), each_worker_jsonb(), elements_worker(), elements_worker_jsonb(), exec_eval_datum(), ExecEvalWholeRowVar(), ExecInitExprRec(), ExecInitFunctionScan(), get_expr_result_type(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), init_sql_fcache(), MakeOldSnapshotTimeMappingTupleDesc(), pg_buffercache_pages(), pg_control_checkpoint(), pg_control_init(), pg_control_recovery(), pg_control_system(), pg_get_catalog_foreign_keys(), pg_get_object_address(), pg_identify_object(), pg_identify_object_as_address(), pg_last_committed_xact(), pg_lock_status(), pg_partition_tree(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_archiver(), pg_stat_get_wal(), pg_stats_ext_mcvlist_items(), pg_timezone_abbrevs(), pg_visibility_map_summary(), pg_visibility_tupdesc(), pg_walfile_name_offset(), pg_xact_commit_timestamp_origin(), pgstathashindex(), PLy_output_setup_record(), setup_firstcall(), ssl_extension_info(), test_enc_conversion(), test_predtest(), ts_setup_firstcall(), tsvector_unnest(), TupleDescGetAttInMetadata(), and verify_heapam_tupdesc().

2083 {
2084  if (tupdesc->tdtypeid == RECORDOID &&
2085  tupdesc->tdtypmod < 0)
2086  assign_record_type_typmod(tupdesc);
2087 
2088  return tupdesc; /* just for notational convenience */
2089 }
void assign_record_type_typmod(TupleDesc tupDesc)
Definition: typcache.c:1946
int32 tdtypmod
Definition: tupdesc.h:83
Oid tdtypeid
Definition: tupdesc.h:82

◆ BuildTupleFromCStrings()

HeapTuple BuildTupleFromCStrings ( AttInMetadata attinmeta,
char **  values 
)

Definition at line 2146 of file execTuples.c.

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

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

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

◆ do_text_output_multiline()

void do_text_output_multiline ( TupOutputState tstate,
const char *  txt 
)

Definition at line 2314 of file execTuples.c.

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

Referenced by ExplainQuery().

2315 {
2316  Datum values[1];
2317  bool isnull[1] = {false};
2318 
2319  while (*txt)
2320  {
2321  const char *eol;
2322  int len;
2323 
2324  eol = strchr(txt, '\n');
2325  if (eol)
2326  {
2327  len = eol - txt;
2328  eol++;
2329  }
2330  else
2331  {
2332  len = strlen(txt);
2333  eol = txt + len;
2334  }
2335 
2336  values[0] = PointerGetDatum(cstring_to_text_with_len(txt, len));
2337  do_tup_output(tstate, values, isnull);
2338  pfree(DatumGetPointer(values[0]));
2339  txt = eol;
2340  }
2341 }
#define PointerGetDatum(X)
Definition: postgres.h:600
void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
Definition: execTuples.c:2286
void pfree(void *pointer)
Definition: mcxt.c:1169
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:202
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetPointer(X)
Definition: postgres.h:593
static Datum values[MAXATTR]
Definition: bootstrap.c:166

◆ do_tup_output()

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

Definition at line 2286 of file execTuples.c.

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

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

2287 {
2288  TupleTableSlot *slot = tstate->slot;
2289  int natts = slot->tts_tupleDescriptor->natts;
2290 
2291  /* make sure the slot is clear */
2292  ExecClearTuple(slot);
2293 
2294  /* insert data */
2295  memcpy(slot->tts_values, values, natts * sizeof(Datum));
2296  memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
2297 
2298  /* mark slot as containing a virtual tuple */
2299  ExecStoreVirtualTuple(slot);
2300 
2301  /* send the tuple to the receiver */
2302  (void) tstate->dest->receiveSlot(slot, tstate->dest);
2303 
2304  /* clean up */
2305  ExecClearTuple(slot);
2306 }
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:119
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
Datum * tts_values
Definition: tuptable.h:126
TupleTableSlot * slot
Definition: executor.h:488
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:411
static Datum values[MAXATTR]
Definition: bootstrap.c:166
DestReceiver * dest
Definition: executor.h:489
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552

◆ end_tup_output()

void end_tup_output ( TupOutputState tstate)

Definition at line 2344 of file execTuples.c.

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

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

2345 {
2346  tstate->dest->rShutdown(tstate->dest);
2347  /* note that destroying the dest is not ours to do */
2349  pfree(tstate);
2350 }
TupleTableSlot * slot
Definition: executor.h:488
void pfree(void *pointer)
Definition: mcxt.c:1169
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1254
void(* rShutdown)(DestReceiver *self)
Definition: dest.h:125
DestReceiver * dest
Definition: executor.h:489

◆ ExecAllocTableSlot()

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

Definition at line 1171 of file execTuples.c.

References lappend(), and MakeTupleTableSlot().

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

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

◆ ExecCleanTypeFromTL()

TupleDesc ExecCleanTypeFromTL ( List targetList)

Definition at line 1950 of file execTuples.c.

References ExecTypeFromTLInternal().

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

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

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 1254 of file execTuples.c.

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(), compute_expr_stats(), compute_index_stats(), CopyMultiInsertBufferCleanup(), copyTemplateDependencies(), DefineQueryRewrite(), DoCopyTo(), end_tup_output(), ExecBatchInsert(), ExecCleanupTupleRouting(), ExecEndIncrementalSort(), ExecEndModifyTable(), fetch_remote_table_info(), fetch_table_list(), get_actual_variable_range(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), hypothetical_dense_rank_final(), IndexCheckExclusion(), InsertPgAttributeTuples(), make_build_data(), recordMultipleDependencies(), RelationFindReplTupleSeq(), RI_Initial_Check(), RunFromStore(), systable_endscan(), systable_endscan_ordered(), table_index_fetch_tuple_check(), tstoreShutdownReceiver(), tuplesort_free(), unique_key_recheck(), validateDomainConstraint(), and validateForeignKeyConstraint().

1255 {
1256  /* This should match ExecResetTupleTable's processing of one slot */
1257  Assert(IsA(slot, TupleTableSlot));
1258  ExecClearTuple(slot);
1259  slot->tts_ops->release(slot);
1260  if (slot->tts_tupleDescriptor)
1262  if (!TTS_FIXED(slot))
1263  {
1264  if (slot->tts_values)
1265  pfree(slot->tts_values);
1266  if (slot->tts_isnull)
1267  pfree(slot->tts_isnull);
1268  }
1269  pfree(slot);
1270 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
void(* release)(TupleTableSlot *slot)
Definition: tuptable.h:144
Datum * tts_values
Definition: tuptable.h:126
void pfree(void *pointer)
Definition: mcxt.c:1169
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122

◆ ExecFetchSlotHeapTuple()

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

Definition at line 1644 of file execTuples.c.

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().

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

◆ ExecFetchSlotHeapTupleDatum()

Datum ExecFetchSlotHeapTupleDatum ( TupleTableSlot slot)

Definition at line 1723 of file execTuples.c.

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

Referenced by ExecMakeFunctionResultSet(), and postquel_get_single_result().

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

◆ ExecFetchSlotMinimalTuple()

MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot,
bool shouldFree 
)

Definition at line 1692 of file execTuples.c.

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().

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

◆ ExecForceStoreHeapTuple()

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

Definition at line 1469 of file execTuples.c.

References BufferHeapTupleTableSlot::base, 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, TupleTableSlot::tts_values, and HeapTupleTableSlot::tuple.

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

1472 {
1473  if (TTS_IS_HEAPTUPLE(slot))
1474  {
1475  ExecStoreHeapTuple(tuple, slot, shouldFree);
1476  }
1477  else if (TTS_IS_BUFFERTUPLE(slot))
1478  {
1479  MemoryContext oldContext;
1481 
1482  ExecClearTuple(slot);
1483  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1484  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
1485  bslot->base.tuple = heap_copytuple(tuple);
1486  slot->tts_flags |= TTS_FLAG_SHOULDFREE;
1487  MemoryContextSwitchTo(oldContext);
1488 
1489  if (shouldFree)
1490  pfree(tuple);
1491  }
1492  else
1493  {
1494  ExecClearTuple(slot);
1496  slot->tts_values, slot->tts_isnull);
1497  ExecStoreVirtualTuple(slot);
1498 
1499  if (shouldFree)
1500  {
1501  ExecMaterializeSlot(slot);
1502  pfree(tuple);
1503  }
1504  }
1505 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
HeapTuple tuple
Definition: tuptable.h:250
MemoryContext tts_mcxt
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:126
uint16 tts_flags
Definition: tuptable.h:119
void pfree(void *pointer)
Definition: mcxt.c:1169
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define TTS_IS_BUFFERTUPLE(slot)
Definition: tuptable.h:231
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:443
#define TTS_IS_HEAPTUPLE(slot)
Definition: tuptable.h:229
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
HeapTupleTableSlot base
Definition: tuptable.h:259
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1352
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552

◆ ExecForceStoreMinimalTuple()

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

Definition at line 1512 of file execTuples.c.

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().

1515 {
1516  if (TTS_IS_MINIMALTUPLE(slot))
1517  {
1518  tts_minimal_store_tuple(slot, mtup, shouldFree);
1519  }
1520  else
1521  {
1522  HeapTupleData htup;
1523 
1524  ExecClearTuple(slot);
1525 
1526  htup.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
1527  htup.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
1529  slot->tts_values, slot->tts_isnull);
1530  ExecStoreVirtualTuple(slot);
1531 
1532  if (shouldFree)
1533  {
1534  ExecMaterializeSlot(slot);
1535  pfree(mtup);
1536  }
1537  }
1538 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define TTS_IS_MINIMALTUPLE(slot)
Definition: tuptable.h:230
Datum * tts_values
Definition: tuptable.h:126
HeapTupleHeader t_data
Definition: htup.h:68
void pfree(void *pointer)
Definition: mcxt.c:1169
uint32 t_len
Definition: htup.h:64
bool * tts_isnull
Definition: tuptable.h:128
static void tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
Definition: execTuples.c:620
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:443
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:618
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552

◆ ExecInitExtraTupleSlot()

◆ ExecInitNullTupleSlot()

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

Definition at line 1847 of file execTuples.c.

References ExecInitExtraTupleSlot(), and ExecStoreAllNullTuple().

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

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

◆ ExecInitResultSlot()

void ExecInitResultSlot ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

Definition at line 1779 of file execTuples.c.

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().

1780 {
1781  TupleTableSlot *slot;
1782 
1783  slot = ExecAllocTableSlot(&planstate->state->es_tupleTable,
1784  planstate->ps_ResultTupleDesc, tts_ops);
1785  planstate->ps_ResultTupleSlot = slot;
1786 
1787  planstate->resultopsfixed = planstate->ps_ResultTupleDesc != NULL;
1788  planstate->resultops = tts_ops;
1789  planstate->resultopsset = true;
1790 }
EState * state
Definition: execnodes.h:966
const TupleTableSlotOps * resultops
Definition: execnodes.h:1039
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1002
bool resultopsset
Definition: execnodes.h:1047
TupleTableSlot * ExecAllocTableSlot(List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1171
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1001
List * es_tupleTable
Definition: execnodes.h:600
bool resultopsfixed
Definition: execnodes.h:1043

◆ ExecInitResultTupleSlotTL()

void ExecInitResultTupleSlotTL ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

◆ ExecInitResultTypeTL()

◆ ExecInitScanTupleSlot()

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

Definition at line 1811 of file execTuples.c.

References EState::es_tupleTable, ExecAllocTableSlot(), ScanState::ps, PlanState::scandesc, PlanState::scanops, PlanState::scanopsfixed, PlanState::scanopsset, and ScanState::ss_ScanTupleSlot.

Referenced by ExecCreateScanSlotFromOuterPlan(), ExecInitBitmapHeapScan(), ExecInitCteScan(), ExecInitCustomScan(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitNamedTuplestoreScan(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitSubqueryScan(), ExecInitTableFuncScan(), ExecInitTidRangeScan(), ExecInitTidScan(), ExecInitValuesScan(), and ExecInitWorkTableScan().

1813 {
1814  scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable,
1815  tupledesc, tts_ops);
1816  scanstate->ps.scandesc = tupledesc;
1817  scanstate->ps.scanopsfixed = tupledesc != NULL;
1818  scanstate->ps.scanops = tts_ops;
1819  scanstate->ps.scanopsset = true;
1820 }
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1376
PlanState ps
Definition: execnodes.h:1373
const TupleTableSlotOps * scanops
Definition: execnodes.h:1036
TupleTableSlot * ExecAllocTableSlot(List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1171
List * es_tupleTable
Definition: execnodes.h:600
TupleDesc scandesc
Definition: execnodes.h:1011
bool scanopsfixed
Definition: execnodes.h:1040
bool scanopsset
Definition: execnodes.h:1044

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 1191 of file execTuples.c.

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_estate().

1193 {
1194  ListCell *lc;
1195 
1196  foreach(lc, tupleTable)
1197  {
1199 
1200  /* Always release resources and reset the slot to empty */
1201  ExecClearTuple(slot);
1202  slot->tts_ops->release(slot);
1203  if (slot->tts_tupleDescriptor)
1204  {
1206  slot->tts_tupleDescriptor = NULL;
1207  }
1208 
1209  /* If shouldFree, release memory occupied by the slot itself */
1210  if (shouldFree)
1211  {
1212  if (!TTS_FIXED(slot))
1213  {
1214  if (slot->tts_values)
1215  pfree(slot->tts_values);
1216  if (slot->tts_isnull)
1217  pfree(slot->tts_isnull);
1218  }
1219  pfree(slot);
1220  }
1221  }
1222 
1223  /* If shouldFree, release the list structure */
1224  if (shouldFree)
1225  list_free(tupleTable);
1226 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
void(* release)(TupleTableSlot *slot)
Definition: tuptable.h:144
Datum * tts_values
Definition: tuptable.h:126
void pfree(void *pointer)
Definition: mcxt.c:1169
#define lfirst_node(type, lc)
Definition: pg_list.h:172
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void list_free(List *list)
Definition: list.c:1391
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122

◆ ExecSetSlotDescriptor()

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 1289 of file execTuples.c.

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().

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

◆ ExecStoreAllNullTuple()

TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 1576 of file execTuples.c.

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().

1577 {
1578  /*
1579  * sanity checks
1580  */
1581  Assert(slot != NULL);
1582  Assert(slot->tts_tupleDescriptor != NULL);
1583 
1584  /* Clear any old contents */
1585  ExecClearTuple(slot);
1586 
1587  /*
1588  * Fill all the columns of the virtual tuple with nulls
1589  */
1590  MemSet(slot->tts_values, 0,
1591  slot->tts_tupleDescriptor->natts * sizeof(Datum));
1592  memset(slot->tts_isnull, true,
1593  slot->tts_tupleDescriptor->natts * sizeof(bool));
1594 
1595  return ExecStoreVirtualTuple(slot);
1596 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
#define MemSet(start, val, len)
Definition: c.h:1008
Datum * tts_values
Definition: tuptable.h:126
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:411
#define Assert(condition)
Definition: c.h:804
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552

◆ ExecStoreBufferHeapTuple()

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

Definition at line 1392 of file execTuples.c.

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().

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

◆ ExecStoreHeapTuple()

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

Definition at line 1352 of file execTuples.c.

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(), compute_expr_stats(), compute_index_stats(), ExecForceStoreHeapTuple(), ExecuteCallStmt(), get_returning_data(), heapam_index_validate_scan(), make_build_data(), postgresIterateForeignScan(), setop_retrieve_direct(), and tts_heap_copyslot().

1355 {
1356  /*
1357  * sanity checks
1358  */
1359  Assert(tuple != NULL);
1360  Assert(slot != NULL);
1361  Assert(slot->tts_tupleDescriptor != NULL);
1362 
1363  if (unlikely(!TTS_IS_HEAPTUPLE(slot)))
1364  elog(ERROR, "trying to store a heap tuple into wrong type of slot");
1365  tts_heap_store_tuple(slot, tuple, shouldFree);
1366 
1367  slot->tts_tableOid = tuple->t_tableOid;
1368 
1369  return slot;
1370 }
Oid tts_tableOid
Definition: tuptable.h:131
#define ERROR
Definition: elog.h:46
Oid t_tableOid
Definition: htup.h:66
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define TTS_IS_HEAPTUPLE(slot)
Definition: tuptable.h:229
#define Assert(condition)
Definition: c.h:804
#define elog(elevel,...)
Definition: elog.h:232
static void tts_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, bool shouldFree)
Definition: execTuples.c:448
#define unlikely(x)
Definition: c.h:273

◆ ExecStoreHeapTupleDatum()

void ExecStoreHeapTupleDatum ( Datum  data,
TupleTableSlot slot 
)

Definition at line 1606 of file execTuples.c.

References 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().

1607 {
1608  HeapTupleData tuple = {0};
1609  HeapTupleHeader td;
1610 
1611  td = DatumGetHeapTupleHeader(data);
1612 
1614  tuple.t_self = td->t_ctid;
1615  tuple.t_data = td;
1616 
1617  ExecClearTuple(slot);
1618 
1619  heap_deform_tuple(&tuple, slot->tts_tupleDescriptor,
1620  slot->tts_values, slot->tts_isnull);
1621  ExecStoreVirtualTuple(slot);
1622 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
Datum * tts_values
Definition: tuptable.h:126
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:295
HeapTupleHeader t_data
Definition: htup.h:68
ItemPointerData t_ctid
Definition: htup_details.h:160
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ ExecStoreMinimalTuple()

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

Definition at line 1446 of file execTuples.c.

References Assert, elog, ERROR, TTS_IS_MINIMALTUPLE, tts_minimal_store_tuple(), TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by agg_refill_hash_table(), agg_retrieve_hash_table_in_memory(), ExecParallelScanHashBucket(), ExecResultCache(), ExecScanHashBucket(), ExecScanHashTableForUnmatched(), findPartialMatch(), gather_getnext(), gather_merge_readnext(), prepare_probe_slot(), ResultCacheHash_equal(), setop_retrieve_hash_table(), tts_minimal_copyslot(), TupleHashTableHash_internal(), TupleHashTableMatch(), tuplesort_gettupleslot(), and tuplestore_gettupleslot().

1449 {
1450  /*
1451  * sanity checks
1452  */
1453  Assert(mtup != NULL);
1454  Assert(slot != NULL);
1455  Assert(slot->tts_tupleDescriptor != NULL);
1456 
1457  if (unlikely(!TTS_IS_MINIMALTUPLE(slot)))
1458  elog(ERROR, "trying to store a minimal tuple into wrong type of slot");
1459  tts_minimal_store_tuple(slot, mtup, shouldFree);
1460 
1461  return slot;
1462 }
#define TTS_IS_MINIMALTUPLE(slot)
Definition: tuptable.h:230
#define ERROR
Definition: elog.h:46
static void tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
Definition: execTuples.c:620
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273

◆ ExecStorePinnedBufferHeapTuple()

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

Definition at line 1418 of file execTuples.c.

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().

1421 {
1422  /*
1423  * sanity checks
1424  */
1425  Assert(tuple != NULL);
1426  Assert(slot != NULL);
1427  Assert(slot->tts_tupleDescriptor != NULL);
1428  Assert(BufferIsValid(buffer));
1429 
1430  if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1431  elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1432  tts_buffer_heap_store_tuple(slot, tuple, buffer, true);
1433 
1434  slot->tts_tableOid = tuple->t_tableOid;
1435 
1436  return slot;
1437 }
Oid tts_tableOid
Definition: tuptable.h:131
static void tts_buffer_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
Definition: execTuples.c:859
#define ERROR
Definition: elog.h:46
Oid t_tableOid
Definition: htup.h:66
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define TTS_IS_BUFFERTUPLE(slot)
Definition: tuptable.h:231
#define Assert(condition)
Definition: c.h:804
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273

◆ ExecStoreVirtualTuple()

TupleTableSlot* ExecStoreVirtualTuple ( TupleTableSlot slot)

Definition at line 1552 of file execTuples.c.

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(), do_tup_output(), ExecComputeStoredGenerated(), ExecEvalAggOrderedTransTuple(), ExecFilterJunk(), ExecForceStoreHeapTuple(), ExecForceStoreMinimalTuple(), ExecProjectSRF(), ExecStoreAllNullTuple(), ExecStoreHeapTupleDatum(), execute_attr_map_slot(), fileIterateForeignScan(), FunctionNext(), hashagg_spill_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), InsertPgAttributeTuples(), ordered_set_transition_multi(), prepare_hash_slot(), prepare_probe_slot(), recordMultipleDependencies(), RI_Initial_Check(), RI_PartitionRemove_Check(), slot_modify_data(), slot_store_data(), StoreIndexTuple(), and ValuesNext().

1553 {
1554  /*
1555  * sanity checks
1556  */
1557  Assert(slot != NULL);
1558  Assert(slot->tts_tupleDescriptor != NULL);
1559  Assert(TTS_EMPTY(slot));
1560 
1561  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1562  slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
1563 
1564  return slot;
1565 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
uint16 tts_flags
Definition: tuptable.h:119
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ ExecTypeFromExprList()

TupleDesc ExecTypeFromExprList ( List exprList)

Definition at line 1997 of file execTuples.c.

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

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

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

◆ ExecTypeFromTL()

TupleDesc ExecTypeFromTL ( List targetList)

Definition at line 1938 of file execTuples.c.

References ExecTypeFromTLInternal().

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

1939 {
1940  return ExecTypeFromTLInternal(targetList, false);
1941 }
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool skipjunk)
Definition: execTuples.c:1956

◆ ExecTypeFromTLInternal()

static TupleDesc ExecTypeFromTLInternal ( List targetList,
bool  skipjunk 
)
static

Definition at line 1956 of file execTuples.c.

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

Referenced by ExecCleanTypeFromTL(), and ExecTypeFromTL().

1957 {
1958  TupleDesc typeInfo;
1959  ListCell *l;
1960  int len;
1961  int cur_resno = 1;
1962 
1963  if (skipjunk)
1964  len = ExecCleanTargetListLength(targetList);
1965  else
1966  len = ExecTargetListLength(targetList);
1967  typeInfo = CreateTemplateTupleDesc(len);
1968 
1969  foreach(l, targetList)
1970  {
1971  TargetEntry *tle = lfirst(l);
1972 
1973  if (skipjunk && tle->resjunk)
1974  continue;
1975  TupleDescInitEntry(typeInfo,
1976  cur_resno,
1977  tle->resname,
1978  exprType((Node *) tle->expr),
1979  exprTypmod((Node *) tle->expr),
1980  0);
1981  TupleDescInitEntryCollation(typeInfo,
1982  cur_resno,
1983  exprCollation((Node *) tle->expr));
1984  cur_resno++;
1985  }
1986 
1987  return typeInfo;
1988 }
int ExecTargetListLength(List *targetlist)
Definition: execUtils.c:1137
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:267
Definition: nodes.h:539
char * resname
Definition: primnodes.h:1446
bool resjunk
Definition: primnodes.h:1451
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:751
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:580
int ExecCleanTargetListLength(List *targetlist)
Definition: execUtils.c:1147
#define lfirst(lc)
Definition: pg_list.h:169
Expr * expr
Definition: primnodes.h:1444
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:759

◆ ExecTypeSetColNames()

void ExecTypeSetColNames ( TupleDesc  typeInfo,
List namesList 
)

Definition at line 2036 of file execTuples.c.

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

Referenced by ExecEvalWholeRowVar(), and ExecInitExprRec().

2037 {
2038  bool modified = false;
2039  int colno = 0;
2040  ListCell *lc;
2041 
2042  foreach(lc, namesList)
2043  {
2044  char *cname = strVal(lfirst(lc));
2045  Form_pg_attribute attr;
2046 
2047  /* Guard against too-long names list */
2048  if (colno >= typeInfo->natts)
2049  break;
2050  attr = TupleDescAttr(typeInfo, colno);
2051  colno++;
2052 
2053  /* Ignore empty aliases (these must be for dropped columns) */
2054  if (cname[0] == '\0')
2055  continue;
2056 
2057  /* Change tupdesc only if alias is actually different */
2058  if (strcmp(cname, NameStr(attr->attname)) != 0)
2059  {
2060  namestrcpy(&(attr->attname), cname);
2061  modified = true;
2062  }
2063  }
2064 
2065  /* If we modified the tupdesc, it's now a new record type */
2066  if (modified)
2067  {
2068  typeInfo->tdtypeid = RECORDOID;
2069  typeInfo->tdtypmod = -1;
2070  }
2071 }
void namestrcpy(Name name, const char *str)
Definition: name.c:233
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define strVal(v)
Definition: value.h:54
int32 tdtypmod
Definition: tupdesc.h:83
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:203
#define lfirst(lc)
Definition: pg_list.h:169
Oid tdtypeid
Definition: tupdesc.h:82
#define NameStr(name)
Definition: c.h:681

◆ HeapTupleHeaderGetDatum()

Datum HeapTupleHeaderGetDatum ( HeapTupleHeader  tuple)

Definition at line 2235 of file execTuples.c.

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

Referenced by populate_composite(), and populate_recordset_record().

2236 {
2237  Datum result;
2238  TupleDesc tupDesc;
2239 
2240  /* No work if there are no external TOAST pointers in the tuple */
2241  if (!HeapTupleHeaderHasExternal(tuple))
2242  return PointerGetDatum(tuple);
2243 
2244  /* Use the type data saved by heap_form_tuple to look up the rowtype */
2246  HeapTupleHeaderGetTypMod(tuple));
2247 
2248  /* And do the flattening */
2249  result = toast_flatten_tuple_to_datum(tuple,
2251  tupDesc);
2252 
2253  ReleaseTupleDesc(tupDesc);
2254 
2255  return result;
2256 }
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1826
#define PointerGetDatum(X)
Definition: postgres.h:600
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:467
uintptr_t Datum
Definition: postgres.h:411
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:457
#define HeapTupleHeaderHasExternal(tup)
Definition: htup_details.h:538
Datum toast_flatten_tuple_to_datum(HeapTupleHeader tup, uint32 tup_len, TupleDesc tupleDesc)
Definition: heaptoast.c:449
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

TupleTableSlot* MakeTupleTableSlot ( TupleDesc  tupleDesc,
const TupleTableSlotOps tts_ops 
)

Definition at line 1112 of file execTuples.c.

References TupleTableSlotOps::base_slot_size, CurrentMemoryContext, TupleTableSlotOps::init, MAXALIGN, TupleDescData::natts, palloc0(), PinTupleDesc, T_TupleTableSlot, 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(), and MakeSingleTupleTableSlot().

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

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

References att_addlength_pointer, att_align_nominal, att_align_pointer, att_isnull, attnum, TupleTableSlotOps::base_slot_size, fetchatt, HeapTupleHasNulls, HeapTupleHeaderGetNatts, init, Min, HeapTupleHeaderData::t_bits, HeapTupleData::t_data, HeapTupleHeaderData::t_hoff, tts_buffer_heap_clear(), tts_buffer_heap_copy_heap_tuple(), tts_buffer_heap_copy_minimal_tuple(), tts_buffer_heap_copyslot(), tts_buffer_heap_get_heap_tuple(), tts_buffer_heap_getsomeattrs(), tts_buffer_heap_getsysattr(), tts_buffer_heap_init(), tts_buffer_heap_materialize(), tts_buffer_heap_release(), TTS_FLAG_SLOW, tts_heap_clear(), tts_heap_copy_heap_tuple(), tts_heap_copy_minimal_tuple(), tts_heap_copyslot(), tts_heap_get_heap_tuple(), tts_heap_getsomeattrs(), tts_heap_getsysattr(), tts_heap_init(), tts_heap_materialize(), tts_heap_release(), TupleTableSlot::tts_isnull, tts_minimal_clear(), tts_minimal_copy_heap_tuple(), tts_minimal_copy_minimal_tuple(), tts_minimal_copyslot(), tts_minimal_get_minimal_tuple(), tts_minimal_getsomeattrs(), tts_minimal_getsysattr(), tts_minimal_init(), tts_minimal_materialize(), tts_minimal_release(), TupleTableSlot::tts_nvalid, TTS_SLOW, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, tts_virtual_clear(), tts_virtual_copy_heap_tuple(), tts_virtual_copy_minimal_tuple(), tts_virtual_copyslot(), tts_virtual_getsomeattrs(), tts_virtual_getsysattr(), tts_virtual_init(), tts_virtual_materialize(), tts_virtual_release(), TupleDescAttr, and values.

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

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

◆ slot_getmissingattrs()

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

Definition at line 1868 of file execTuples.c.

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().

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

◆ slot_getsomeattrs_int()

void slot_getsomeattrs_int ( TupleTableSlot slot,
int  attnum 
)

Definition at line 1902 of file execTuples.c.

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().

1903 {
1904  /* Check for caller errors */
1905  Assert(slot->tts_nvalid < attnum); /* checked in slot_getsomeattrs */
1906  Assert(attnum > 0);
1907 
1908  if (unlikely(attnum > slot->tts_tupleDescriptor->natts))
1909  elog(ERROR, "invalid attribute number %d", attnum);
1910 
1911  /* Fetch as many attributes as possible from the underlying tuple. */
1912  slot->tts_ops->getsomeattrs(slot, attnum);
1913 
1914  /*
1915  * If the underlying tuple doesn't have enough attributes, tuple
1916  * descriptor must have the missing attributes.
1917  */
1918  if (unlikely(slot->tts_nvalid < attnum))
1919  {
1920  slot_getmissingattrs(slot, slot->tts_nvalid, attnum);
1921  slot->tts_nvalid = attnum;
1922  }
1923 }
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
#define ERROR
Definition: elog.h:46
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
int16 attnum
Definition: pg_attribute.h:83
#define Assert(condition)
Definition: c.h:804
void(* getsomeattrs)(TupleTableSlot *slot, int natts)
Definition: tuptable.h:161
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
Definition: execTuples.c:1868
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ tts_buffer_heap_clear()

static void tts_buffer_heap_clear ( TupleTableSlot slot)
static

Definition at line 659 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

660 {
662 
663  /*
664  * Free the memory for heap tuple if allowed. A tuple coming from buffer
665  * can never be freed. But we may have materialized a tuple from buffer.
666  * Such a tuple can be freed.
667  */
668  if (TTS_SHOULDFREE(slot))
669  {
670  /* We should have unpinned the buffer while materializing the tuple. */
671  Assert(!BufferIsValid(bslot->buffer));
672 
673  heap_freetuple(bslot->base.tuple);
674  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
675  }
676 
677  if (BufferIsValid(bslot->buffer))
678  ReleaseBuffer(bslot->buffer);
679 
680  slot->tts_nvalid = 0;
681  slot->tts_flags |= TTS_FLAG_EMPTY;
683  bslot->base.tuple = NULL;
684  bslot->base.off = 0;
685  bslot->buffer = InvalidBuffer;
686 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
#define InvalidBuffer
Definition: buf.h:25
HeapTuple tuple
Definition: tuptable.h:250
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3784
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
uint16 tts_flags
Definition: tuptable.h:119
#define Assert(condition)
Definition: c.h:804
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
AttrNumber tts_nvalid
Definition: tuptable.h:121
HeapTupleTableSlot base
Definition: tuptable.h:259
ItemPointerData tts_tid
Definition: tuptable.h:130

◆ tts_buffer_heap_copy_heap_tuple()

static HeapTuple tts_buffer_heap_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 833 of file execTuples.c.

References Assert, BufferHeapTupleTableSlot::base, heap_copytuple(), tts_buffer_heap_materialize(), TTS_EMPTY, and HeapTupleTableSlot::tuple.

Referenced by slot_deform_heap_tuple().

834 {
836 
837  Assert(!TTS_EMPTY(slot));
838 
839  if (!bslot->base.tuple)
841 
842  return heap_copytuple(bslot->base.tuple);
843 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
#define Assert(condition)
Definition: c.h:804
static void tts_buffer_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:719
HeapTupleTableSlot base
Definition: tuptable.h:259

◆ tts_buffer_heap_copy_minimal_tuple()

static MinimalTuple tts_buffer_heap_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 846 of file execTuples.c.

References Assert, BufferHeapTupleTableSlot::base, minimal_tuple_from_heap_tuple(), tts_buffer_heap_materialize(), TTS_EMPTY, and HeapTupleTableSlot::tuple.

Referenced by slot_deform_heap_tuple().

847 {
849 
850  Assert(!TTS_EMPTY(slot));
851 
852  if (!bslot->base.tuple)
854 
856 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
#define Assert(condition)
Definition: c.h:804
static void tts_buffer_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:719
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Definition: heaptuple.c:1480
HeapTupleTableSlot base
Definition: tuptable.h:259

◆ tts_buffer_heap_copyslot()

static void tts_buffer_heap_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 778 of file execTuples.c.

References Assert, BufferHeapTupleTableSlot::base, 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, TTS_SHOULDFREE, HeapTupleTableSlot::tupdata, and HeapTupleTableSlot::tuple.

Referenced by slot_deform_heap_tuple().

779 {
780  BufferHeapTupleTableSlot *bsrcslot = (BufferHeapTupleTableSlot *) srcslot;
781  BufferHeapTupleTableSlot *bdstslot = (BufferHeapTupleTableSlot *) dstslot;
782 
783  /*
784  * If the source slot is of a different kind, or is a buffer slot that has
785  * been materialized / is virtual, make a new copy of the tuple. Otherwise
786  * make a new reference to the in-buffer tuple.
787  */
788  if (dstslot->tts_ops != srcslot->tts_ops ||
789  TTS_SHOULDFREE(srcslot) ||
790  !bsrcslot->base.tuple)
791  {
792  MemoryContext oldContext;
793 
794  ExecClearTuple(dstslot);
795  dstslot->tts_flags &= ~TTS_FLAG_EMPTY;
796  oldContext = MemoryContextSwitchTo(dstslot->tts_mcxt);
797  bdstslot->base.tuple = ExecCopySlotHeapTuple(srcslot);
798  dstslot->tts_flags |= TTS_FLAG_SHOULDFREE;
799  MemoryContextSwitchTo(oldContext);
800  }
801  else
802  {
803  Assert(BufferIsValid(bsrcslot->buffer));
804 
805  tts_buffer_heap_store_tuple(dstslot, bsrcslot->base.tuple,
806  bsrcslot->buffer, false);
807 
808  /*
809  * The HeapTupleData portion of the source tuple might be shorter
810  * lived than the destination slot. Therefore copy the HeapTuple into
811  * our slot's tupdata, which is guaranteed to live long enough (but
812  * will still point into the buffer).
813  */
814  memcpy(&bdstslot->base.tupdata, bdstslot->base.tuple, sizeof(HeapTupleData));
815  bdstslot->base.tuple = &bdstslot->base.tupdata;
816  }
817 }
static void tts_buffer_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
Definition: execTuples.c:859
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
HeapTuple tuple
Definition: tuptable.h:250
MemoryContext tts_mcxt
Definition: tuptable.h:129
uint16 tts_flags
Definition: tuptable.h:119
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:452
#define Assert(condition)
Definition: c.h:804
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
HeapTupleTableSlot base
Definition: tuptable.h:259
HeapTupleData tupdata
Definition: tuptable.h:253

◆ tts_buffer_heap_get_heap_tuple()

static HeapTuple tts_buffer_heap_get_heap_tuple ( TupleTableSlot slot)
static

Definition at line 820 of file execTuples.c.

References Assert, BufferHeapTupleTableSlot::base, tts_buffer_heap_materialize(), TTS_EMPTY, and HeapTupleTableSlot::tuple.

Referenced by slot_deform_heap_tuple().

821 {
823 
824  Assert(!TTS_EMPTY(slot));
825 
826  if (!bslot->base.tuple)
828 
829  return bslot->base.tuple;
830 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
#define Assert(condition)
Definition: c.h:804
static void tts_buffer_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:719
HeapTupleTableSlot base
Definition: tuptable.h:259

◆ tts_buffer_heap_getsomeattrs()

static void tts_buffer_heap_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 689 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

690 {
692 
693  Assert(!TTS_EMPTY(slot));
694 
695  slot_deform_heap_tuple(slot, bslot->base.tuple, &bslot->base.off, natts);
696 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
static pg_attribute_always_inline void slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int natts)
Definition: execTuples.c:925
#define Assert(condition)
Definition: c.h:804
HeapTupleTableSlot base
Definition: tuptable.h:259

◆ tts_buffer_heap_getsysattr()

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

Definition at line 699 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

700 {
702 
703  Assert(!TTS_EMPTY(slot));
704 
705  /*
706  * In some code paths it's possible to get here with a non-materialized
707  * slot, in which case we can't retrieve system columns.
708  */
709  if (!bslot->base.tuple)
710  ereport(ERROR,
711  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
712  errmsg("cannot retrieve a system column in this context")));
713 
714  return heap_getsysattr(bslot->base.tuple, attnum,
715  slot->tts_tupleDescriptor, isnull);
716 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: heaptuple.c:627
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
int16 attnum
Definition: pg_attribute.h:83
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
int errmsg(const char *fmt,...)
Definition: elog.c:909
HeapTupleTableSlot base
Definition: tuptable.h:259

◆ tts_buffer_heap_init()

static void tts_buffer_heap_init ( TupleTableSlot slot)
static

Definition at line 649 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

650 {
651 }

◆ tts_buffer_heap_materialize()

static void tts_buffer_heap_materialize ( TupleTableSlot slot)
static

Definition at line 719 of file execTuples.c.

References Assert, BufferHeapTupleTableSlot::base, BufferHeapTupleTableSlot::buffer, BufferIsValid, heap_copytuple(), heap_form_tuple(), InvalidBuffer, likely, MemoryContextSwitchTo(), HeapTupleTableSlot::off, ReleaseBuffer(), 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 slot_deform_heap_tuple(), tts_buffer_heap_copy_heap_tuple(), tts_buffer_heap_copy_minimal_tuple(), and tts_buffer_heap_get_heap_tuple().

720 {
722  MemoryContext oldContext;
723 
724  Assert(!TTS_EMPTY(slot));
725 
726  /* If slot has its tuple already materialized, nothing to do. */
727  if (TTS_SHOULDFREE(slot))
728  return;
729 
730  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
731 
732  /*
733  * Have to deform from scratch, otherwise tts_values[] entries could point
734  * into the non-materialized tuple (which might be gone when accessed).
735  */
736  bslot->base.off = 0;
737  slot->tts_nvalid = 0;
738 
739  if (!bslot->base.tuple)
740  {
741  /*
742  * Normally BufferHeapTupleTableSlot should have a tuple + buffer
743  * associated with it, unless it's materialized (which would've
744  * returned above). But when it's useful to allow storing virtual
745  * tuples in a buffer slot, which then also needs to be
746  * materializable.
747  */
749  slot->tts_values,
750  slot->tts_isnull);
751  }
752  else
753  {
754  bslot->base.tuple = heap_copytuple(bslot->base.tuple);
755 
756  /*
757  * A heap tuple stored in a BufferHeapTupleTableSlot should have a
758  * buffer associated with it, unless it's materialized or virtual.
759  */
760  if (likely(BufferIsValid(bslot->buffer)))
761  ReleaseBuffer(bslot->buffer);
762  bslot->buffer = InvalidBuffer;
763  }
764 
765  /*
766  * We don't set TTS_FLAG_SHOULDFREE until after releasing the buffer, if
767  * any. This avoids having a transient state that would fall foul of our
768  * assertions that a slot with TTS_FLAG_SHOULDFREE doesn't own a buffer.
769  * In the unlikely event that ReleaseBuffer() above errors out, we'd
770  * effectively leak the copied tuple, but that seems fairly harmless.
771  */
773 
774  MemoryContextSwitchTo(oldContext);
775 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
#define likely(x)
Definition: c.h:272
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
#define InvalidBuffer
Definition: buf.h:25
HeapTuple tuple
Definition: tuptable.h:250
MemoryContext tts_mcxt
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:126
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3784
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
uint16 tts_flags
Definition: tuptable.h:119
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
AttrNumber tts_nvalid
Definition: tuptable.h:121
HeapTupleTableSlot base
Definition: tuptable.h:259

◆ tts_buffer_heap_release()

static void tts_buffer_heap_release ( TupleTableSlot slot)
static

Definition at line 654 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

655 {
656 }

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

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

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

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

◆ tts_heap_clear()

static void tts_heap_clear ( TupleTableSlot slot)
static

Definition at line 311 of file execTuples.c.

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 slot_deform_heap_tuple(), and tts_heap_store_tuple().

312 {
313  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
314 
315  /* Free the memory for the heap tuple if it's allowed. */
316  if (TTS_SHOULDFREE(slot))
317  {
318  heap_freetuple(hslot->tuple);
319  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
320  }
321 
322  slot->tts_nvalid = 0;
323  slot->tts_flags |= TTS_FLAG_EMPTY;
325  hslot->off = 0;
326  hslot->tuple = NULL;
327 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
HeapTuple tuple
Definition: tuptable.h:250
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
uint16 tts_flags
Definition: tuptable.h:119
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
AttrNumber tts_nvalid
Definition: tuptable.h:121
ItemPointerData tts_tid
Definition: tuptable.h:130

◆ tts_heap_copy_heap_tuple()

static HeapTuple tts_heap_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 425 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

426 {
427  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
428 
429  Assert(!TTS_EMPTY(slot));
430  if (!hslot->tuple)
431  tts_heap_materialize(slot);
432 
433  return heap_copytuple(hslot->tuple);
434 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
static void tts_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:360
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
#define Assert(condition)
Definition: c.h:804

◆ tts_heap_copy_minimal_tuple()

static MinimalTuple tts_heap_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 437 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

438 {
439  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
440 
441  if (!hslot->tuple)
442  tts_heap_materialize(slot);
443 
444  return minimal_tuple_from_heap_tuple(hslot->tuple);
445 }
static void tts_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:360
HeapTuple tuple
Definition: tuptable.h:250
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Definition: heaptuple.c:1480

◆ tts_heap_copyslot()

static void tts_heap_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 400 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

401 {
402  HeapTuple tuple;
403  MemoryContext oldcontext;
404 
405  oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt);
406  tuple = ExecCopySlotHeapTuple(srcslot);
407  MemoryContextSwitchTo(oldcontext);
408 
409  ExecStoreHeapTuple(tuple, dstslot, true);
410 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext tts_mcxt
Definition: tuptable.h:129
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:452
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1352

◆ tts_heap_get_heap_tuple()

static HeapTuple tts_heap_get_heap_tuple ( TupleTableSlot slot)
static

Definition at line 413 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

414 {
415  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
416 
417  Assert(!TTS_EMPTY(slot));
418  if (!hslot->tuple)
419  tts_heap_materialize(slot);
420 
421  return hslot->tuple;
422 }
static void tts_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:360
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
#define Assert(condition)
Definition: c.h:804

◆ tts_heap_getsomeattrs()

static void tts_heap_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 330 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

331 {
332  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
333 
334  Assert(!TTS_EMPTY(slot));
335 
336  slot_deform_heap_tuple(slot, hslot->tuple, &hslot->off, natts);
337 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
static pg_attribute_always_inline void slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int natts)
Definition: execTuples.c:925
#define Assert(condition)
Definition: c.h:804

◆ tts_heap_getsysattr()

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

Definition at line 340 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

341 {
342  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
343 
344  Assert(!TTS_EMPTY(slot));
345 
346  /*
347  * In some code paths it's possible to get here with a non-materialized
348  * slot, in which case we can't retrieve system columns.
349  */
350  if (!hslot->tuple)
351  ereport(ERROR,
352  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
353  errmsg("cannot retrieve a system column in this context")));
354 
355  return heap_getsysattr(hslot->tuple, attnum,
356  slot->tts_tupleDescriptor, isnull);
357 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTuple tuple
Definition: tuptable.h:250
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: heaptuple.c:627
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
int16 attnum
Definition: pg_attribute.h:83
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ tts_heap_init()

static void tts_heap_init ( TupleTableSlot slot)
static

Definition at line 301 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

302 {
303 }

◆ tts_heap_materialize()

static void tts_heap_materialize ( TupleTableSlot slot)
static

Definition at line 360 of file execTuples.c.

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 slot_deform_heap_tuple(), tts_heap_copy_heap_tuple(), tts_heap_copy_minimal_tuple(), and tts_heap_get_heap_tuple().

361 {
362  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
363  MemoryContext oldContext;
364 
365  Assert(!TTS_EMPTY(slot));
366 
367  /* If slot has its tuple already materialized, nothing to do. */
368  if (TTS_SHOULDFREE(slot))
369  return;
370 
371  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
372 
373  /*
374  * Have to deform from scratch, otherwise tts_values[] entries could point
375  * into the non-materialized tuple (which might be gone when accessed).
376  */
377  slot->tts_nvalid = 0;
378  hslot->off = 0;
379 
380  if (!hslot->tuple)
382  slot->tts_values,
383  slot->tts_isnull);
384  else
385  {
386  /*
387  * The tuple contained in this slot is not allocated in the memory
388  * context of the given slot (else it would have TTS_SHOULDFREE set).
389  * Copy the tuple into the given slot's memory context.
390  */
391  hslot->tuple = heap_copytuple(hslot->tuple);
392  }
393 
395 
396  MemoryContextSwitchTo(oldContext);
397 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
HeapTuple tuple
Definition: tuptable.h:250
MemoryContext tts_mcxt
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:126
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
uint16 tts_flags
Definition: tuptable.h:119
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ tts_heap_release()

static void tts_heap_release ( TupleTableSlot slot)
static

Definition at line 306 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

307 {
308 }

◆ tts_heap_store_tuple()

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

Definition at line 448 of file execTuples.c.

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().

449 {
450  HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
451 
452  tts_heap_clear(slot);
453 
454  slot->tts_nvalid = 0;
455  hslot->tuple = tuple;
456  hslot->off = 0;
458  slot->tts_tid = tuple->t_self;
459 
460  if (shouldFree)
462 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
HeapTuple tuple
Definition: tuptable.h:250
static void tts_heap_clear(TupleTableSlot *slot)
Definition: execTuples.c:311
uint16 tts_flags
Definition: tuptable.h:119
ItemPointerData t_self
Definition: htup.h:65
AttrNumber tts_nvalid
Definition: tuptable.h:121
ItemPointerData tts_tid
Definition: tuptable.h:130

◆ tts_minimal_clear()

static void tts_minimal_clear ( TupleTableSlot slot)
static

Definition at line 487 of file execTuples.c.

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 slot_deform_heap_tuple(), and tts_minimal_store_tuple().

488 {
490 
491  if (TTS_SHOULDFREE(slot))
492  {
494  slot->tts_flags &= ~TTS_FLAG_SHOULDFREE;
495  }
496 
497  slot->tts_nvalid = 0;
498  slot->tts_flags |= TTS_FLAG_EMPTY;
500  mslot->off = 0;
501  mslot->mintuple = NULL;
502 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
uint16 tts_flags
Definition: tuptable.h:119
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1427
MinimalTuple mintuple
Definition: tuptable.h:283
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
AttrNumber tts_nvalid
Definition: tuptable.h:121
ItemPointerData tts_tid
Definition: tuptable.h:130

◆ tts_minimal_copy_heap_tuple()

static HeapTuple tts_minimal_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 598 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

599 {
601 
602  if (!mslot->mintuple)
604 
606 }
static void tts_minimal_materialize(TupleTableSlot *slot)
Definition: execTuples.c:527
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1458
MinimalTuple mintuple
Definition: tuptable.h:283

◆ tts_minimal_copy_minimal_tuple()

static MinimalTuple tts_minimal_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 609 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

610 {
612 
613  if (!mslot->mintuple)
615 
616  return heap_copy_minimal_tuple(mslot->mintuple);
617 }
static void tts_minimal_materialize(TupleTableSlot *slot)
Definition: execTuples.c:527
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1439
MinimalTuple mintuple
Definition: tuptable.h:283

◆ tts_minimal_copyslot()

static void tts_minimal_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 574 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

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

◆ tts_minimal_get_minimal_tuple()

static MinimalTuple tts_minimal_get_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 587 of file execTuples.c.

References MinimalTupleTableSlot::mintuple, and tts_minimal_materialize().

Referenced by slot_deform_heap_tuple().

588 {
590 
591  if (!mslot->mintuple)
593 
594  return mslot->mintuple;
595 }
static void tts_minimal_materialize(TupleTableSlot *slot)
Definition: execTuples.c:527
MinimalTuple mintuple
Definition: tuptable.h:283

◆ tts_minimal_getsomeattrs()

static void tts_minimal_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 505 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

506 {
508 
509  Assert(!TTS_EMPTY(slot));
510 
511  slot_deform_heap_tuple(slot, mslot->tuple, &mslot->off, natts);
512 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
static pg_attribute_always_inline void slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int natts)
Definition: execTuples.c:925
#define Assert(condition)
Definition: c.h:804

◆ tts_minimal_getsysattr()

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

Definition at line 515 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

516 {
517  Assert(!TTS_EMPTY(slot));
518 
519  ereport(ERROR,
520  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
521  errmsg("cannot retrieve a system column in this context")));
522 
523  return 0; /* silence compiler warnings */
524 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ tts_minimal_init()

static void tts_minimal_init ( TupleTableSlot slot)
static

Definition at line 470 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

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

◆ tts_minimal_materialize()

static void tts_minimal_materialize ( TupleTableSlot slot)
static

Definition at line 527 of file execTuples.c.

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 slot_deform_heap_tuple(), tts_minimal_copy_heap_tuple(), tts_minimal_copy_minimal_tuple(), and tts_minimal_get_minimal_tuple().

528 {
530  MemoryContext oldContext;
531 
532  Assert(!TTS_EMPTY(slot));
533 
534  /* If slot has its tuple already materialized, nothing to do. */
535  if (TTS_SHOULDFREE(slot))
536  return;
537 
538  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
539 
540  /*
541  * Have to deform from scratch, otherwise tts_values[] entries could point
542  * into the non-materialized tuple (which might be gone when accessed).
543  */
544  slot->tts_nvalid = 0;
545  mslot->off = 0;
546 
547  if (!mslot->mintuple)
548  {
550  slot->tts_values,
551  slot->tts_isnull);
552  }
553  else
554  {
555  /*
556  * The minimal tuple contained in this slot is not allocated in the
557  * memory context of the given slot (else it would have TTS_SHOULDFREE
558  * set). Copy the minimal tuple into the given slot's memory context.
559  */
560  mslot->mintuple = heap_copy_minimal_tuple(mslot->mintuple);
561  }
562 
564 
565  Assert(mslot->tuple == &mslot->minhdr);
566 
567  mslot->minhdr.t_len = mslot->mintuple->t_len + MINIMAL_TUPLE_OFFSET;
568  mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mslot->mintuple - MINIMAL_TUPLE_OFFSET);
569 
570  MemoryContextSwitchTo(oldContext);
571 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
MemoryContext tts_mcxt
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:126
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1439
HeapTupleHeader t_data
Definition: htup.h:68
uint16 tts_flags
Definition: tuptable.h:119
uint32 t_len
Definition: htup.h:64
bool * tts_isnull
Definition: tuptable.h:128
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1356
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:618
MinimalTuple mintuple
Definition: tuptable.h:283
HeapTupleData minhdr
Definition: tuptable.h:284
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ tts_minimal_release()

static void tts_minimal_release ( TupleTableSlot slot)
static

Definition at line 482 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

483 {
484 }

◆ tts_minimal_store_tuple()

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

Definition at line 620 of file execTuples.c.

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().

621 {
623 
624  tts_minimal_clear(slot);
625 
626  Assert(!TTS_SHOULDFREE(slot));
627  Assert(TTS_EMPTY(slot));
628 
629  slot->tts_flags &= ~TTS_FLAG_EMPTY;
630  slot->tts_nvalid = 0;
631  mslot->off = 0;
632 
633  mslot->mintuple = mtup;
634  Assert(mslot->tuple == &mslot->minhdr);
635  mslot->minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
636  mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
637  /* no need to set t_self or t_tableOid since we won't allow access */
638 
639  if (shouldFree)
641 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
HeapTupleHeader t_data
Definition: htup.h:68
uint16 tts_flags
Definition: tuptable.h:119
uint32 t_len
Definition: htup.h:64
static void tts_minimal_clear(TupleTableSlot *slot)
Definition: execTuples.c:487
#define Assert(condition)
Definition: c.h:804
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:618
MinimalTuple mintuple
Definition: tuptable.h:283
HeapTupleData minhdr
Definition: tuptable.h:284
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ tts_virtual_clear()

static void tts_virtual_clear ( TupleTableSlot slot)
static

Definition at line 107 of file execTuples.c.

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 slot_deform_heap_tuple(), and tts_virtual_copyslot().

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 }
#define TTS_FLAG_EMPTY
Definition: tuptable.h:96
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
uint16 tts_flags
Definition: tuptable.h:119
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define unlikely(x)
Definition: c.h:273
AttrNumber tts_nvalid
Definition: tuptable.h:121
ItemPointerData tts_tid
Definition: tuptable.h:130

◆ tts_virtual_copy_heap_tuple()

static HeapTuple tts_virtual_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 276 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

277 {
278  Assert(!TTS_EMPTY(slot));
279 
281  slot->tts_values,
282  slot->tts_isnull);
283 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
Datum * tts_values
Definition: tuptable.h:126
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804

◆ tts_virtual_copy_minimal_tuple()

static MinimalTuple tts_virtual_copy_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 286 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

287 {
288  Assert(!TTS_EMPTY(slot));
289 
291  slot->tts_values,
292  slot->tts_isnull);
293 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
Datum * tts_values
Definition: tuptable.h:126
bool * tts_isnull
Definition: tuptable.h:128
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1356
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:804

◆ tts_virtual_copyslot()

static void tts_virtual_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 252 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

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

◆ tts_virtual_getsomeattrs()

static void tts_virtual_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 129 of file execTuples.c.

References elog, and ERROR.

Referenced by slot_deform_heap_tuple().

130 {
131  elog(ERROR, "getsomeattrs is not required to be called on a virtual tuple table slot");
132 }
#define ERROR
Definition: elog.h:46
#define elog(elevel,...)
Definition: elog.h:232

◆ tts_virtual_getsysattr()

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

Definition at line 140 of file execTuples.c.

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

Referenced by slot_deform_heap_tuple().

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 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ tts_virtual_init()

static void tts_virtual_init ( TupleTableSlot slot)
static

Definition at line 97 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

98 {
99 }

◆ tts_virtual_materialize()

static void tts_virtual_materialize ( TupleTableSlot slot)
static

Definition at line 159 of file execTuples.c.

References att_addlength_datum, att_align_nominal, VirtualTupleTableSlot::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 slot_deform_heap_tuple(), and tts_virtual_copyslot().

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);
189  sz += EOH_get_flat_size(DatumGetEOHP(val));
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 }
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:335
#define PointerGetDatum(X)
Definition: postgres.h:600
#define TTS_SHOULDFREE(slot)
Definition: tuptable.h:101
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define TTS_FLAG_SHOULDFREE
Definition: tuptable.h:100
MemoryContext tts_mcxt
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:126
uint16 tts_flags
Definition: tuptable.h:119
bool * tts_isnull
Definition: tuptable.h:128
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:203
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
Definition: expandeddatum.c:75
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:411
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
Definition: expandeddatum.c:81
size_t Size
Definition: c.h:540
#define DatumGetPointer(X)
Definition: postgres.h:593
#define att_addlength_datum(cur_offset, attlen, attdatum)
Definition: tupmacs.h:164
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
long val
Definition: informix.c:664

◆ tts_virtual_release()

static void tts_virtual_release ( TupleTableSlot slot)
static

Definition at line 102 of file execTuples.c.

Referenced by slot_deform_heap_tuple().

103 {
104 }

◆ TupleDescGetAttInMetadata()

AttInMetadata* TupleDescGetAttInMetadata ( TupleDesc  tupdesc)

Definition at line 2097 of file execTuples.c.

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_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_config(), pg_get_keywords(), pg_get_multixact_members(), pg_logdir_ls_internal(), pg_stats_ext_mcvlist_items(), pgp_armor_headers(), pgrowlocks(), pgstatindex_impl(), pltcl_build_tuple_result(), pltcl_func_handler(), pltcl_init_tuple_store(), postgresAcquireSampleRowsFunc(), postgresBeginDirectModify(), postgresBeginForeignScan(), prs_setup_firstcall(), show_all_settings(), storeRow(), ts_setup_firstcall(), tt_setup_firstcall(), and xpath_table().

2098 {
2099  int natts = tupdesc->natts;
2100  int i;
2101  Oid atttypeid;
2102  Oid attinfuncid;
2103  FmgrInfo *attinfuncinfo;
2104  Oid *attioparams;
2105  int32 *atttypmods;
2106  AttInMetadata *attinmeta;
2107 
2108  attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata));
2109 
2110  /* "Bless" the tupledesc so that we can make rowtype datums with it */
2111  attinmeta->tupdesc = BlessTupleDesc(tupdesc);
2112 
2113  /*
2114  * Gather info needed later to call the "in" function for each attribute
2115  */
2116  attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
2117  attioparams = (Oid *) palloc0(natts * sizeof(Oid));
2118  atttypmods = (int32 *) palloc0(natts * sizeof(int32));
2119 
2120  for (i = 0; i < natts; i++)
2121  {
2122  Form_pg_attribute att = TupleDescAttr(tupdesc, i);
2123 
2124  /* Ignore dropped attributes */
2125  if (!att->attisdropped)
2126  {
2127  atttypeid = att->atttypid;
2128  getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
2129  fmgr_info(attinfuncid, &attinfuncinfo[i]);
2130  atttypmods[i] = att->atttypmod;
2131  }
2132  }
2133  attinmeta->attinfuncs = attinfuncinfo;
2134  attinmeta->attioparams = attioparams;
2135  attinmeta->atttypmods = atttypmods;
2136 
2137  return attinmeta;
2138 }
Definition: fmgr.h:56
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
int32 * atttypmods
Definition: funcapi.h:47
unsigned int Oid
Definition: postgres_ext.h:31
Oid * attioparams
Definition: funcapi.h:44
signed int int32
Definition: c.h:429
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
TupleDesc tupdesc
Definition: funcapi.h:38
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:203
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2821
void * palloc0(Size size)
Definition: mcxt.c:1093
void * palloc(Size size)
Definition: mcxt.c:1062
int i
FmgrInfo * attinfuncs
Definition: funcapi.h:41

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:778
static HeapTuple tts_buffer_heap_get_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:820
static MinimalTuple tts_buffer_heap_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:846
static Datum tts_buffer_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:699
static HeapTuple tts_buffer_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:833
static void tts_buffer_heap_init(TupleTableSlot *slot)
Definition: execTuples.c:649
#define init()
struct BufferHeapTupleTableSlot BufferHeapTupleTableSlot
static void tts_buffer_heap_clear(TupleTableSlot *slot)
Definition: execTuples.c:659
static void tts_buffer_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:689
static void tts_buffer_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:719
static void tts_buffer_heap_release(TupleTableSlot *slot)
Definition: execTuples.c:654

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 void tts_heap_materialize(TupleTableSlot *slot)
Definition: execTuples.c:360
static void tts_heap_clear(TupleTableSlot *slot)
Definition: execTuples.c:311
static Datum tts_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:340
static HeapTuple tts_heap_get_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:413
struct HeapTupleTableSlot HeapTupleTableSlot
static void tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:400
#define init()
static void tts_heap_release(TupleTableSlot *slot)
Definition: execTuples.c:306
static MinimalTuple tts_heap_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:437
static void tts_heap_init(TupleTableSlot *slot)
Definition: execTuples.c:301
static void tts_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:330
static HeapTuple tts_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:425

Definition at line 84 of file execTuples.c.

Referenced by CatalogIndexInsert(), CheckOpSlotCompatibility(), compute_expr_stats(), compute_index_stats(), copyTemplateDependencies(), ExecInitForeignScan(), ExecInitSetOp(), ExecuteCallStmt(), heapam_index_validate_scan(), InsertPgAttributeTuples(), make_build_data(), 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 void tts_minimal_materialize(TupleTableSlot *slot)
Definition: execTuples.c:527
static void tts_minimal_getsomeattrs(TupleTableSlot *slot, int natts)
Definition: execTuples.c:505
static void tts_minimal_init(TupleTableSlot *slot)
Definition: execTuples.c:470
static HeapTuple tts_minimal_copy_heap_tuple(TupleTableSlot *slot)
Definition: execTuples.c:598
static MinimalTuple tts_minimal_get_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:587
static MinimalTuple tts_minimal_copy_minimal_tuple(TupleTableSlot *slot)
Definition: execTuples.c:609
#define init()
static Datum tts_minimal_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: execTuples.c:515
static void tts_minimal_release(TupleTableSlot *slot)
Definition: execTuples.c:482
struct MinimalTupleTableSlot MinimalTupleTableSlot
static void tts_minimal_clear(TupleTableSlot *slot)
Definition: execTuples.c:487
static void tts_minimal_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:574

Definition at line 85 of file execTuples.c.

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

◆ TTSOpsVirtual

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

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(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNestLoop(), ExecInitPartitionDispatchInfo(), ExecInitPartitionInfo(), ExecInitProjectSet(), ExecInitResult(), ExecInitResultCache(), ExecInitSort(), ExecInitSubPlan(), ExecInitValuesScan(), ExecInitWholeRowVar(), ExecInitWindowAgg(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), ExplainQuery(), GetAfterTriggersStoreSlot(), IdentifySystem(), InitPlan(), llvm_compile_expr(), RI_Initial_Check(), RI_PartitionRemove_Check(), ShowAllGUCConfig(), ShowGUCConfigOption(), slot_compile_deform(), StartReplication(), table_slot_callbacks(), and tstoreStartupReceiver().