PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 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 (void)
 
TupleTableSlotExecAllocTableSlot (List **tupleTable)
 
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)
 

Macro Definition Documentation

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

Definition at line 132 of file tuptable.h.

Referenced by ExecCopySlotTuple(), and ExecFetchSlotTuple().

Typedef Documentation

Function Documentation

TupleTableSlot* ExecAllocTableSlot ( List **  tupleTable)

Definition at line 137 of file execTuples.c.

References lappend(), and MakeTupleTableSlot().

Referenced by ExecInitExtraTupleSlot(), ExecInitResultTupleSlot(), and ExecInitScanTupleSlot().

138 {
140 
141  *tupleTable = lappend(*tupleTable, slot);
142 
143  return slot;
144 }
TupleTableSlot * MakeTupleTableSlot(void)
Definition: execTuples.c:111
List * lappend(List *list, void *datum)
Definition: list.c:128
TupleTableSlot* ExecClearTuple ( TupleTableSlot slot)

Definition at line 439 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), InvalidBuffer, NULL, 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 advance_aggregates(), agg_retrieve_hash_table(), apply_handle_update(), 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(), ExecEndNestLoop(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndTableFuncScan(), ExecEndTidScan(), ExecEndUnique(), ExecEndValuesScan(), ExecEndWindowAgg(), ExecEndWorkTableScan(), ExecFilterJunk(), ExecGather(), ExecHashJoinGetSavedTuple(), ExecHashSubPlan(), ExecMaterial(), ExecMergeAppend(), ExecProject(), ExecProjectSRF(), ExecReScanAgg(), ExecReScanCteScan(), ExecReScanFunctionScan(), ExecReScanGroup(), ExecReScanMaterial(), ExecReScanMergeJoin(), ExecReScanSetOp(), ExecReScanSort(), ExecReScanTableFuncScan(), ExecReScanUnique(), ExecReScanValuesScan(), ExecReScanWindowAgg(), ExecReScanWorkTableScan(), ExecResetTupleTable(), ExecScan(), ExecScanFetch(), ExecSetSlotDescriptor(), ExecStoreAllNullTuple(), ExecUnique(), fetch_remote_table_info(), fetch_table_list(), fileIterateForeignScan(), FunctionNext(), gather_getnext(), gather_merge_clear_slots(), get_partition_for_tuple(), 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(), ShutdownFuncExpr(), slot_modify_cstrings(), slot_store_cstrings(), StoreIndexTuple(), tfuncLoadRows(), TidNext(), tuplesort_gettupleslot(), tuplestore_gettupleslot(), ValuesNext(), and WinRowsArePeers().

440 {
441  /*
442  * sanity checks
443  */
444  Assert(slot != NULL);
445 
446  /*
447  * Free the old physical tuple if necessary.
448  */
449  if (slot->tts_shouldFree)
450  heap_freetuple(slot->tts_tuple);
451  if (slot->tts_shouldFreeMin)
453 
454  slot->tts_tuple = NULL;
455  slot->tts_mintuple = NULL;
456  slot->tts_shouldFree = false;
457  slot->tts_shouldFreeMin = false;
458 
459  /*
460  * Drop the pin on the referenced buffer, if there is one.
461  */
462  if (BufferIsValid(slot->tts_buffer))
463  ReleaseBuffer(slot->tts_buffer);
464 
465  slot->tts_buffer = InvalidBuffer;
466 
467  /*
468  * Mark it empty.
469  */
470  slot->tts_isempty = true;
471  slot->tts_nvalid = 0;
472 
473  return slot;
474 }
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:1374
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1469
bool tts_shouldFree
Definition: tuptable.h:117
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:127
HeapTuple tts_tuple
Definition: tuptable.h:120
Buffer tts_buffer
Definition: tuptable.h:123
TupleTableSlot* ExecCopySlot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)

Definition at line 795 of file execTuples.c.

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

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

796 {
797  HeapTuple newTuple;
798  MemoryContext oldContext;
799 
800  /*
801  * There might be ways to optimize this when the source is virtual, but
802  * for now just always build a physical copy. Make sure it is in the
803  * right context.
804  */
805  oldContext = MemoryContextSwitchTo(dstslot->tts_mcxt);
806  newTuple = ExecCopySlotTuple(srcslot);
807  MemoryContextSwitchTo(oldContext);
808 
809  return ExecStoreTuple(newTuple, dstslot, InvalidBuffer, true);
810 }
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:320
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define InvalidBuffer
Definition: buf.h:25
MemoryContext tts_mcxt
Definition: tuptable.h:122
HeapTuple ExecCopySlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:545
MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot slot)

