PostgreSQL Source Code  git master
tuptable.h File Reference
#include "access/htup.h"
#include "access/sysattr.h"
#include "access/tupdesc.h"
#include "access/htup_details.h"
#include "storage/buf.h"
Include dependency graph for tuptable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TupleTableSlot
 
struct  TupleTableSlotOps
 
struct  VirtualTupleTableSlot
 
struct  HeapTupleTableSlot
 
struct  BufferHeapTupleTableSlot
 
struct  MinimalTupleTableSlot
 

Macros

#define TTS_FLAG_EMPTY   (1 << 1)
 
#define TTS_EMPTY(slot)   (((slot)->tts_flags & TTS_FLAG_EMPTY) != 0)
 
#define TTS_FLAG_SHOULDFREE   (1 << 2)
 
#define TTS_SHOULDFREE(slot)   (((slot)->tts_flags & TTS_FLAG_SHOULDFREE) != 0)
 
#define TTS_FLAG_SLOW   (1 << 3)
 
#define TTS_SLOW(slot)   (((slot)->tts_flags & TTS_FLAG_SLOW) != 0)
 
#define TTS_FLAG_FIXED   (1 << 4)
 
#define TTS_FIXED(slot)   (((slot)->tts_flags & TTS_FLAG_FIXED) != 0)
 
#define FIELDNO_TUPLETABLESLOT_FLAGS   1
 
#define FIELDNO_TUPLETABLESLOT_NVALID   2
 
#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR   4
 
#define FIELDNO_TUPLETABLESLOT_VALUES   5
 
#define FIELDNO_TUPLETABLESLOT_ISNULL   6
 
#define TTS_IS_VIRTUAL(slot)   ((slot)->tts_ops == &TTSOpsVirtual)
 
#define TTS_IS_HEAPTUPLE(slot)   ((slot)->tts_ops == &TTSOpsHeapTuple)
 
#define TTS_IS_MINIMALTUPLE(slot)   ((slot)->tts_ops == &TTSOpsMinimalTuple)
 
#define TTS_IS_BUFFERTUPLE(slot)   ((slot)->tts_ops == &TTSOpsBufferHeapTuple)
 
#define FIELDNO_HEAPTUPLETABLESLOT_TUPLE   1
 
#define FIELDNO_HEAPTUPLETABLESLOT_OFF   2
 
#define FIELDNO_MINIMALTUPLETABLESLOT_TUPLE   1
 
#define FIELDNO_MINIMALTUPLETABLESLOT_OFF   4
 
#define TupIsNull(slot)   ((slot) == NULL || TTS_EMPTY(slot))
 

Typedefs

typedef struct TupleTableSlotOps TupleTableSlotOps
 
typedef struct TupleTableSlot TupleTableSlot
 
typedef struct VirtualTupleTableSlot VirtualTupleTableSlot
 
typedef struct HeapTupleTableSlot HeapTupleTableSlot
 
typedef struct BufferHeapTupleTableSlot BufferHeapTupleTableSlot
 
typedef struct MinimalTupleTableSlot MinimalTupleTableSlot
 

Functions

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)
 
