PostgreSQL Source Code  git master
tuptable.h File Reference
#include "access/htup.h"
#include "access/tupdesc.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
 

Macros

#define FIELDNO_TUPLETABLESLOT_SLOW   4
 
#define FIELDNO_TUPLETABLESLOT_TUPLE   5
 
#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR   6
 
#define FIELDNO_TUPLETABLESLOT_NVALID   9
 
#define FIELDNO_TUPLETABLESLOT_VALUES   10
 
#define FIELDNO_TUPLETABLESLOT_ISNULL   11
 
#define FIELDNO_TUPLETABLESLOT_OFF   14
 
#define TTS_HAS_PHYSICAL_TUPLE(slot)   ((slot)->tts_tuple != NULL && (slot)->tts_tuple != &((slot)->tts_minhdr))
 
#define TupIsNull(slot)   ((slot) == NULL || (slot)->tts_isempty)
 

Typedefs

typedef struct TupleTableSlot TupleTableSlot
 

Functions

TupleTableSlotMakeTupleTableSlot (TupleDesc desc)
 
TupleTableSlotExecAllocTableSlot (List **tupleTable, TupleDesc desc)
 
void ExecResetTupleTable (List *tupleTable, bool shouldFree)
 
TupleTableSlotMakeSingleTupleTableSlot (TupleDesc tupdesc)
 
void ExecDropSingleTupleTableSlot (TupleTableSlot *slot)
 
void ExecSetSlotDescriptor (TupleTableSlot *slot, TupleDesc tupdesc)
 
TupleTableSlotExecStoreTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
 
TupleTableSlotExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecClearTuple (TupleTableSlot *slot)
 
TupleTableSlotExecStoreVirtualTuple (TupleTableSlot *slot)
 
TupleTableSlotExecStoreAllNullTuple (TupleTableSlot *slot)
 
HeapTuple ExecCopySlotTuple (TupleTableSlot *slot)
 
MinimalTuple ExecCopySlotMinimalTuple (TupleTableSlot *slot)
 
HeapTuple ExecFetchSlotTuple (TupleTableSlot *slot)
 
MinimalTuple ExecFetchSlotMinimalTuple (TupleTableSlot *slot)
 
Datum ExecFetchSlotTupleDatum (TupleTableSlot *slot)
 
HeapTuple ExecMaterializeSlot (TupleTableSlot *slot)
 
TupleTableSlotExecCopySlot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
Datum slot_getattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
void slot_getallattrs (TupleTableSlot *slot)
 
void slot_getsomeattrs (TupleTableSlot *slot, int attnum)
 
bool slot_attisnull (TupleTableSlot *slot, int attnum)
 
bool slot_getsysattr (TupleTableSlot *slot, int attnum, Datum *value, bool *isnull)
 
void slot_getmissingattrs (TupleTableSlot *slot, int startAttNum, int lastAttNum)
 

Macro Definition Documentation

◆ FIELDNO_TUPLETABLESLOT_ISNULL

#define FIELDNO_TUPLETABLESLOT_ISNULL   11

Definition at line 131 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_NVALID

#define FIELDNO_TUPLETABLESLOT_NVALID   9

Definition at line 127 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_OFF

#define FIELDNO_TUPLETABLESLOT_OFF   14

Definition at line 135 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_SLOW

#define FIELDNO_TUPLETABLESLOT_SLOW   4

Definition at line 119 of file tuptable.h.

Referenced by slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_TUPLE

#define FIELDNO_TUPLETABLESLOT_TUPLE   5

Definition at line 121 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR

#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR   6

Definition at line 123 of file tuptable.h.

Referenced by llvm_compile_expr().

◆ FIELDNO_TUPLETABLESLOT_VALUES

#define FIELDNO_TUPLETABLESLOT_VALUES   10

Definition at line 129 of file tuptable.h.

Referenced by llvm_compile_expr(), and slot_compile_deform().

◆ TTS_HAS_PHYSICAL_TUPLE