Definition at line 577 of file execTuples.c.

References Assert, heap_copy_minimal_tuple(), heap_form_minimal_tuple(), minimal_tuple_from_heap_tuple(), NULL, 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().

578 {
579  /*
580  * sanity checks
581  */
582  Assert(slot != NULL);
583  Assert(!slot->tts_isempty);
584 
585  /*
586  * If we have a physical tuple then just copy it. Prefer to copy
587  * tts_mintuple since that's a tad cheaper.
588  */
589  if (slot->tts_mintuple)
591  if (slot->tts_tuple)
593 
594  /*
595  * Otherwise we need to build a tuple from the Datum array.
596  */
598  slot->tts_values,
599  slot->tts_isnull);
600 }
bool tts_isempty
Definition: tuptable.h:116
Datum * tts_values
Definition: tuptable.h:125
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1481
bool * tts_isnull
Definition: tuptable.h:126
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1392
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
MinimalTuple tts_mintuple
Definition: tuptable.h:127
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
Definition: heaptuple.c:1522
HeapTuple tts_tuple
Definition: tuptable.h:120
HeapTuple ExecCopySlotTuple ( TupleTableSlot slot)

Definition at line 545 of file execTuples.c.

References Assert, heap_copytuple(), heap_form_tuple(), heap_tuple_from_minimal_tuple(), NULL, 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().

546 {
547  /*
548  * sanity checks
549  */
550  Assert(slot != NULL);
551  Assert(!slot->tts_isempty);
552 
553  /*
554  * If we have a physical tuple (either format) then just copy it.
555  */
556  if (TTS_HAS_PHYSICAL_TUPLE(slot))
557  return heap_copytuple(slot->tts_tuple);
558  if (slot->tts_mintuple)
560 
561  /*
562  * Otherwise we need to build a tuple from the Datum array.
563  */
565  slot->tts_values,
566  slot->tts_isnull);
567 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
bool tts_isempty
Definition: tuptable.h:116
Datum * tts_values
Definition: tuptable.h:125
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
bool * tts_isnull
Definition: tuptable.h:126
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1500
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
MinimalTuple tts_mintuple
Definition: tuptable.h:127
HeapTuple tts_tuple
Definition: tuptable.h:120
#define TTS_HAS_PHYSICAL_TUPLE(slot)
Definition: tuptable.h:132
void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 216 of file execTuples.c.

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

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

217 {
218  /* This should match ExecResetTupleTable's processing of one slot */
219  Assert(IsA(slot, TupleTableSlot));
220  ExecClearTuple(slot);
221  if (slot->tts_tupleDescriptor)
223  if (slot->tts_values)
224  pfree(slot->tts_values);
225  if (slot->tts_isnull)
226  pfree(slot->tts_isnull);
227  pfree(slot);
228 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:571
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
Datum * tts_values
Definition: tuptable.h:125
void pfree(void *pointer)
Definition: mcxt.c:950
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define Assert(condition)
Definition: c.h:675
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:107
MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot)

Definition at line 652 of file execTuples.c.

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

Referenced by ExecHashJoin(), ExecHashSkewTableInsert(), and ExecHashTableInsert().

653 {
654  MemoryContext oldContext;
655 
656  /*
657  * sanity checks
658  */
659  Assert(slot != NULL);
660  Assert(!slot->tts_isempty);
661 
662  /*
663  * If we have a minimal physical tuple (local or not) then just return it.
664  */
665  if (slot->tts_mintuple)
666  return slot->tts_mintuple;
667 
668  /*
669  * Otherwise, copy or build a minimal tuple, and store it into the slot.
670  *
671  * We may be called in a context that is shorter-lived than the tuple
672  * slot, but we have to ensure that the materialized tuple will survive
673  * anyway.
674  */
675  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
677  slot->tts_shouldFreeMin = true;
678  MemoryContextSwitchTo(oldContext);
679 
680  /*
681  * Note: we may now have a situation where we have a local minimal tuple
682  * attached to a virtual or non-local physical tuple. There seems no harm
683  * in that at the moment, but if any materializes, we should change this
684  * function to force the slot into minimal-tuple-only state.
685  */
686 
687  return slot->tts_mintuple;
688 }
bool tts_isempty
Definition: tuptable.h:116
MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition: execTuples.c:577
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool tts_shouldFreeMin
Definition: tuptable.h:118
MemoryContext tts_mcxt
Definition: tuptable.h:122
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
MinimalTuple tts_mintuple
Definition: tuptable.h:127
HeapTuple ExecFetchSlotTuple ( TupleTableSlot slot)