void ExecForceStoreHeapTuple (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 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 slot_getmissingattrs (TupleTableSlot *slot, int startAttNum, int lastAttNum)
 
void slot_getsomeattrs_int (TupleTableSlot *slot, int attnum)
 
static void slot_getsomeattrs (TupleTableSlot *slot, int attnum)
 
static void slot_getallattrs (TupleTableSlot *slot)
 
static bool slot_attisnull (TupleTableSlot *slot, int attnum)
 
static Datum slot_getattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static Datum slot_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static TupleTableSlotExecClearTuple (TupleTableSlot *slot)
 
static void ExecMaterializeSlot (TupleTableSlot *slot)
 
static HeapTuple ExecCopySlotHeapTuple (TupleTableSlot *slot)
 
static MinimalTuple ExecCopySlotMinimalTuple (TupleTableSlot *slot)
 
static TupleTableSlotExecCopySlot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 

Variables

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

Macro Definition Documentation

◆ FIELDNO_HEAPTUPLETABLESLOT_OFF

#define FIELDNO_HEAPTUPLETABLESLOT_OFF   2

Definition at line 251 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_HEAPTUPLETABLESLOT_TUPLE

#define FIELDNO_HEAPTUPLETABLESLOT_TUPLE   1

Definition at line 249 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_MINIMALTUPLETABLESLOT_OFF

#define FIELDNO_MINIMALTUPLETABLESLOT_OFF   4

Definition at line 286 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_MINIMALTUPLETABLESLOT_TUPLE

#define FIELDNO_MINIMALTUPLETABLESLOT_TUPLE   1

Definition at line 282 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_FLAGS

#define FIELDNO_TUPLETABLESLOT_FLAGS   1

Definition at line 118 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_ISNULL

#define FIELDNO_TUPLETABLESLOT_ISNULL   6

Definition at line 127 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_NVALID

#define FIELDNO_TUPLETABLESLOT_NVALID   2

Definition at line 120 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR

#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR   4

Definition at line 123 of file tuptable.h.

◆ FIELDNO_TUPLETABLESLOT_VALUES

#define FIELDNO_TUPLETABLESLOT_VALUES   5

Definition at line 125 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ TTS_EMPTY

◆ TTS_FIXED

#define TTS_FIXED (   slot)    (((slot)->tts_flags & TTS_FLAG_FIXED) != 0)

◆ TTS_FLAG_EMPTY

◆ TTS_FLAG_FIXED

#define TTS_FLAG_FIXED   (1 << 4)

Definition at line 108 of file tuptable.h.

Referenced by MakeTupleTableSlot().

◆ TTS_FLAG_SHOULDFREE

◆ TTS_FLAG_SLOW

#define TTS_FLAG_SLOW   (1 << 3)

Definition at line 104 of file tuptable.h.

Referenced by slot_compile_deform(), and slot_deform_heap_tuple().

◆ TTS_IS_BUFFERTUPLE

◆ TTS_IS_HEAPTUPLE

#define TTS_IS_HEAPTUPLE (   slot)    ((slot)->tts_ops == &TTSOpsHeapTuple)

Definition at line 229 of file tuptable.h.

Referenced by ExecForceStoreHeapTuple(), and ExecStoreHeapTuple().

◆ TTS_IS_MINIMALTUPLE

#define TTS_IS_MINIMALTUPLE (   slot)    ((slot)->tts_ops == &TTSOpsMinimalTuple)

Definition at line 230 of file tuptable.h.

Referenced by ExecForceStoreMinimalTuple(), and ExecStoreMinimalTuple().

◆ TTS_IS_VIRTUAL

#define TTS_IS_VIRTUAL (   slot)    ((slot)->tts_ops == &TTSOpsVirtual)

Definition at line 228 of file tuptable.h.

◆ TTS_SHOULDFREE

◆ TTS_SLOW

#define TTS_SLOW (   slot)    (((slot)->tts_flags & TTS_FLAG_SLOW) != 0)

Definition at line 105 of file tuptable.h.

Referenced by slot_deform_heap_tuple().

◆ TupIsNull

Typedef Documentation

◆ BufferHeapTupleTableSlot

◆ HeapTupleTableSlot

◆ MinimalTupleTableSlot

◆ TupleTableSlot

◆ TupleTableSlotOps

Definition at line 112 of file tuptable.h.

◆ VirtualTupleTableSlot

Function Documentation

◆ ExecAllocTableSlot()

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

Definition at line 1136 of file execTuples.c.

References lappend(), and MakeTupleTableSlot().

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

1138 {
1139  TupleTableSlot *slot = MakeTupleTableSlot(desc, tts_ops);
1140 
1141  *tupleTable = lappend(*tupleTable, slot);
1142 
1143  return slot;
1144 }
List * lappend(List *list, void *datum)
Definition: list.c:321
TupleTableSlot * MakeTupleTableSlot(TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1077

◆ ExecClearTuple()

static TupleTableSlot* ExecClearTuple ( TupleTableSlot slot)
inlinestatic

Definition at line 426 of file tuptable.h.

References TupleTableSlotOps::clear, and TupleTableSlot::tts_ops.

Referenced by AfterTriggerExecute(), agg_retrieve_hash_table(), apply_handle_update(), apply_returning_filter(), ATRewriteTable(), begin_partition(), BitmapHeapNext(), buildSubPlanHash(), CopyFrom(), CopyMultiInsertBufferFlush(), CteScanNext(), do_tup_output(), eval_windowaggregates(), EvalPlanQual(), ExecAppend(), ExecARUpdateTriggers(), ExecCheckTIDVisible(), ExecComputeStoredGenerated(), ExecDelete(), ExecDropSingleTupleTableSlot(), ExecEndAgg(), ExecEndBitmapHeapScan(), ExecEndCteScan(), ExecEndCustomScan(), ExecEndForeignScan(), ExecEndFunctionScan(), ExecEndGather(), ExecEndGatherMerge(), ExecEndGroup(), ExecEndHashJoin(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecEndMaterial(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNamedTuplestoreScan(), ExecEndNestLoop(), ExecEndProjectSet(), ExecEndResult(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndTableFuncScan(), ExecEndTidScan(), ExecEndUnique(), ExecEndValuesScan(), ExecEndWindowAgg(), ExecEndWorkTableScan(), ExecEvalAggOrderedTransTuple(), ExecFilterJunk(), ExecFindPartition(), ExecForceStoreHeapTuple(), ExecForceStoreMinimalTuple(), ExecHashJoinGetSavedTuple(), ExecHashSubPlan(), ExecLockRows(), ExecMaterial(), ExecMergeAppend(), ExecOnConflictUpdate(), ExecParallelHashJoinOuterGetTuple(), ExecProject(), ExecProjectSRF(), ExecReScanAgg(), ExecReScanCteScan(), ExecReScanFunctionScan(), ExecReScanGroup(), ExecReScanMaterial(), ExecReScanMergeJoin(), ExecReScanNamedTuplestoreScan(), ExecReScanSetOp(), ExecReScanSort(), ExecReScanTableFuncScan(), ExecReScanUnique(), ExecReScanValuesScan(), ExecReScanWindowAgg(), ExecReScanWorkTableScan(), ExecResetTupleTable(), ExecScan(), ExecScanFetch(), ExecScanReScan(), ExecSetSlotDescriptor(), ExecStoreAllNullTuple(), ExecStoreHeapTupleDatum(), ExecUnique(), execute_attr_map_slot(), ExecWindowAgg(), fetch_remote_table_info(), fetch_table_list(), fileIterateForeignScan(), FunctionNext(), gather_getnext(), gather_merge_clear_tuples(), gather_merge_init(), get_actual_variable_endpoint(), get_returning_data(), heap_getnextslot(), heapam_scan_analyze_next_tuple(), heapam_scan_sample_next_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), lookup_hash_entry(), ordered_set_shutdown(), ordered_set_transition_multi(), postgresIterateDirectModify(), postgresIterateForeignScan(), process_ordered_aggregate_multi(), RunFromStore(), setop_retrieve_direct(), setop_retrieve_hash_table(), ShutdownSetExpr(), slot_modify_cstrings(), slot_store_cstrings(), StoreIndexTuple(), tablesample_getnext(), tfuncLoadRows(), TidNext(), tts_buffer_heap_copyslot(), tuplesort_gettupleslot(), tuplestore_gettupleslot(), update_frameheadpos(), update_frametailpos(), update_grouptailpos(), ValuesNext(), and WinRowsArePeers().

427 {
428  slot->tts_ops->clear(slot);
429 
430  return slot;
431 }
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
void(* clear)(TupleTableSlot *slot)
Definition: tuptable.h:152

◆ ExecCopySlot()

static TupleTableSlot* ExecCopySlot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
inlinestatic

Definition at line 476 of file tuptable.h.

References Assert, TupleTableSlotOps::copyslot, TTS_EMPTY, and TupleTableSlot::tts_ops.

Referenced by apply_handle_update(), begin_partition(), CopyFrom(), CteScanNext(), EvalPlanQual(), ExecBRUpdateTriggers(), ExecGroup(), ExecMaterial(), ExecModifyTable(), ExecUnique(), ExecWindowAgg(), postgresRecheckForeignScan(), RelationFindReplTupleSeq(), spool_tuples(), update_frameheadpos(), and update_frametailpos().

477 {
478  Assert(!TTS_EMPTY(srcslot));
479 
480  dstslot->tts_ops->copyslot(dstslot, srcslot);
481 
482  return dstslot;
483 }
#define TTS_EMPTY(slot)
Definition: tuptable.h:97
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
#define Assert(condition)
Definition: c.h:732
void(* copyslot)(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:180

◆ ExecCopySlotHeapTuple()

static HeapTuple ExecCopySlotHeapTuple ( TupleTableSlot slot)
inlinestatic

Definition at line 453 of file tuptable.h.

References Assert, TupleTableSlotOps::copy_heap_tuple, TTS_EMPTY, and TupleTableSlot::tts_ops.

Referenced by acquire_sample_rows(), agg_retrieve_direct(), ExecScanSubPlan(), ExecSetParamPlan(), reorderqueue_push(), setop_retrieve_direct(), spi_printtup(), tts_buffer_heap_copyslot(), and tts_heap_copyslot().

454 {
455  Assert(!TTS_EMPTY(slot));
456 
457  return slot->tts_ops->copy_heap_tuple(slot);
458 }
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
#define Assert(condition)
Definition: c.h:732

◆ ExecCopySlotMinimalTuple()

static MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot slot)
inlinestatic

Definition at line 464 of file tuptable.h.

References TupleTableSlotOps::copy_minimal_tuple, and TupleTableSlot::tts_ops.

Referenced by copytup_heap(), LookupTupleHashEntry(), tts_minimal_copyslot(), and tuplestore_puttupleslot().

465 {
466  return slot->tts_ops->copy_minimal_tuple(slot);
467 }
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
MinimalTuple(* copy_minimal_tuple)(TupleTableSlot *slot)
Definition: tuptable.h:216

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 1219 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(), afterTriggerInvokeEvents(), AlterDomainNotNull(), ATRewriteTable(), CatalogIndexInsert(), check_default_partition_contents(), check_exclusion_or_unique_constraint(), compute_index_stats(), CopyMultiInsertBufferCleanup(), CopyTo(), DefineQueryRewrite(), end_tup_output(), ExecCleanupTupleRouting(), 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(), RelationFindReplTupleSeq(), RI_Initial_Check(), RunFromStore(), systable_endscan(), systable_endscan_ordered(), table_index_fetch_tuple_check(), tuplesort_end(), unique_key_recheck(), validateCheckConstraint(), validateDomainConstraint(), and validateForeignKeyConstraint().

1220 {
1221  /* This should match ExecResetTupleTable's processing of one slot */
1222  Assert(IsA(slot, TupleTableSlot));
1223  ExecClearTuple(slot);
1224  slot->tts_ops->release(slot);
1225  if (slot->tts_tupleDescriptor)
1227  if (!TTS_FIXED(slot))
1228  {
1229  if (slot->tts_values)
1230  pfree(slot->tts_values);
1231  if (slot->tts_isnull)
1232  pfree(slot->tts_isnull);
1233  }
1234  pfree(slot);
1235 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
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:1031
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:732
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122

◆ ExecFetchSlotHeapTuple()

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

Definition at line 1609 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(), 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(), tqueueReceiveSlot(), and validateForeignKeyConstraint().

1610 {
1611  /*
1612  * sanity checks
1613  */
1614  Assert(slot != NULL);
1615  Assert(!TTS_EMPTY(slot));
1616 
1617  /* Materialize the tuple so that the slot "owns" it, if requested. */
1618  if (materialize)
1619  slot->tts_ops->materialize(slot);
1620 
1621  if (slot->tts_ops->get_heap_tuple == NULL)
1622  {
1623  if (shouldFree)
1624  *shouldFree = true;
1625  return slot->tts_ops->copy_heap_tuple(slot);
1626  }
1627  else
1628  {
1629  if (shouldFree)
1630  *shouldFree = false;
1631  return slot->tts_ops->get_heap_tuple(slot);
1632  }
1633 }
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:732
void(* materialize)(TupleTableSlot *slot)
Definition: tuptable.h:174

◆ ExecFetchSlotHeapTupleDatum()

Datum ExecFetchSlotHeapTupleDatum ( TupleTableSlot slot)

Definition at line 1688 of file execTuples.c.

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

Referenced by ExecMakeFunctionResultSet(), and postquel_get_single_result().

1689 {
1690  HeapTuple tup;
1691  TupleDesc tupdesc;
1692  bool shouldFree;
1693  Datum ret;
1694 
1695  /* Fetch slot's contents in regular-physical-tuple form */
1696  tup = ExecFetchSlotHeapTuple(slot, false, &shouldFree);
1697  tupdesc = slot->tts_tupleDescriptor;
1698 
1699  /* Convert to Datum form */
1700  ret = heap_copy_tuple_as_datum(tup, tupdesc);
1701 
1702  if (shouldFree)
1703  pfree(tup);
1704 
1705  return ret;
1706 }
void pfree(void *pointer)
Definition: mcxt.c:1031
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
Definition: execTuples.c:1609
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:367

◆ ExecFetchSlotMinimalTuple()

MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot,
bool shouldFree 
)

Definition at line 1657 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(), and ExecParallelHashTableInsertCurrentBatch().

1659 {
1660  /*
1661  * sanity checks
1662  */
1663  Assert(slot != NULL);
1664  Assert(!TTS_EMPTY(slot));
1665 
1666  if (slot->tts_ops->get_minimal_tuple)
1667  {
1668  if (shouldFree)
1669  *shouldFree = false;
1670  return slot->tts_ops->get_minimal_tuple(slot);
1671  }
1672  else
1673  {
1674  if (shouldFree)
1675  *shouldFree = true;
1676  return slot->tts_ops->copy_minimal_tuple(slot);
1677  }
1678 }
#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:732

◆ ExecForceStoreHeapTuple()

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

Definition at line 1434 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(), IndexNextWithReorder(), IndexOnlyNext(), and store_returning_result().

1437 {
1438  if (TTS_IS_HEAPTUPLE(slot))
1439  {
1440  ExecStoreHeapTuple(tuple, slot, shouldFree);
1441  }
1442  else if (TTS_IS_BUFFERTUPLE(slot))
1443  {
1444  MemoryContext oldContext;
1446 
1447  ExecClearTuple(slot);
1448  slot->tts_flags |= TTS_FLAG_SHOULDFREE;
1449  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1450  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
1451  bslot->base.tuple = heap_copytuple(tuple);
1452  MemoryContextSwitchTo(oldContext);
1453 
1454  if (shouldFree)
1455  pfree(tuple);
1456  }
1457  else
1458  {
1459  ExecClearTuple(slot);
1461  slot->tts_values, slot->tts_isnull);
1462  ExecStoreVirtualTuple(slot);
1463 
1464  if (shouldFree)
1465  {
1466  ExecMaterializeSlot(slot);
1467  pfree(tuple);
1468  }
1469  }
1470 }
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:426
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:1031
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:444
#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:1317
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1517

◆ ExecForceStoreMinimalTuple()

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

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

1480 {
1481  if (TTS_IS_MINIMALTUPLE(slot))
1482  {
1483  tts_minimal_store_tuple(slot, mtup, shouldFree);
1484  }
1485  else
1486  {
1487  HeapTupleData htup;
1488 
1489  ExecClearTuple(slot);
1490 
1491  htup.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
1492  htup.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
1494  slot->tts_values, slot->tts_isnull);
1495  ExecStoreVirtualTuple(slot);
1496 
1497  if (shouldFree)
1498  {
1499  ExecMaterializeSlot(slot);
1500  pfree(mtup);
1501  }
1502  }
1503 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
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:1031
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:598
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:444
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:619
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1517

◆ ExecMaterializeSlot()

static void ExecMaterializeSlot ( TupleTableSlot slot)
inlinestatic

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 1156 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(), apply_handle_delete(), apply_handle_insert(), apply_handle_update(), CopyFrom(), EvalPlanQualEnd(), and ExecEndPlan().

1158 {
1159  ListCell *lc;
1160 
1161  foreach(lc, tupleTable)
1162  {
1164 
1165  /* Always release resources and reset the slot to empty */
1166  ExecClearTuple(slot);
1167  slot->tts_ops->release(slot);
1168  if (slot->tts_tupleDescriptor)
1169  {
1171  slot->tts_tupleDescriptor = NULL;
1172  }
1173 
1174  /* If shouldFree, release memory occupied by the slot itself */
1175  if (shouldFree)
1176  {
1177  if (!TTS_FIXED(slot))
1178  {
1179  if (slot->tts_values)
1180  pfree(slot->tts_values);
1181  if (slot->tts_isnull)
1182  pfree(slot->tts_isnull);
1183  }
1184  pfree(slot);
1185  }
1186  }
1187 
1188  /* If shouldFree, release the list structure */
1189  if (shouldFree)
1190  list_free(tupleTable);
1191 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
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:1031
#define lfirst_node(type, lc)
Definition: pg_list.h:193
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void list_free(List *list)
Definition: list.c:1373
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122

◆ ExecSetSlotDescriptor()

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

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

1256 {
1257  Assert(!TTS_FIXED(slot));
1258 
1259  /* For safety, make sure slot is empty before changing it */
1260  ExecClearTuple(slot);
1261 
1262  /*
1263  * Release any old descriptor. Also release old Datum/isnull arrays if
1264  * present (we don't bother to check if they could be re-used).
1265  */
1266  if (slot->tts_tupleDescriptor)
1268 
1269  if (slot->tts_values)
1270  pfree(slot->tts_values);
1271  if (slot->tts_isnull)
1272  pfree(slot->tts_isnull);
1273 
1274  /*
1275  * Install the new descriptor; if it's refcounted, bump its refcount.
1276  */
1277  slot->tts_tupleDescriptor = tupdesc;
1278  PinTupleDesc(tupdesc);
1279 
1280  /*
1281  * Allocate Datum/isnull arrays of the appropriate size. These must have
1282  * the same lifetime as the slot, so allocate in the slot's own context.
1283  */
1284  slot->tts_values = (Datum *)
1285  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
1286  slot->tts_isnull = (bool *)
1287  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(bool));
1288 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
MemoryContext tts_mcxt
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:126
void pfree(void *pointer)
Definition: mcxt.c:1031
bool * tts_isnull
Definition: tuptable.h:128
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:732
#define PinTupleDesc(tupdesc)
Definition: tupdesc.h:116
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122

◆ ExecStoreAllNullTuple()

TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 1541 of file execTuples.c.

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

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

1542 {
1543  /*
1544  * sanity checks
1545  */
1546  Assert(slot != NULL);
1547  Assert(slot->tts_tupleDescriptor != NULL);
1548 
1549  /* Clear any old contents */
1550  ExecClearTuple(slot);
1551 
1552  /*
1553  * Fill all the columns of the virtual tuple with nulls
1554  */
1555  MemSet(slot->tts_values, 0,
1556  slot->tts_tupleDescriptor->natts * sizeof(Datum));
1557  memset(slot->tts_isnull, true,
1558  slot->tts_tupleDescriptor->natts * sizeof(bool));
1559 
1560  return ExecStoreVirtualTuple(slot);
1561 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
#define MemSet(start, val, len)
Definition: c.h:955
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:367
#define Assert(condition)
Definition: c.h:732
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1517

◆ ExecStoreBufferHeapTuple()

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

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

1360 {
1361  /*
1362  * sanity checks
1363  */
1364  Assert(tuple != NULL);
1365  Assert(slot != NULL);
1366  Assert(slot->tts_tupleDescriptor != NULL);
1367  Assert(BufferIsValid(buffer));
1368 
1369  if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1370  elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1371  tts_buffer_heap_store_tuple(slot, tuple, buffer, false);
1372 
1373  slot->tts_tableOid = tuple->t_tableOid;
1374 
1375  return slot;
1376 }
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:824
#define ERROR
Definition: elog.h:43
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:732
#define BufferIsValid(bufnum)
Definition: bufmgr.h:113
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208

◆ ExecStoreHeapTuple()

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

Definition at line 1317 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_index_stats(), ExecForceStoreHeapTuple(), ExecuteCallStmt(), gather_getnext(), gather_merge_readnext(), get_returning_data(), heapam_index_validate_scan(), postgresIterateForeignScan(), setop_retrieve_direct(), and tts_heap_copyslot().

1320 {
1321  /*
1322  * sanity checks
1323  */
1324  Assert(tuple != NULL);
1325  Assert(slot != NULL);
1326  Assert(slot->tts_tupleDescriptor != NULL);
1327 
1328  if (unlikely(!TTS_IS_HEAPTUPLE(slot)))
1329  elog(ERROR, "trying to store a heap tuple into wrong type of slot");
1330  tts_heap_store_tuple(slot, tuple, shouldFree);
1331 
1332  slot->tts_tableOid = tuple->t_tableOid;
1333 
1334  return slot;
1335 }
Oid tts_tableOid
Definition: tuptable.h:131
#define ERROR
Definition: elog.h:43
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:732
#define elog(elevel,...)
Definition: elog.h:226
static void tts_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, bool shouldFree)
Definition: execTuples.c:431
#define unlikely(x)
Definition: c.h:208

◆ ExecStoreHeapTupleDatum()

void ExecStoreHeapTupleDatum ( Datum  data,
TupleTableSlot slot 
)

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

1572 {
1573  HeapTupleData tuple = {0};
1574  HeapTupleHeader td;
1575 
1576  td = DatumGetHeapTupleHeader(data);
1577 
1579  tuple.t_self = td->t_ctid;
1580  tuple.t_data = td;
1581 
1582  ExecClearTuple(slot);
1583 
1584  heap_deform_tuple(&tuple, slot->tts_tupleDescriptor,
1585  slot->tts_values, slot->tts_isnull);
1586  ExecStoreVirtualTuple(slot);
1587 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
Datum * tts_values
Definition: tuptable.h:126
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
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:1517
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ ExecStoreMinimalTuple()

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

Definition at line 1411 of file execTuples.c.

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

Referenced by agg_retrieve_hash_table(), ExecParallelScanHashBucket(), ExecScanHashBucket(), ExecScanHashTableForUnmatched(), findPartialMatch(), setop_retrieve_hash_table(), tts_minimal_copyslot(), TupleHashTableHash(), TupleHashTableMatch(), tuplesort_gettupleslot(), and tuplestore_gettupleslot().

1414 {
1415  /*
1416  * sanity checks
1417  */
1418  Assert(mtup != NULL);
1419  Assert(slot != NULL);
1420  Assert(slot->tts_tupleDescriptor != NULL);
1421 
1422  if (unlikely(!TTS_IS_MINIMALTUPLE(slot)))
1423  elog(ERROR, "trying to store a minimal tuple into wrong type of slot");
1424  tts_minimal_store_tuple(slot, mtup, shouldFree);
1425 
1426  return slot;
1427 }
#define TTS_IS_MINIMALTUPLE(slot)
Definition: tuptable.h:230
#define ERROR
Definition: elog.h:43
static void tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
Definition: execTuples.c:598
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
#define Assert(condition)
Definition: c.h:732
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208

◆ ExecStorePinnedBufferHeapTuple()

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

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

1386 {
1387  /*
1388  * sanity checks
1389  */
1390  Assert(tuple != NULL);
1391  Assert(slot != NULL);
1392  Assert(slot->tts_tupleDescriptor != NULL);
1393  Assert(BufferIsValid(buffer));
1394 
1395  if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1396  elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1397  tts_buffer_heap_store_tuple(slot, tuple, buffer, true);
1398 
1399  slot->tts_tableOid = tuple->t_tableOid;
1400 
1401  return slot;
1402 }
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:824
#define ERROR
Definition: elog.h:43
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:732
#define BufferIsValid(bufnum)
Definition: bufmgr.h:113
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208

◆ ExecStoreVirtualTuple()

TupleTableSlot* ExecStoreVirtualTuple ( TupleTableSlot slot)

Definition at line 1517 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(), apply_returning_filter(), ATRewriteTable(), CopyFrom(), do_tup_output(), ExecComputeStoredGenerated(), ExecEvalAggOrderedTransTuple(), ExecFilterJunk(), ExecForceStoreHeapTuple(), ExecForceStoreMinimalTuple(), ExecProjectSRF(), ExecStoreAllNullTuple(), ExecStoreHeapTupleDatum(), execute_attr_map_slot(), fileIterateForeignScan(), FunctionNext(), hypothetical_dense_rank_final(), hypothetical_rank_common(), lookup_hash_entry(), ordered_set_transition_multi(), RI_Initial_Check(), RI_PartitionRemove_Check(), slot_modify_cstrings(), slot_store_cstrings(), StoreIndexTuple(), and ValuesNext().

1518 {
1519  /*
1520  * sanity checks
1521  */
1522  Assert(slot != NULL);
1523  Assert(slot->tts_tupleDescriptor != NULL);
1524  Assert(TTS_EMPTY(slot));
1525 
1526  slot->tts_flags &= ~TTS_FLAG_EMPTY;
1527  slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
1528 
1529  return slot;
1530 }
#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:732
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

TupleTableSlot* MakeTupleTableSlot ( TupleDesc  tupleDesc,
const TupleTableSlotOps tts_ops 
)

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

1079 {
1080  Size basesz,
1081  allocsz;
1082  TupleTableSlot *slot;
1083 
1084  basesz = tts_ops->base_slot_size;
1085 
1086  /*
1087  * When a fixed descriptor is specified, we can reduce overhead by
1088  * allocating the entire slot in one go.
1089  */
1090  if (tupleDesc)
1091  allocsz = MAXALIGN(basesz) +
1092  MAXALIGN(tupleDesc->natts * sizeof(Datum)) +
1093  MAXALIGN(tupleDesc->natts * sizeof(bool));
1094  else
1095  allocsz = basesz;
1096 
1097  slot = palloc0(allocsz);
1098  /* const for optimization purposes, OK to modify at allocation time */
1099  *((const TupleTableSlotOps **) &slot->tts_ops) = tts_ops;
1100  slot->type = T_TupleTableSlot;
1101  slot->tts_flags |= TTS_FLAG_EMPTY;
1102  if (tupleDesc != NULL)
1103  slot->tts_flags |= TTS_FLAG_FIXED;
1104  slot->tts_tupleDescriptor = tupleDesc;
1106  slot->tts_nvalid = 0;
1107 
1108  if (tupleDesc != NULL)
1109  {
1110  slot->tts_values = (Datum *)
1111  (((char *) slot)
1112  + MAXALIGN(basesz));
1113  slot->tts_isnull = (bool *)
1114  (((char *) slot)
1115  + MAXALIGN(basesz)
1116  + MAXALIGN(tupleDesc->natts * sizeof(Datum)));
1117 
1118  PinTupleDesc(tupleDesc);
1119  }
1120 
1121  /*
1122  * And allow slot type specific initialization.
1123  */
1124  slot->tts_ops->init(slot);
1125 
1126  return slot;
1127 }
#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:38
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void * palloc0(Size size)
Definition: mcxt.c:955
uintptr_t Datum
Definition: postgres.h:367
#define TTS_FLAG_FIXED
Definition: tuptable.h:108
size_t Size
Definition: c.h:466
#define MAXALIGN(LEN)
Definition: c.h:685
#define PinTupleDesc(tupdesc)
Definition: tupdesc.h:116
AttrNumber tts_nvalid
Definition: tuptable.h:121
size_t base_slot_size
Definition: tuptable.h:138

◆ slot_attisnull()

static bool slot_attisnull ( TupleTableSlot slot,
int  attnum 
)
inlinestatic

Definition at line 368 of file tuptable.h.

References AssertArg, slot_getsomeattrs(), TupleTableSlot::tts_isnull, and TupleTableSlot::tts_nvalid.

Referenced by AlterDomainNotNull(), ATRewriteTable(), ExecConstraints(), ri_NullCheck(), slotAllNulls(), and slotNoNulls().

369 {
370  AssertArg(attnum > 0);
371 
372  if (attnum > slot->tts_nvalid)
373  slot_getsomeattrs(slot, attnum);
374 
375  return slot->tts_isnull[attnum - 1];
376 }
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition: tuptable.h:342
bool * tts_isnull
Definition: tuptable.h:128
#define AssertArg(condition)
Definition: c.h:734
int16 attnum
Definition: pg_attribute.h:79
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ slot_getallattrs()

◆ slot_getattr()

static Datum slot_getattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)
inlinestatic

Definition at line 382 of file tuptable.h.

References AssertArg, slot_getsomeattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, and TupleTableSlot::tts_values.

Referenced by buildSubPlanHash(), convert_prep_stmt_params(), debugtup(), ExecGetJunkAttribute(), ExecJustAssignInnerVar(), ExecJustAssignOuterVar(), ExecJustAssignScanVar(), ExecJustInnerVar(), ExecJustOuterVar(), ExecJustScanVar(), ExecMakeFunctionResultSet(), ExecNestLoop(), ExecScanSubPlan(), ExecSetParamPlan(), execTuplesUnequal(), fetch_remote_table_info(), fetch_table_list(), fetch_tuple_flag(), FormIndexDatum(), FormPartitionKeyDatum(), heap_compare_slots(), hypothetical_dense_rank_final(), hypothetical_rank_common(), postquel_get_single_result(), ri_ExtractValues(), ri_KeysEqual(), ri_ReportViolation(), TupleHashTableHash(), update_frameheadpos(), update_frametailpos(), and validateDomainConstraint().

384 {
385  AssertArg(attnum > 0);
386 
387  if (attnum > slot->tts_nvalid)
388  slot_getsomeattrs(slot, attnum);
389 
390  *isnull = slot->tts_isnull[attnum - 1];
391 
392  return slot->tts_values[attnum - 1];
393 }
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition: tuptable.h:342
Datum * tts_values
Definition: tuptable.h:126
bool * tts_isnull
Definition: tuptable.h:128
#define AssertArg(condition)
Definition: c.h:734
int16 attnum
Definition: pg_attribute.h:79
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ slot_getmissingattrs()

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

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

1834 {
1835  AttrMissing *attrmiss = NULL;
1836 
1837  if (slot->tts_tupleDescriptor->constr)
1838  attrmiss = slot->tts_tupleDescriptor->constr->missing;
1839 
1840  if (!attrmiss)
1841  {
1842  /* no missing values array at all, so just fill everything in as NULL */
1843  memset(slot->tts_values + startAttNum, 0,
1844  (lastAttNum - startAttNum) * sizeof(Datum));
1845  memset(slot->tts_isnull + startAttNum, 1,
1846  (lastAttNum - startAttNum) * sizeof(bool));
1847  }
1848  else
1849  {
1850  int missattnum;
1851 
1852  /* if there is a missing values array we must process them one by one */
1853  for (missattnum = startAttNum;
1854  missattnum < lastAttNum;
1855  missattnum++)
1856  {
1857  slot->tts_values[missattnum] = attrmiss[missattnum].am_value;
1858  slot->tts_isnull[missattnum] = !attrmiss[missattnum].am_present;
1859  }
1860 
1861  }
1862 }
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:367
struct AttrMissing * missing
Definition: tupdesc.h:41

◆ slot_getsomeattrs()

static void slot_getsomeattrs ( TupleTableSlot slot,
int  attnum 
)
inlinestatic

Definition at line 342 of file tuptable.h.

References slot_getsomeattrs_int(), and TupleTableSlot::tts_nvalid.

Referenced by ExecInterpExpr(), lookup_hash_entry(), prepare_projection_slot(), process_ordered_aggregate_multi(), slot_attisnull(), slot_getallattrs(), and slot_getattr().

343 {
344  if (slot->tts_nvalid < attnum)
346 }
int16 attnum
Definition: pg_attribute.h:79
void slot_getsomeattrs_int(TupleTableSlot *slot, int attnum)
Definition: execTuples.c:1868
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ slot_getsomeattrs_int()

void slot_getsomeattrs_int ( TupleTableSlot slot,
int  attnum 
)

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

1869 {
1870  /* Check for caller errors */
1871  Assert(slot->tts_nvalid < attnum); /* checked in slot_getsomeattrs */
1872  Assert(attnum > 0);
1873 
1874  if (unlikely(attnum > slot->tts_tupleDescriptor->natts))
1875  elog(ERROR, "invalid attribute number %d", attnum);
1876 
1877  /* Fetch as many attributes as possible from the underlying tuple. */
1878  slot->tts_ops->getsomeattrs(slot, attnum);
1879 
1880  /*
1881  * If the underlying tuple doesn't have enough attributes, tuple
1882  * descriptor must have the missing attributes.
1883  */
1884  if (unlikely(slot->tts_nvalid < attnum))
1885  {
1886  slot_getmissingattrs(slot, slot->tts_nvalid, attnum);
1887  slot->tts_nvalid = attnum;
1888  }
1889 }
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
#define ERROR
Definition: elog.h:43
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:732
void(* getsomeattrs)(TupleTableSlot *slot, int natts)
Definition: tuptable.h:161
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
Definition: execTuples.c:1833
#define elog(elevel,...)
Definition: elog.h:226
#define unlikely(x)
Definition: c.h:208
AttrNumber tts_nvalid
Definition: tuptable.h:121

◆ slot_getsysattr()

static Datum slot_getsysattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)
inlinestatic

Definition at line 403 of file tuptable.h.

References AssertArg, TupleTableSlotOps::getsysattr, ObjectIdGetDatum, PointerGetDatum, SelfItemPointerAttributeNumber, TableOidAttributeNumber, TupleTableSlot::tts_ops, TupleTableSlot::tts_tableOid, and TupleTableSlot::tts_tid.

Referenced by ExecCheckTupleVisible(), execCurrentOf(), ExecEvalSysVar(), ExecOnConflictUpdate(), FormIndexDatum(), and RI_FKey_fk_upd_check_required().

404 {
405  AssertArg(attnum < 0); /* caller error */
406 
408  {
409  *isnull = false;
410  return ObjectIdGetDatum(slot->tts_tableOid);
411  }
413  {
414  *isnull = false;
415  return PointerGetDatum(&slot->tts_tid);
416  }
417 
418  /* Fetch the system attribute from the underlying tuple. */
419  return slot->tts_ops->getsysattr(slot, attnum, isnull);
420 }
Oid tts_tableOid
Definition: tuptable.h:131
Datum(* getsysattr)(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:168
#define PointerGetDatum(X)
Definition: postgres.h:556
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define TableOidAttributeNumber
Definition: sysattr.h:26
#define AssertArg(condition)
Definition: c.h:734
int16 attnum
Definition: pg_attribute.h:79
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
ItemPointerData tts_tid
Definition: tuptable.h:130

Variable Documentation

◆ TTSOpsBufferHeapTuple

PGDLLIMPORT const TupleTableSlotOps TTSOpsBufferHeapTuple

◆ TTSOpsHeapTuple

◆ TTSOpsMinimalTuple

◆ TTSOpsVirtual