#define TTS_HAS_PHYSICAL_TUPLE (   slot)    ((slot)->tts_tuple != NULL && (slot)->tts_tuple != &((slot)->tts_minhdr))

Definition at line 140 of file tuptable.h.

Referenced by ExecCopySlotTuple(), and ExecFetchSlotTuple().

◆ TupIsNull

Typedef Documentation

◆ TupleTableSlot

Function Documentation

◆ ExecAllocTableSlot()

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

Definition at line 167 of file execTuples.c.

References lappend(), and MakeTupleTableSlot().

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

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

◆ ExecClearTuple()

TupleTableSlot* ExecClearTuple ( TupleTableSlot slot)

Definition at line 475 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), InvalidBuffer, ReleaseBuffer(), TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, and TupleTableSlot::tts_tuple.

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

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

◆ ExecCopySlot()

TupleTableSlot* ExecCopySlot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)

Definition at line 851 of file execTuples.c.

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

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

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

◆ ExecCopySlotMinimalTuple()

MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot slot)

Definition at line 613 of file execTuples.c.

References Assert, heap_copy_minimal_tuple(), heap_form_minimal_tuple(), HeapTupleHeaderGetNatts, minimal_expand_tuple(), minimal_tuple_from_heap_tuple(), tupleDesc::natts, HeapTupleData::t_data, TupleTableSlot::tts_isempty, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

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

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

◆ ExecCopySlotTuple()

HeapTuple ExecCopySlotTuple ( TupleTableSlot slot)

Definition at line 581 of file execTuples.c.

References Assert, heap_copytuple(), heap_form_tuple(), heap_tuple_from_minimal_tuple(), TTS_HAS_PHYSICAL_TUPLE, TupleTableSlot::tts_isempty, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by agg_retrieve_direct(), ExecCopySlot(), ExecMaterializeSlot(), ExecScanSubPlan(), ExecSetParamPlan(), setop_retrieve_direct(), and spi_printtup().

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

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 247 of file execTuples.c.

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

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

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

◆ ExecFetchSlotMinimalTuple()

MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot)

Definition at line 708 of file execTuples.c.

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

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

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

◆ ExecFetchSlotTuple()

HeapTuple ExecFetchSlotTuple ( TupleTableSlot slot)

Definition at line 661 of file execTuples.c.

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

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

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

◆ ExecFetchSlotTupleDatum()

Datum ExecFetchSlotTupleDatum ( TupleTableSlot slot)

Definition at line 754 of file execTuples.c.

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

Referenced by ExecMakeFunctionResultSet(), and postquel_get_single_result().

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

◆ ExecMaterializeSlot()

HeapTuple ExecMaterializeSlot ( TupleTableSlot slot)

Definition at line 781 of file execTuples.c.

References Assert, BufferIsValid, ExecCopySlotTuple(), InvalidBuffer, MemoryContextSwitchTo(), ReleaseBuffer(), TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, and TupleTableSlot::tts_tuple.