Definition at line 618 of file execTuples.c.

References Assert, ExecMaterializeSlot(), NULL, TTS_HAS_PHYSICAL_TUPLE, TupleTableSlot::tts_isempty, and TupleTableSlot::tts_tuple.

Referenced by ExecEvalWholeRowSlow(), ExecFetchSlotTupleDatum(), and get_partition_for_tuple().

619 {
620  /*
621  * sanity checks
622  */
623  Assert(slot != NULL);
624  Assert(!slot->tts_isempty);
625 
626  /*
627  * If we have a regular physical tuple then just return it.
628  */
629  if (TTS_HAS_PHYSICAL_TUPLE(slot))
630  return slot->tts_tuple;
631 
632  /*
633  * Otherwise materialize the slot...
634  */
635  return ExecMaterializeSlot(slot);
636 }
bool tts_isempty
Definition: tuptable.h:116
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
HeapTuple ExecMaterializeSlot(TupleTableSlot *slot)
Definition: execTuples.c:725
HeapTuple tts_tuple
Definition: tuptable.h:120
#define TTS_HAS_PHYSICAL_TUPLE(slot)
Definition: tuptable.h:132
Datum ExecFetchSlotTupleDatum ( TupleTableSlot slot)

Definition at line 698 of file execTuples.c.

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

Referenced by ExecEvalWholeRowFast(), ExecEvalWholeRowSlow(), ExecMakeFunctionResultSet(), and postquel_get_single_result().

699 {
700  HeapTuple tup;
701  TupleDesc tupdesc;
702 
703  /* Fetch slot's contents in regular-physical-tuple form */
704  tup = ExecFetchSlotTuple(slot);
705  tupdesc = slot->tts_tupleDescriptor;
706 
707  /* Convert to Datum form */
708  return heap_copy_tuple_as_datum(tup, tupdesc);
709 }
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:656
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
HeapTuple ExecFetchSlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:618
HeapTuple ExecMaterializeSlot ( TupleTableSlot slot)

Definition at line 725 of file execTuples.c.