Referenced by AfterTriggerExecute(), apply_returning_filter(), CopyFrom(), EvalPlanQual(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecFetchSlotTuple(), ExecInsert(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecPrepareTupleRouting(), ExecProcessReturning(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), ExecUpdate(), ForeignNext(), intorel_receive(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), tqueueReceiveSlot(), and transientrel_receive().

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

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 186 of file execTuples.c.

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

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

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

◆ ExecSetSlotDescriptor()

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 281 of file execTuples.c.

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

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

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

◆ ExecStoreAllNullTuple()

TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 548 of file execTuples.c.

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

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

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

◆ ExecStoreMinimalTuple()

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

Definition at line 420 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), InvalidBuffer, MINIMAL_TUPLE_OFFSET, ReleaseBuffer(), HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_minhdr, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

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

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

◆ ExecStoreTuple()

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

Definition at line 356 of file execTuples.c.

References Assert, buffer, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), IncrBufferRefCount(), ReleaseBuffer(), TupleTableSlot::tts_buffer, TupleTableSlot::tts_isempty, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by agg_retrieve_direct(), apply_handle_update(), ATRewriteTable(), BitmapHeapNext(), CatalogIndexInsert(), check_default_allows_bound(), check_exclusion_or_unique_constraint(), comparetup_cluster(), compute_index_stats(), ConvertPartitionTupleSlot(), CopyFrom(), CopyFromInsertBatch(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecConstraints(), ExecCopySlot(), ExecDelete(), ExecFetchSlotTuple(), ExecFindPartition(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecOnConflictUpdate(), ExecPartitionCheckEmitError(), ExecScanFetch(), ExecuteCallStmt(), ExecWithCheckOptions(), gather_getnext(), gather_merge_readnext(), get_actual_variable_range(), get_returning_data(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), postgresIterateForeignScan(), ProjIndexIsUnchanged(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), SampleNext(), SeqNext(), setop_retrieve_direct(), store_returning_result(), TidNext(), TriggerEnabled(), unique_key_recheck(), validate_index_heapscan(), and validateCheckConstraint().

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

◆ ExecStoreVirtualTuple()

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

TupleTableSlot* MakeTupleTableSlot ( TupleDesc  desc)

Definition at line 113 of file execTuples.c.

References CurrentMemoryContext, InvalidBuffer, MAXALIGN, tupleDesc::natts, palloc0(), PinTupleDesc, T_TupleTableSlot, TupleTableSlot::tts_buffer, TupleTableSlot::tts_fixedTupleDescriptor, TupleTableSlot::tts_isempty, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_mintuple, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_shouldFree, TupleTableSlot::tts_shouldFreeMin, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and TupleTableSlot::type.

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

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

◆ slot_attisnull()

bool slot_attisnull ( TupleTableSlot slot,
int  attnum 
)

Definition at line 1703 of file heaptuple.c.

References elog, ERROR, heap_attisnull(), tupleDesc::natts, TupleTableSlot::tts_isnull, TupleTableSlot::tts_minhdr, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecConstraints(), slotAllNulls(), and slotNoNulls().

1704 {
1705  HeapTuple tuple = slot->tts_tuple;
1707 
1708  /*
1709  * system attributes are handled by heap_attisnull
1710  */
1711  if (attnum <= 0)
1712  {
1713  if (tuple == NULL) /* internal error */
1714  elog(ERROR, "cannot extract system attribute from virtual tuple");
1715  if (tuple == &(slot->tts_minhdr)) /* internal error */
1716  elog(ERROR, "cannot extract system attribute from minimal tuple");
1717  return heap_attisnull(tuple, attnum, tupleDesc);
1718  }
1719 
1720  /*
1721  * fast path if desired attribute already cached
1722  */
1723  if (attnum <= slot->tts_nvalid)
1724  return slot->tts_isnull[attnum - 1];
1725 
1726  /*
1727  * return NULL if attnum is out of range according to the tupdesc
1728  */
1729  if (attnum > tupleDesc->natts)
1730  return true;
1731 
1732  /*
1733  * otherwise we had better have a physical tuple (tts_nvalid should equal
1734  * natts in all virtual-tuple cases)
1735  */
1736  if (tuple == NULL) /* internal error */
1737  elog(ERROR, "cannot extract attribute from empty tuple slot");
1738 
1739  /* and let the tuple tell it */
1740  return heap_attisnull(tuple, attnum, tupleDesc);
1741 }
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:397
int natts
Definition: tupdesc.h:82
#define ERROR
Definition: elog.h:43
HeapTupleData tts_minhdr
Definition: tuptable.h:134
bool * tts_isnull
Definition: tuptable.h:132
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
int16 attnum
Definition: pg_attribute.h:79
HeapTuple tts_tuple
Definition: tuptable.h:122
#define elog
Definition: elog.h:219

◆ slot_getallattrs()

void slot_getallattrs ( TupleTableSlot slot)

Definition at line 1612 of file heaptuple.c.

References attnum, elog, ERROR, HeapTupleHeaderGetNatts, Min, tupleDesc::natts, slot_deform_tuple(), slot_getmissingattrs(), HeapTupleData::t_data, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by agg_retrieve_hash_table(), apply_returning_filter(), copy_dest_receive(), ExecBuildSlotValueDescription(), ExecEvalWholeRowVar(), ExecFilterJunk(), FunctionNext(), printsimple(), printtup(), printtup_20(), printtup_internal_20(), slot_modify_cstrings(), and tstoreReceiveSlot_detoast().

1613 {
1614  int tdesc_natts = slot->tts_tupleDescriptor->natts;
1615  int attnum;
1616  HeapTuple tuple;
1617 
1618  /* Quick out if we have 'em all already */
1619  if (slot->tts_nvalid == tdesc_natts)
1620  return;
1621 
1622  /*
1623  * otherwise we had better have a physical tuple (tts_nvalid should equal
1624  * natts in all virtual-tuple cases)
1625  */
1626  tuple = slot->tts_tuple;
1627  if (tuple == NULL) /* internal error */
1628  elog(ERROR, "cannot extract attribute from empty tuple slot");
1629 
1630  /*
1631  * load up any slots available from physical tuple
1632  */
1633  attnum = HeapTupleHeaderGetNatts(tuple->t_data);
1634  attnum = Min(attnum, tdesc_natts);
1635 
1636  slot_deform_tuple(slot, attnum);
1637 
1638  attnum = slot->tts_nvalid;
1639 
1640  /*
1641  * If tuple doesn't have all the atts indicated by tupleDesc, read the
1642  * rest as NULLS or missing values.
1643  */
1644  if (attnum < tdesc_natts)
1645  slot_getmissingattrs(slot, attnum, tdesc_natts);
1646 
1647  slot->tts_nvalid = tdesc_natts;
1648 }
#define Min(x, y)
Definition: c.h:857
int natts
Definition: tupdesc.h:82
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:43
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:544
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
Definition: heaptuple.c:122
int16 attnum
Definition: pg_attribute.h:79
HeapTuple tts_tuple
Definition: tuptable.h:122
#define elog
Definition: elog.h:219
static void slot_deform_tuple(TupleTableSlot *slot, int natts)
Definition: heaptuple.c:1412

◆ slot_getattr()

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

Definition at line 1518 of file heaptuple.c.

References att_isnull, elog, ERROR, getmissingattr(), heap_getsysattr(), HeapTupleHasNulls, HeapTupleHeaderGetNatts, tupleDesc::natts, slot_deform_tuple(), HeapTupleHeaderData::t_bits, HeapTupleData::t_data, TupleTableSlot::tts_isnull, TupleTableSlot::tts_minhdr, TupleTableSlot::tts_tuple, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and TupleDescAttr.

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(), TupleHashTableHash(), update_frameheadpos(), and update_frametailpos().

1519 {
1520  HeapTuple tuple = slot->tts_tuple;
1522  HeapTupleHeader tup;
1523 
1524  /*
1525  * system attributes are handled by heap_getsysattr
1526  */
1527  if (attnum <= 0)
1528  {
1529  if (tuple == NULL) /* internal error */
1530  elog(ERROR, "cannot extract system attribute from virtual tuple");
1531  if (tuple == &(slot->tts_minhdr)) /* internal error */
1532  elog(ERROR, "cannot extract system attribute from minimal tuple");
1533  return heap_getsysattr(tuple, attnum, tupleDesc, isnull);
1534  }
1535 
1536  /*
1537  * fast path if desired attribute already cached
1538  */
1539  if (attnum <= slot->tts_nvalid)
1540  {
1541  *isnull = slot->tts_isnull[attnum - 1];
1542  return slot->tts_values[attnum - 1];
1543  }
1544 
1545  /*
1546  * return NULL if attnum is out of range according to the tupdesc
1547  */
1548  if (attnum > tupleDesc->natts)
1549  {
1550  *isnull = true;
1551  return (Datum) 0;
1552  }
1553 
1554  /*
1555  * otherwise we had better have a physical tuple (tts_nvalid should equal
1556  * natts in all virtual-tuple cases)
1557  */
1558  if (tuple == NULL) /* internal error */
1559  elog(ERROR, "cannot extract attribute from empty tuple slot");
1560 
1561  /*
1562  * return NULL or missing value if attnum is out of range according to the
1563  * tuple
1564  *
1565  * (We have to check this separately because of various inheritance and
1566  * table-alteration scenarios: the tuple could be either longer or shorter
1567  * than the tupdesc.)
1568  */
1569  tup = tuple->t_data;
1570  if (attnum > HeapTupleHeaderGetNatts(tup))
1571  return getmissingattr(slot->tts_tupleDescriptor, attnum, isnull);
1572 
1573  /*
1574  * check if target attribute is null: no point in groveling through tuple
1575  */
1576  if (HeapTupleHasNulls(tuple) && att_isnull(attnum - 1, tup->t_bits))
1577  {
1578  *isnull = true;
1579  return (Datum) 0;
1580  }
1581 
1582  /*
1583  * If the attribute's column has been dropped, we force a NULL result.
1584  * This case should not happen in normal use, but it could happen if we
1585  * are executing a plan cached before the column was dropped.
1586  */
1587  if (TupleDescAttr(tupleDesc, attnum - 1)->attisdropped)
1588  {
1589  *isnull = true;
1590  return (Datum) 0;
1591  }
1592 
1593  /*
1594  * Extract the attribute, along with any preceding attributes.
1595  */
1596  slot_deform_tuple(slot, attnum);
1597 
1598  /*
1599  * The result is acquired from tts_values array.
1600  */
1601  *isnull = slot->tts_isnull[attnum - 1];
1602  return slot->tts_values[attnum - 1];
1603 }
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]
Definition: htup_details.h:176
#define att_isnull(ATT, BITS)
Definition: tupmacs.h:21
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
Datum * tts_values
Definition: tuptable.h:130
int natts
Definition: tupdesc.h:82
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:43
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: heaptuple.c:666
HeapTupleData tts_minhdr
Definition: tuptable.h:134
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:544
#define HeapTupleHasNulls(tuple)
Definition: htup_details.h:674
bool * tts_isnull
Definition: tuptable.h:132
static Datum getmissingattr(TupleDesc tupleDesc, int attnum, bool *isnull)
Definition: heaptuple.c:84
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
int16 attnum
Definition: pg_attribute.h:79
HeapTuple tts_tuple
Definition: tuptable.h:122
#define elog
Definition: elog.h:219
static void slot_deform_tuple(TupleTableSlot *slot, int natts)
Definition: heaptuple.c:1412

◆ slot_getmissingattrs()

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

Definition at line 122 of file heaptuple.c.

References attrMissing::ammissing, attrMissing::ammissingPresent, tupleDesc::constr, tupleConstr::missing, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by slot_getallattrs(), and slot_getsomeattrs().

123 {
124  AttrMissing *attrmiss = NULL;
125  int missattnum;
126 
127  if (slot->tts_tupleDescriptor->constr)
128  attrmiss = slot->tts_tupleDescriptor->constr->missing;
129 
130  if (!attrmiss)
131  {
132  /* no missing values array at all, so just fill everything in as NULL */
133  memset(slot->tts_values + startAttNum, 0,
134  (lastAttNum - startAttNum) * sizeof(Datum));
135  memset(slot->tts_isnull + startAttNum, 1,
136  (lastAttNum - startAttNum) * sizeof(bool));
137  }
138  else
139  {
140  /* if there is a missing values array we must process them one by one */
141  for (missattnum = startAttNum;
142  missattnum < lastAttNum;
143  missattnum++)
144  {
145  slot->tts_values[missattnum] = attrmiss[missattnum].ammissing;
146  slot->tts_isnull[missattnum] =
147  !attrmiss[missattnum].ammissingPresent;
148  }
149  }
150 }
MissingPtr missing
Definition: tupdesc.h:43
Datum * tts_values
Definition: tuptable.h:130
bool ammissingPresent
bool * tts_isnull
Definition: tuptable.h:132
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
TupleConstr * constr
Definition: tupdesc.h:87

◆ slot_getsomeattrs()

void slot_getsomeattrs ( TupleTableSlot slot,
int  attnum 
)

Definition at line 1656 of file heaptuple.c.

References attnum, elog, ERROR, HeapTupleHeaderGetNatts, Min, tupleDesc::natts, slot_deform_tuple(), slot_getmissingattrs(), HeapTupleData::t_data, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecInterpExpr(), lookup_hash_entry(), prepare_projection_slot(), and process_ordered_aggregate_multi().

1657 {
1658  HeapTuple tuple;
1659  int attno;
1660 
1661  /* Quick out if we have 'em all already */
1662  if (slot->tts_nvalid >= attnum)
1663  return;
1664 
1665  /* Check for caller error */
1666  if (attnum <= 0 || attnum > slot->tts_tupleDescriptor->natts)
1667  elog(ERROR, "invalid attribute number %d", attnum);
1668 
1669  /*
1670  * otherwise we had better have a physical tuple (tts_nvalid should equal
1671  * natts in all virtual-tuple cases)
1672  */
1673  tuple = slot->tts_tuple;
1674  if (tuple == NULL) /* internal error */
1675  elog(ERROR, "cannot extract attribute from empty tuple slot");
1676 
1677  /*
1678  * load up any slots available from physical tuple
1679  */
1680  attno = HeapTupleHeaderGetNatts(tuple->t_data);
1681  attno = Min(attno, attnum);
1682 
1683  slot_deform_tuple(slot, attno);
1684 
1685  attno = slot->tts_nvalid;
1686 
1687  /*
1688  * If tuple doesn't have all the atts indicated by attnum, read the rest
1689  * as NULLs or missing values
1690  */
1691  if (attno < attnum)
1692  slot_getmissingattrs(slot, attno, attnum);
1693 
1694  slot->tts_nvalid = attnum;
1695 }
#define Min(x, y)
Definition: c.h:857
int natts
Definition: tupdesc.h:82
HeapTupleHeader t_data
Definition: htup.h:68
#define ERROR
Definition: elog.h:43
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:544
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
Definition: heaptuple.c:122
int16 attnum
Definition: pg_attribute.h:79
HeapTuple tts_tuple
Definition: tuptable.h:122
#define elog
Definition: elog.h:219
static void slot_deform_tuple(TupleTableSlot *slot, int natts)
Definition: heaptuple.c:1412

◆ slot_getsysattr()

bool slot_getsysattr ( TupleTableSlot slot,
int  attnum,
Datum value,
bool isnull 
)

Definition at line 1751 of file heaptuple.c.

References Assert, heap_getsysattr(), TupleTableSlot::tts_minhdr, TupleTableSlot::tts_tuple, and TupleTableSlot::tts_tupleDescriptor.

Referenced by execCurrentOf().

1753 {
1754  HeapTuple tuple = slot->tts_tuple;
1755 
1756  Assert(attnum < 0); /* else caller error */
1757  if (tuple == NULL ||
1758  tuple == &(slot->tts_minhdr))
1759  {
1760  /* No physical tuple, or minimal tuple, so fail */
1761  *value = (Datum) 0;
1762  *isnull = true;
1763  return false;
1764  }
1765  *value = heap_getsysattr(tuple, attnum, slot->tts_tupleDescriptor, isnull);
1766  return true;
1767 }
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: heaptuple.c:666
HeapTupleData tts_minhdr
Definition: tuptable.h:134
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
static struct @131 value
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:699
HeapTuple tts_tuple
Definition: tuptable.h:122