References Assert, BufferIsValid, ExecCopySlotTuple(), InvalidBuffer, MemoryContextSwitchTo(), NULL, 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(), CopyFrom(), EvalPlanQual(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecFetchSlotTuple(), ExecInsert(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecProcessReturning(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), ExecUpdate(), ForeignNext(), intorel_receive(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), tqueueReceiveSlot(), and transientrel_receive().

726 {
727  MemoryContext oldContext;
728 
729  /*
730  * sanity checks
731  */
732  Assert(slot != NULL);
733  Assert(!slot->tts_isempty);
734 
735  /*
736  * If we have a regular physical tuple, and it's locally palloc'd, we have
737  * nothing to do.
738  */
739  if (slot->tts_tuple && slot->tts_shouldFree)
740  return slot->tts_tuple;
741 
742  /*
743  * Otherwise, copy or build a physical tuple, and store it into the slot.
744  *
745  * We may be called in a context that is shorter-lived than the tuple
746  * slot, but we have to ensure that the materialized tuple will survive
747  * anyway.
748  */
749  oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
750  slot->tts_tuple = ExecCopySlotTuple(slot);
751  slot->tts_shouldFree = true;
752  MemoryContextSwitchTo(oldContext);
753 
754  /*
755  * Drop the pin on the referenced buffer, if there is one.
756  */
757  if (BufferIsValid(slot->tts_buffer))
758  ReleaseBuffer(slot->tts_buffer);
759 
760  slot->tts_buffer = InvalidBuffer;
761 
762  /*
763  * Mark extracted state invalid. This is important because the slot is
764  * not supposed to depend any more on the previous external data; we
765  * mustn't leave any dangling pass-by-reference datums in tts_values.
766  * However, we have not actually invalidated any such datums, if there
767  * happen to be any previously fetched from the slot. (Note in particular
768  * that we have not pfree'd tts_mintuple, if there is one.)
769  */
770  slot->tts_nvalid = 0;
771 
772  /*
773  * On the same principle of not depending on previous remote storage,
774  * forget the mintuple if it's not local storage. (If it is local
775  * storage, we must not pfree it now, since callers might have already
776  * fetched datum pointers referencing it.)
777  */
778  if (!slot->tts_shouldFreeMin)
779  slot->tts_mintuple = NULL;
780 
781  return slot->tts_tuple;
782 }
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:122
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
bool tts_shouldFree
Definition: tuptable.h:117
HeapTuple ExecCopySlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:545
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:127
HeapTuple tts_tuple
Definition: tuptable.h:120
Buffer tts_buffer
Definition: tuptable.h:123
void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 156 of file execTuples.c.

References castNode, ExecClearTuple(), lfirst, list_free(), NULL, pfree(), ReleaseTupleDesc, 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().

158 {
159  ListCell *lc;
160 
161  foreach(lc, tupleTable)
162  {
164 
165  /* Always release resources and reset the slot to empty */
166  ExecClearTuple(slot);
167  if (slot->tts_tupleDescriptor)
168  {
170  slot->tts_tupleDescriptor = NULL;
171  }
172 
173  /* If shouldFree, release memory occupied by the slot itself */
174  if (shouldFree)
175  {
176  if (slot->tts_values)
177  pfree(slot->tts_values);
178  if (slot->tts_isnull)
179  pfree(slot->tts_isnull);
180  pfree(slot);
181  }
182  }
183 
184  /* If shouldFree, release the list structure */
185  if (shouldFree)
186  list_free(tupleTable);
187 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:589
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
Datum * tts_values
Definition: tuptable.h:125
void pfree(void *pointer)
Definition: mcxt.c:950
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
void list_free(List *list)
Definition: list.c:1133
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:107
void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 247 of file execTuples.c.

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

Referenced by apply_handle_delete(), apply_handle_insert(), apply_handle_update(), build_pertrans_for_aggref(), CopyFrom(), ExecAssignResultType(), ExecAssignScanType(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecDelete(), ExecInitAgg(), ExecInitFunctionScan(), ExecInitGather(), ExecInitHashJoin(), ExecInitJunkFilter(), ExecInitJunkFilterConversion(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNullTupleSlot(), ExecInitSubPlan(), ExecInitWindowAgg(), ExecInsert(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), find_hash_columns(), gather_merge_init(), MakeSingleTupleTableSlot(), and TriggerEnabled().

249 {
250  /* For safety, make sure slot is empty before changing it */
251  ExecClearTuple(slot);
252 
253  /*
254  * Release any old descriptor. Also release old Datum/isnull arrays if
255  * present (we don't bother to check if they could be re-used).
256  */
257  if (slot->tts_tupleDescriptor)
259 
260  if (slot->tts_values)
261  pfree(slot->tts_values);
262  if (slot->tts_isnull)
263  pfree(slot->tts_isnull);
264 
265  /*
266  * Install the new descriptor; if it's refcounted, bump its refcount.
267  */
268  slot->tts_tupleDescriptor = tupdesc;
269  PinTupleDesc(tupdesc);
270 
271  /*
272  * Allocate Datum/isnull arrays of the appropriate size. These must have
273  * the same lifetime as the slot, so allocate in the slot's own context.
274  */
275  slot->tts_values = (Datum *)
276  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
277  slot->tts_isnull = (bool *)
278  MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(bool));
279 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
MemoryContext tts_mcxt
Definition: tuptable.h:122
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
void pfree(void *pointer)
Definition: mcxt.c:950
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
#define PinTupleDesc(tupdesc)
Definition: tupdesc.h:101
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:107
TupleTableSlot* ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 512 of file execTuples.c.

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

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

513 {
514  /*
515  * sanity checks
516  */
517  Assert(slot != NULL);
518  Assert(slot->tts_tupleDescriptor != NULL);
519 
520  /* Clear any old contents */
521  ExecClearTuple(slot);
522 
523  /*
524  * Fill all the columns of the virtual tuple with nulls
525  */
526  MemSet(slot->tts_values, 0,
527  slot->tts_tupleDescriptor->natts * sizeof(Datum));
528  memset(slot->tts_isnull, true,
529  slot->tts_tupleDescriptor->natts * sizeof(bool));
530 
531  return ExecStoreVirtualTuple(slot);
532 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
#define MemSet(start, val, len)
Definition: c.h:857
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:488
TupleTableSlot* ExecStoreMinimalTuple ( MinimalTuple  mtup,
TupleTableSlot slot,
bool  shouldFree 
)

Definition at line 384 of file execTuples.c.

References Assert, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), InvalidBuffer, MINIMAL_TUPLE_OFFSET, NULL, 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(), ExecScanHashBucket(), ExecScanHashTableForUnmatched(), findPartialMatch(), setop_retrieve_hash_table(), TupleHashTableHash(), TupleHashTableMatch(), tuplesort_gettupleslot(), and tuplestore_gettupleslot().

387 {
388  /*
389  * sanity checks
390  */
391  Assert(mtup != NULL);
392  Assert(slot != NULL);
393  Assert(slot->tts_tupleDescriptor != NULL);
394 
395  /*
396  * Free any old physical tuple belonging to the slot.
397  */
398  if (slot->tts_shouldFree)
399  heap_freetuple(slot->tts_tuple);
400  if (slot->tts_shouldFreeMin)
402 
403  /*
404  * Drop the pin on the referenced buffer, if there is one.
405  */
406  if (BufferIsValid(slot->tts_buffer))
407  ReleaseBuffer(slot->tts_buffer);
408 
409  slot->tts_buffer = InvalidBuffer;
410 
411  /*
412  * Store the new tuple into the specified slot.
413  */
414  slot->tts_isempty = false;
415  slot->tts_shouldFree = false;
416  slot->tts_shouldFreeMin = shouldFree;
417  slot->tts_tuple = &slot->tts_minhdr;
418  slot->tts_mintuple = mtup;
419 
420  slot->tts_minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
421  slot->tts_minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
422  /* no need to set t_self or t_tableOid since we won't allow access */
423 
424  /* Mark extracted state invalid */
425  slot->tts_nvalid = 0;
426 
427  return slot;
428 }
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:1374
HeapTupleHeader t_data
Definition: htup.h:67
HeapTupleData tts_minhdr
Definition: tuptable.h:128
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1469
uint32 t_len
Definition: htup.h:64
bool tts_shouldFree
Definition: tuptable.h:117
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:127
#define MINIMAL_TUPLE_OFFSET
Definition: htup_details.h:620
HeapTuple tts_tuple
Definition: tuptable.h:120
Buffer tts_buffer
Definition: tuptable.h:123
TupleTableSlot* ExecStoreTuple ( HeapTuple  tuple,
TupleTableSlot slot,
Buffer  buffer,
bool  shouldFree 
)

Definition at line 320 of file execTuples.c.

References Assert, buffer, BufferIsValid, heap_free_minimal_tuple(), heap_freetuple(), IncrBufferRefCount(), NULL, 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_exclusion_or_unique_constraint(), comparetup_cluster(), compute_index_stats(), CopyFrom(), CopyFromInsertBatch(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecCopySlot(), ExecDelete(), ExecInsert(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecOnConflictUpdate(), ExecScanFetch(), gather_getnext(), gather_merge_readnext(), get_actual_variable_range(), get_partition_for_tuple(), get_returning_data(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), postgresIterateForeignScan(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), SampleNext(), SeqNext(), setop_retrieve_direct(), store_returning_result(), TidNext(), TriggerEnabled(), unique_key_recheck(), validate_index_heapscan(), and validateCheckConstraint().

324 {
325  /*
326  * sanity checks
327  */
328  Assert(tuple != NULL);
329  Assert(slot != NULL);
330  Assert(slot->tts_tupleDescriptor != NULL);
331  /* passing shouldFree=true for a tuple on a disk page is not sane */
332  Assert(BufferIsValid(buffer) ? (!shouldFree) : true);
333 
334  /*
335  * Free any old physical tuple belonging to the slot.
336  */
337  if (slot->tts_shouldFree)
338  heap_freetuple(slot->tts_tuple);
339  if (slot->tts_shouldFreeMin)
341 
342  /*
343  * Store the new tuple into the specified slot.
344  */
345  slot->tts_isempty = false;
346  slot->tts_shouldFree = shouldFree;
347  slot->tts_shouldFreeMin = false;
348  slot->tts_tuple = tuple;
349  slot->tts_mintuple = NULL;
350 
351  /* Mark extracted state invalid */
352  slot->tts_nvalid = 0;
353 
354  /*
355  * If tuple is on a disk page, keep the page pinned as long as we hold a
356  * pointer into it. We assume the caller already has such a pin.
357  *
358  * This is coded to optimize the case where the slot previously held a
359  * tuple on the same disk page: in that case releasing and re-acquiring
360  * the pin is a waste of cycles. This is a common situation during
361  * seqscans, so it's worth troubling over.
362  */
363  if (slot->tts_buffer != buffer)
364  {
365  if (BufferIsValid(slot->tts_buffer))
366  ReleaseBuffer(slot->tts_buffer);
367  slot->tts_buffer = buffer;
368  if (BufferIsValid(buffer))
370  }
371 
372  return slot;
373 }
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:1374
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition: heaptuple.c:1469
bool tts_shouldFree
Definition: tuptable.h:117
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
MinimalTuple tts_mintuple
Definition: tuptable.h:127
HeapTuple tts_tuple
Definition: tuptable.h:120
Buffer tts_buffer
Definition: tuptable.h:123
void IncrBufferRefCount(Buffer buffer)
Definition: bufmgr.c:3347
TupleTableSlot* MakeTupleTableSlot ( void  )

Definition at line 111 of file execTuples.c.

References CurrentMemoryContext, InvalidBuffer, makeNode, NULL, TupleTableSlot::tts_buffer, 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, and TupleTableSlot::tts_values.

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

112 {
114 
115  slot->tts_isempty = true;
116  slot->tts_shouldFree = false;
117  slot->tts_shouldFreeMin = false;
118  slot->tts_tuple = NULL;
119  slot->tts_tupleDescriptor = NULL;
121  slot->tts_buffer = InvalidBuffer;
122  slot->tts_nvalid = 0;
123  slot->tts_values = NULL;
124  slot->tts_isnull = NULL;
125  slot->tts_mintuple = NULL;
126 
127  return slot;
128 }
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:122
Datum * tts_values
Definition: tuptable.h:125
bool * tts_isnull
Definition: tuptable.h:126
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
bool tts_shouldFree
Definition: tuptable.h:117
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define makeNode(_type_)
Definition: nodes.h:568
#define NULL
Definition: c.h:229
MinimalTuple tts_mintuple
Definition: tuptable.h:127
HeapTuple tts_tuple
Definition: tuptable.h:120
Buffer tts_buffer
Definition: tuptable.h:123
bool slot_attisnull ( TupleTableSlot slot,
int  attnum 
)

Definition at line 1330 of file heaptuple.c.

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

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

1331 {
1332  HeapTuple tuple = slot->tts_tuple;
1334 
1335  /*
1336  * system attributes are handled by heap_attisnull
1337  */
1338  if (attnum <= 0)
1339  {
1340  if (tuple == NULL) /* internal error */
1341  elog(ERROR, "cannot extract system attribute from virtual tuple");
1342  if (tuple == &(slot->tts_minhdr)) /* internal error */
1343  elog(ERROR, "cannot extract system attribute from minimal tuple");
1344  return heap_attisnull(tuple, attnum);
1345  }
1346 
1347  /*
1348  * fast path if desired attribute already cached
1349  */
1350  if (attnum <= slot->tts_nvalid)
1351  return slot->tts_isnull[attnum - 1];
1352 
1353  /*
1354  * return NULL if attnum is out of range according to the tupdesc
1355  */
1356  if (attnum > tupleDesc->natts)
1357  return true;
1358 
1359  /*
1360  * otherwise we had better have a physical tuple (tts_nvalid should equal
1361  * natts in all virtual-tuple cases)
1362  */
1363  if (tuple == NULL) /* internal error */
1364  elog(ERROR, "cannot extract attribute from empty tuple slot");
1365 
1366  /* and let the tuple tell it */
1367  return heap_attisnull(tuple, attnum);
1368 }
int natts
Definition: tupdesc.h:73
#define ERROR
Definition: elog.h:43
HeapTupleData tts_minhdr
Definition: tuptable.h:128
bool * tts_isnull
Definition: tuptable.h:126
bool heap_attisnull(HeapTuple tup, int attnum)
Definition: heaptuple.c:297
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
#define NULL
Definition: c.h:229
HeapTuple tts_tuple
Definition: tuptable.h:120
#define elog
Definition: elog.h:219
void slot_getallattrs ( TupleTableSlot slot)

Definition at line 1239 of file heaptuple.c.

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

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

1240 {
1241  int tdesc_natts = slot->tts_tupleDescriptor->natts;
1242  int attnum;
1243  HeapTuple tuple;
1244 
1245  /* Quick out if we have 'em all already */
1246  if (slot->tts_nvalid == tdesc_natts)
1247  return;
1248 
1249  /*
1250  * otherwise we had better have a physical tuple (tts_nvalid should equal
1251  * natts in all virtual-tuple cases)
1252  */
1253  tuple = slot->tts_tuple;
1254  if (tuple == NULL) /* internal error */
1255  elog(ERROR, "cannot extract attribute from empty tuple slot");
1256 
1257  /*
1258  * load up any slots available from physical tuple
1259  */
1260  attnum = HeapTupleHeaderGetNatts(tuple->t_data);
1261  attnum = Min(attnum, tdesc_natts);
1262 
1263  slot_deform_tuple(slot, attnum);
1264 
1265  /*
1266  * If tuple doesn't have all the atts indicated by tupleDesc, read the
1267  * rest as null
1268  */
1269  for (; attnum < tdesc_natts; attnum++)
1270  {
1271  slot->tts_values[attnum] = (Datum) 0;
1272  slot->tts_isnull[attnum] = true;
1273  }
1274  slot->tts_nvalid = tdesc_natts;
1275 }
#define Min(x, y)
Definition: c.h:806
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
HeapTupleHeader t_data
Definition: htup.h:67
#define ERROR
Definition: elog.h:43
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:532
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
HeapTuple tts_tuple
Definition: tuptable.h:120
#define elog
Definition: elog.h:219
static void slot_deform_tuple(TupleTableSlot *slot, int natts)
Definition: heaptuple.c:1036
Datum slot_getattr ( TupleTableSlot slot,
int  attnum,
bool isnull 
)

Definition at line 1143 of file heaptuple.c.

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

Referenced by buildSubPlanHash(), convert_prep_stmt_params(), debugtup(), execCurrentOf(), ExecEvalScalarVar(), ExecEvalScalarVarFast(), ExecGetJunkAttribute(), ExecMakeFunctionResultSet(), ExecNestLoop(), ExecScanSubPlan(), ExecSetParamPlan(), execTuplesMatch(), 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(), and TupleHashTableHash().

1144 {
1145  HeapTuple tuple = slot->tts_tuple;
1147  HeapTupleHeader tup;
1148 
1149  /*
1150  * system attributes are handled by heap_getsysattr
1151  */
1152  if (attnum <= 0)
1153  {
1154  if (tuple == NULL) /* internal error */
1155  elog(ERROR, "cannot extract system attribute from virtual tuple");
1156  if (tuple == &(slot->tts_minhdr)) /* internal error */
1157  elog(ERROR, "cannot extract system attribute from minimal tuple");
1158  return heap_getsysattr(tuple, attnum, tupleDesc, isnull);
1159  }
1160 
1161  /*
1162  * fast path if desired attribute already cached
1163  */
1164  if (attnum <= slot->tts_nvalid)
1165  {
1166  *isnull = slot->tts_isnull[attnum - 1];
1167  return slot->tts_values[attnum - 1];
1168  }
1169 
1170  /*
1171  * return NULL if attnum is out of range according to the tupdesc
1172  */
1173  if (attnum > tupleDesc->natts)
1174  {
1175  *isnull = true;
1176  return (Datum) 0;
1177  }
1178 
1179  /*
1180  * otherwise we had better have a physical tuple (tts_nvalid should equal
1181  * natts in all virtual-tuple cases)
1182  */
1183  if (tuple == NULL) /* internal error */
1184  elog(ERROR, "cannot extract attribute from empty tuple slot");
1185 
1186  /*
1187  * return NULL if attnum is out of range according to the tuple
1188  *
1189  * (We have to check this separately because of various inheritance and
1190  * table-alteration scenarios: the tuple could be either longer or shorter
1191  * than the tupdesc.)
1192  */
1193  tup = tuple->t_data;
1194  if (attnum > HeapTupleHeaderGetNatts(tup))
1195  {
1196  *isnull = true;
1197  return (Datum) 0;
1198  }
1199 
1200  /*
1201  * check if target attribute is null: no point in groveling through tuple
1202  */
1203  if (HeapTupleHasNulls(tuple) && att_isnull(attnum - 1, tup->t_bits))
1204  {
1205  *isnull = true;
1206  return (Datum) 0;
1207  }
1208 
1209  /*
1210  * If the attribute's column has been dropped, we force a NULL result.
1211  * This case should not happen in normal use, but it could happen if we
1212  * are executing a plan cached before the column was dropped.
1213  */
1214  if (tupleDesc->attrs[attnum - 1]->attisdropped)
1215  {
1216  *isnull = true;
1217  return (Datum) 0;
1218  }
1219 
1220  /*
1221  * Extract the attribute, along with any preceding attributes.
1222  */
1223  slot_deform_tuple(slot, attnum);
1224 
1225  /*
1226  * The result is acquired from tts_values array.
1227  */
1228  *isnull = slot->tts_isnull[attnum - 1];
1229  return slot->tts_values[attnum - 1];
1230 }
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]
Definition: htup_details.h:163
#define att_isnull(ATT, BITS)
Definition: tupmacs.h:21
Form_pg_attribute * attrs
Definition: tupdesc.h:74
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
HeapTupleHeader t_data
Definition: htup.h:67
#define ERROR
Definition: elog.h:43
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: heaptuple.c:552
HeapTupleData tts_minhdr
Definition: tuptable.h:128
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:532
#define HeapTupleHasNulls(tuple)
Definition: htup_details.h:662
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
HeapTuple tts_tuple
Definition: tuptable.h:120
#define elog
Definition: elog.h:219
static void slot_deform_tuple(TupleTableSlot *slot, int natts)
Definition: heaptuple.c:1036
void slot_getsomeattrs ( TupleTableSlot slot,
int  attnum 
)

Definition at line 1283 of file heaptuple.c.

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

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

1284 {
1285  HeapTuple tuple;
1286  int attno;
1287 
1288  /* Quick out if we have 'em all already */
1289  if (slot->tts_nvalid >= attnum)
1290  return;
1291 
1292  /* Check for caller error */
1293  if (attnum <= 0 || attnum > slot->tts_tupleDescriptor->natts)
1294  elog(ERROR, "invalid attribute number %d", attnum);
1295 
1296  /*
1297  * otherwise we had better have a physical tuple (tts_nvalid should equal
1298  * natts in all virtual-tuple cases)
1299  */
1300  tuple = slot->tts_tuple;
1301  if (tuple == NULL) /* internal error */
1302  elog(ERROR, "cannot extract attribute from empty tuple slot");
1303 
1304  /*
1305  * load up any slots available from physical tuple
1306  */
1307  attno = HeapTupleHeaderGetNatts(tuple->t_data);
1308  attno = Min(attno, attnum);
1309 
1310  slot_deform_tuple(slot, attno);
1311 
1312  /*
1313  * If tuple doesn't have all the atts indicated by tupleDesc, read the
1314  * rest as null
1315  */
1316  for (; attno < attnum; attno++)
1317  {
1318  slot->tts_values[attno] = (Datum) 0;
1319  slot->tts_isnull[attno] = true;
1320  }
1321  slot->tts_nvalid = attnum;
1322 }
#define Min(x, y)
Definition: c.h:806
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
HeapTupleHeader t_data
Definition: htup.h:67
#define ERROR
Definition: elog.h:43
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:532
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
HeapTuple tts_tuple
Definition: tuptable.h:120
#define elog
Definition: elog.h:219
static void slot_deform_tuple(TupleTableSlot *slot, int natts)
Definition: heaptuple.c:1036