PostgreSQL Source Code git master
Loading...
Searching...
No Matches
execTuples.c File Reference
#include "postgres.h"
#include "access/heaptoast.h"
#include "access/htup_details.h"
#include "access/tupdesc_details.h"
#include "access/xact.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "nodes/nodeFuncs.h"
#include "storage/bufmgr.h"
#include "utils/builtins.h"
#include "utils/expandeddatum.h"
#include "utils/lsyscache.h"
#include "utils/typcache.h"
Include dependency graph for execTuples.c:

Go to the source code of this file.

Functions

static TupleDesc ExecTypeFromTLInternal (List *targetList, bool skipjunk)
 
static pg_attribute_always_inline void slot_deform_heap_tuple (TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int reqnatts, bool support_cstring)
 
static void tts_buffer_heap_store_tuple (TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
 
static void tts_heap_store_tuple (TupleTableSlot *slot, HeapTuple tuple, bool shouldFree)
 
static void tts_virtual_init (TupleTableSlot *slot)
 
static void tts_virtual_release (TupleTableSlot *slot)
 
static void tts_virtual_clear (TupleTableSlot *slot)
 
static void tts_virtual_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_virtual_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static bool tts_virtual_is_current_xact_tuple (TupleTableSlot *slot)
 
static void tts_virtual_materialize (TupleTableSlot *slot)
 
static void tts_virtual_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static HeapTuple tts_virtual_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_virtual_copy_minimal_tuple (TupleTableSlot *slot, Size extra)
 
static void tts_heap_init (TupleTableSlot *slot)
 
static void tts_heap_release (TupleTableSlot *slot)
 
static void tts_heap_clear (TupleTableSlot *slot)
 
static void tts_heap_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_heap_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static bool tts_heap_is_current_xact_tuple (TupleTableSlot *slot)
 
static void tts_heap_materialize (TupleTableSlot *slot)
 
static void tts_heap_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static HeapTuple tts_heap_get_heap_tuple (TupleTableSlot *slot)
 
static HeapTuple tts_heap_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_heap_copy_minimal_tuple (TupleTableSlot *slot, Size extra)
 
static void tts_minimal_init (TupleTableSlot *slot)
 
static void tts_minimal_release (TupleTableSlot *slot)
 
static void tts_minimal_clear (TupleTableSlot *slot)
 
static void tts_minimal_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_minimal_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static bool tts_minimal_is_current_xact_tuple (TupleTableSlot *slot)
 
static void tts_minimal_materialize (TupleTableSlot *slot)
 
static void tts_minimal_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static MinimalTuple tts_minimal_get_minimal_tuple (TupleTableSlot *slot)
 
static HeapTuple tts_minimal_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_minimal_copy_minimal_tuple (TupleTableSlot *slot, Size extra)
 
static void tts_minimal_store_tuple (TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
 
static void tts_buffer_heap_init (TupleTableSlot *slot)
 
static void tts_buffer_heap_release (TupleTableSlot *slot)
 
static void tts_buffer_heap_clear (TupleTableSlot *slot)
 
static void tts_buffer_heap_getsomeattrs (TupleTableSlot *slot, int natts)
 
static Datum tts_buffer_heap_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static bool tts_buffer_is_current_xact_tuple (TupleTableSlot *slot)
 
static void tts_buffer_heap_materialize (TupleTableSlot *slot)
 
static void tts_buffer_heap_copyslot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 
static HeapTuple tts_buffer_heap_get_heap_tuple (TupleTableSlot *slot)
 
static HeapTuple tts_buffer_heap_copy_heap_tuple (TupleTableSlot *slot)
 
static MinimalTuple tts_buffer_heap_copy_minimal_tuple (TupleTableSlot *slot, Size extra)
 
TupleTableSlotMakeTupleTableSlot (TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops, uint16 flags)
 
TupleTableSlotExecAllocTableSlot (List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops, uint16 flags)
 
void ExecResetTupleTable (List *tupleTable, bool shouldFree)
 
TupleTableSlotMakeSingleTupleTableSlot (TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
 
void ExecDropSingleTupleTableSlot (TupleTableSlot *slot)
 
void ExecSetSlotDescriptor (TupleTableSlot *slot, TupleDesc tupdesc)
 
TupleTableSlotExecStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecStoreBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlotExecStorePinnedBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlotExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecStoreVirtualTuple (TupleTableSlot *slot)
 
TupleTableSlotExecStoreAllNullTuple (TupleTableSlot *slot)
 
void ExecStoreHeapTupleDatum (Datum data, TupleTableSlot *slot)
 
HeapTuple ExecFetchSlotHeapTuple (TupleTableSlot *slot, bool materialize, bool *shouldFree)
 
MinimalTuple ExecFetchSlotMinimalTuple (TupleTableSlot *slot, bool *shouldFree)
 
Datum ExecFetchSlotHeapTupleDatum (TupleTableSlot *slot)
 
void ExecInitResultTypeTL (PlanState *planstate)
 
void ExecInitResultSlot (PlanState *planstate, const TupleTableSlotOps *tts_ops)
 
void ExecInitResultTupleSlotTL (PlanState *planstate, const TupleTableSlotOps *tts_ops)
 
void ExecInitScanTupleSlot (EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops, uint16 flags)
 
TupleTableSlotExecInitExtraTupleSlot (EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
 
TupleTableSlotExecInitNullTupleSlot (EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
 
void slot_getmissingattrs (TupleTableSlot *slot, int startAttNum, int lastAttNum)
 
void slot_getsomeattrs_int (TupleTableSlot *slot, int attnum)
 
TupleDesc ExecTypeFromTL (List *targetList)
 
TupleDesc ExecCleanTypeFromTL (List *targetList)
 
TupleDesc ExecTypeFromExprList (List *exprList)
 
void ExecTypeSetColNames (TupleDesc typeInfo, List *namesList)
 
TupleDesc BlessTupleDesc (TupleDesc tupdesc)
 
AttInMetadataTupleDescGetAttInMetadata (TupleDesc tupdesc)
 
HeapTuple BuildTupleFromCStrings (AttInMetadata *attinmeta, char **values)
 
Datum HeapTupleHeaderGetDatum (HeapTupleHeader tuple)
 
TupOutputStatebegin_tup_output_tupdesc (DestReceiver *dest, TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
 
void do_tup_output (TupOutputState *tstate, const Datum *values, const bool *isnull)
 
void do_text_output_multiline (TupOutputState *tstate, const char *txt)
 
void end_tup_output (TupOutputState *tstate)
 

Variables

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

Function Documentation

◆ begin_tup_output_tupdesc()

TupOutputState * begin_tup_output_tupdesc ( DestReceiver dest,
TupleDesc  tupdesc,
const TupleTableSlotOps tts_ops 
)

Definition at line 2532 of file execTuples.c.

2535{
2537
2539
2540 tstate->slot = MakeSingleTupleTableSlot(tupdesc, tts_ops);
2541 tstate->dest = dest;
2542
2543 tstate->dest->rStartup(tstate->dest, (int) CMD_SELECT, tupdesc);
2544
2545 return tstate;
2546}
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
#define palloc_object(type)
Definition fe_memutils.h:89
@ CMD_SELECT
Definition nodes.h:275
static int fb(int x)

References CMD_SELECT, fb(), MakeSingleTupleTableSlot(), and palloc_object.

Referenced by CreateReplicationSlot(), ExecuteCallStmt(), ExecWaitStmt(), ExplainQuery(), IdentifySystem(), ReadReplicationSlot(), SendTablespaceList(), SendXlogRecPtrResult(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

◆ BlessTupleDesc()

TupleDesc BlessTupleDesc ( TupleDesc  tupdesc)

Definition at line 2345 of file execTuples.c.

2346{
2347 /* Did someone forget to call TupleDescFinalize()? */
2348 Assert(tupdesc->firstNonCachedOffsetAttr >= 0);
2349
2350 if (tupdesc->tdtypeid == RECORDOID &&
2351 tupdesc->tdtypmod < 0)
2353
2354 return tupdesc; /* just for notational convenience */
2355}
#define Assert(condition)
Definition c.h:943
int firstNonCachedOffsetAttr
Definition tupdesc.h:154
int32 tdtypmod
Definition tupdesc.h:152
void assign_record_type_typmod(TupleDesc tupDesc)
Definition typcache.c:2060

References Assert, assign_record_type_typmod(), fb(), TupleDescData::firstNonCachedOffsetAttr, TupleDescData::tdtypeid, and TupleDescData::tdtypmod.

Referenced by aclexplode(), BeginCopyTo(), brin_metapage_info(), bt_page_items_bytea(), bt_page_items_internal(), build_buffercache_pages_tupledesc(), exec_eval_datum(), ExecEvalWholeRowVar(), ExecInitExprRec(), ExecInitFunctionScan(), get_expr_result_type(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), init_execution_state(), InitMaterializedSRF(), pg_buffercache_os_pages_internal(), pg_get_catalog_foreign_keys(), pg_get_publication_tables(), pg_get_sequence_data(), pg_lock_status(), pg_prepared_xact(), pg_stat_file(), pg_stat_get_archiver(), pg_stat_get_backend_subxact(), pg_stat_get_replication_slot(), pg_stat_get_subscription_stats(), pg_stat_wal_build_tuple(), pg_stats_ext_mcvlist_items(), pg_visibility_tupdesc(), pg_walfile_name_offset(), pgstathashindex(), PLy_output_setup_record(), setup_firstcall(), ssl_extension_info(), test_custom_stats_fixed_report(), test_custom_stats_var_report(), test_enc_conversion(), test_predtest(), and TupleDescGetAttInMetadata().

◆ BuildTupleFromCStrings()

HeapTuple BuildTupleFromCStrings ( AttInMetadata attinmeta,
char **  values 
)

Definition at line 2412 of file execTuples.c.

2413{
2414 TupleDesc tupdesc = attinmeta->tupdesc;
2415 int natts = tupdesc->natts;
2416 Datum *dvalues;
2417 bool *nulls;
2418 int i;
2419 HeapTuple tuple;
2420
2421 dvalues = (Datum *) palloc(natts * sizeof(Datum));
2422 nulls = (bool *) palloc(natts * sizeof(bool));
2423
2424 /*
2425 * Call the "in" function for each non-dropped attribute, even for nulls,
2426 * to support domains.
2427 */
2428 for (i = 0; i < natts; i++)
2429 {
2430 if (!TupleDescCompactAttr(tupdesc, i)->attisdropped)
2431 {
2432 /* Non-dropped attributes */
2433 dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
2434 values[i],
2435 attinmeta->attioparams[i],
2436 attinmeta->atttypmods[i]);
2437 if (values[i] != NULL)
2438 nulls[i] = false;
2439 else
2440 nulls[i] = true;
2441 }
2442 else
2443 {
2444 /* Handle dropped attributes by setting to NULL */
2445 dvalues[i] = (Datum) 0;
2446 nulls[i] = true;
2447 }
2448 }
2449
2450 /*
2451 * Form a tuple
2452 */
2453 tuple = heap_form_tuple(tupdesc, dvalues, nulls);
2454
2455 /*
2456 * Release locally palloc'd space. XXX would probably be good to pfree
2457 * values of pass-by-reference datums, as well.
2458 */
2459 pfree(dvalues);
2460 pfree(nulls);
2461
2462 return tuple;
2463}
static Datum values[MAXATTR]
Definition bootstrap.c:190
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition fmgr.c:1532
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1619
void * palloc(Size size)
Definition mcxt.c:1390
uint64_t Datum
Definition postgres.h:70
FmgrInfo * attinfuncs
Definition funcapi.h:41
TupleDesc tupdesc
Definition funcapi.h:38
Oid * attioparams
Definition funcapi.h:44
int32 * atttypmods
Definition funcapi.h:47
bool attisdropped
Definition tupdesc.h:78
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:195

References AttInMetadata::attinfuncs, AttInMetadata::attioparams, CompactAttribute::attisdropped, AttInMetadata::atttypmods, fb(), heap_form_tuple(), i, InputFunctionCall(), TupleDescData::natts, palloc(), pfree(), AttInMetadata::tupdesc, TupleDescCompactAttr(), and values.

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

◆ do_text_output_multiline()

void do_text_output_multiline ( TupOutputState tstate,
const char txt 
)

Definition at line 2580 of file execTuples.c.

2581{
2582 Datum values[1];
2583 bool isnull[1] = {false};
2584
2585 while (*txt)
2586 {
2587 const char *eol;
2588 int len;
2589
2590 eol = strchr(txt, '\n');
2591 if (eol)
2592 {
2593 len = eol - txt;
2594 eol++;
2595 }
2596 else
2597 {
2598 len = strlen(txt);
2599 eol = txt + len;
2600 }
2601
2603 do_tup_output(tstate, values, isnull);
2605 txt = eol;
2606 }
2607}
void do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull)
const void size_t len
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
#define PointerGetDatum(X)
Definition postgres.h:354
text * cstring_to_text_with_len(const char *s, int len)
Definition varlena.c:196

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

Referenced by ExplainQuery().

◆ do_tup_output()

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

Definition at line 2552 of file execTuples.c.

2553{
2554 TupleTableSlot *slot = tstate->slot;
2555 int natts = slot->tts_tupleDescriptor->natts;
2556
2557 /* make sure the slot is clear */
2558 ExecClearTuple(slot);
2559
2560 /* insert data */
2561 memcpy(slot->tts_values, values, natts * sizeof(Datum));
2562 memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
2563
2564 /* mark slot as containing a virtual tuple */
2566
2567 /* send the tuple to the receiver */
2568 (void) tstate->dest->receiveSlot(slot, tstate->dest);
2569
2570 /* clean up */
2571 ExecClearTuple(slot);
2572}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
TupleDesc tts_tupleDescriptor
Definition tuptable.h:129
bool * tts_isnull
Definition tuptable.h:133
Datum * tts_values
Definition tuptable.h:131
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476

References ExecClearTuple(), ExecStoreVirtualTuple(), fb(), memcpy(), TupleDescData::natts, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and values.

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

◆ end_tup_output()

void end_tup_output ( TupOutputState tstate)

Definition at line 2610 of file execTuples.c.

2611{
2612 tstate->dest->rShutdown(tstate->dest);
2613 /* note that destroying the dest is not ours to do */
2615 pfree(tstate);
2616}
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)

References ExecDropSingleTupleTableSlot(), fb(), and pfree().

Referenced by CreateReplicationSlot(), ExecuteCallStmt(), ExecWaitStmt(), ExplainQuery(), IdentifySystem(), ReadReplicationSlot(), SendTablespaceList(), SendXlogRecPtrResult(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

◆ ExecAllocTableSlot()

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

Definition at line 1437 of file execTuples.c.

1439{
1440 TupleTableSlot *slot = MakeTupleTableSlot(desc, tts_ops, flags);
1441
1442 *tupleTable = lappend(*tupleTable, slot);
1443
1444 return slot;
1445}
TupleTableSlot * MakeTupleTableSlot(TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops, uint16 flags)
List * lappend(List *list, void *datum)
Definition list.c:339

References fb(), lappend(), and MakeTupleTableSlot().

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

◆ ExecCleanTypeFromTL()

TupleDesc ExecCleanTypeFromTL ( List targetList)

Definition at line 2217 of file execTuples.c.

2218{
2219 return ExecTypeFromTLInternal(targetList, true);
2220}
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool skipjunk)

References ExecTypeFromTLInternal().

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

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)

Definition at line 1520 of file execTuples.c.

1521{
1522 /* This should match ExecResetTupleTable's processing of one slot */
1523 Assert(IsA(slot, TupleTableSlot));
1524 ExecClearTuple(slot);
1525 slot->tts_ops->release(slot);
1526 if (slot->tts_tupleDescriptor)
1528 if (!TTS_FIXED(slot))
1529 {
1530 if (slot->tts_values)
1531 pfree(slot->tts_values);
1532 if (slot->tts_isnull)
1533 pfree(slot->tts_isnull);
1534 }
1535 pfree(slot);
1536}
#define IsA(nodeptr, _type_)
Definition nodes.h:164
void(* release)(TupleTableSlot *slot)
Definition tuptable.h:156
const TupleTableSlotOps *const tts_ops
Definition tuptable.h:127
#define ReleaseTupleDesc(tupdesc)
Definition tupdesc.h:240
#define TTS_FIXED(slot)
Definition tuptable.h:108

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

Referenced by acquire_sample_rows(), AfterTriggerFreeQuery(), afterTriggerInvokeEvents(), apply_concurrent_changes(), ATRewriteTable(), CatalogIndexInsert(), check_default_partition_contents(), check_exclusion_or_unique_constraint(), check_pub_dead_tuple_retention(), check_publications(), check_publications_origin_sequences(), check_publications_origin_tables(), compute_expr_stats(), compute_index_stats(), copy_sequences(), CopyMultiInsertBufferCleanup(), CopyRelationTo(), copyTemplateDependencies(), DefineTSConfiguration(), deleteSplitPartitionContext(), end_tup_output(), EnumValuesCreate(), ExecCleanupTupleRouting(), ExecEndIncrementalSort(), ExecEndModifyTable(), fetch_relation_list(), fetch_remote_slots(), fetch_remote_table_info(), FindConflictTuple(), freestate_cluster(), get_actual_variable_range(), get_rel_sync_entry(), heap_entry_is_visible(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), hypothetical_dense_rank_final(), IndexCheckExclusion(), InsertPgAttributeTuples(), make_build_data(), MakeConfigurationMapping(), MergePartitionsMoveRows(), pgoutput_change(), recordMultipleDependencies(), RelationFindDeletedTupleInfoByIndex(), RelationFindDeletedTupleInfoSeq(), RelationFindReplTupleSeq(), repack_cleanup_logical_decoding(), ri_FastPathCheck(), ri_FastPathTeardown(), RI_Initial_Check(), RunFromStore(), SplitPartitionMoveRows(), systable_endscan(), systable_endscan_ordered(), table_index_fetch_tuple_check(), tstoreShutdownReceiver(), unique_key_recheck(), validate_remote_info(), validateDomainCheckConstraint(), validateDomainNotNullConstraint(), and validateForeignKeyConstraint().

◆ ExecFetchSlotHeapTuple()

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

Definition at line 1916 of file execTuples.c.

1917{
1918 /*
1919 * sanity checks
1920 */
1921 Assert(slot != NULL);
1922 Assert(!TTS_EMPTY(slot));
1923
1924 /* Materialize the tuple so that the slot "owns" it, if requested. */
1925 if (materialize)
1926 slot->tts_ops->materialize(slot);
1927
1928 if (slot->tts_ops->get_heap_tuple == NULL)
1929 {
1930 if (shouldFree)
1931 *shouldFree = true;
1932 return slot->tts_ops->copy_heap_tuple(slot);
1933 }
1934 else
1935 {
1936 if (shouldFree)
1937 *shouldFree = false;
1938 return slot->tts_ops->get_heap_tuple(slot);
1939 }
1940}
HeapTuple(* get_heap_tuple)(TupleTableSlot *slot)
Definition tuptable.h:209
HeapTuple(* copy_heap_tuple)(TupleTableSlot *slot)
Definition tuptable.h:227
void(* materialize)(TupleTableSlot *slot)
Definition tuptable.h:194
#define TTS_EMPTY(slot)
Definition tuptable.h:92

References Assert, TupleTableSlotOps::copy_heap_tuple, fb(), TupleTableSlotOps::get_heap_tuple, TupleTableSlotOps::materialize, TTS_EMPTY, and TupleTableSlot::tts_ops.

Referenced by AfterTriggerExecute(), apply_returning_filter(), CatalogTuplesMultiInsertWithInfo(), ExecBRDeleteTriggers(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecFetchSlotHeapTupleDatum(), ExecForPortionOfLeftovers(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), heap_multi_insert(), heapam_relation_copy_for_cluster(), heapam_tuple_complete_speculative(), heapam_tuple_insert(), heapam_tuple_insert_speculative(), heapam_tuple_update(), systable_getnext(), systable_getnext_ordered(), systable_recheck_tuple(), update_most_recent_deletion_info(), and validateForeignKeyConstraint().

◆ ExecFetchSlotHeapTupleDatum()

Datum ExecFetchSlotHeapTupleDatum ( TupleTableSlot slot)

Definition at line 1995 of file execTuples.c.

1996{
1997 HeapTuple tup;
1998 TupleDesc tupdesc;
1999 bool shouldFree;
2000 Datum ret;
2001
2002 /* Fetch slot's contents in regular-physical-tuple form */
2003 tup = ExecFetchSlotHeapTuple(slot, false, &shouldFree);
2004 tupdesc = slot->tts_tupleDescriptor;
2005
2006 /* Convert to Datum form */
2007 ret = heap_copy_tuple_as_datum(tup, tupdesc);
2008
2009 if (shouldFree)
2010 pfree(tup);
2011
2012 return ret;
2013}
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition heaptuple.c:989

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

Referenced by CopyToJsonOneRow(), ExecMakeFunctionResultSet(), and postquel_get_single_result().

◆ ExecFetchSlotMinimalTuple()

MinimalTuple ExecFetchSlotMinimalTuple ( TupleTableSlot slot,
bool shouldFree 
)

Definition at line 1964 of file execTuples.c.

1966{
1967 /*
1968 * sanity checks
1969 */
1970 Assert(slot != NULL);
1971 Assert(!TTS_EMPTY(slot));
1972
1973 if (slot->tts_ops->get_minimal_tuple)
1974 {
1975 if (shouldFree)
1976 *shouldFree = false;
1977 return slot->tts_ops->get_minimal_tuple(slot);
1978 }
1979 else
1980 {
1981 if (shouldFree)
1982 *shouldFree = true;
1983 return slot->tts_ops->copy_minimal_tuple(slot, 0);
1984 }
1985}
MinimalTuple(* copy_minimal_tuple)(TupleTableSlot *slot, Size extra)
Definition tuptable.h:241
MinimalTuple(* get_minimal_tuple)(TupleTableSlot *slot)
Definition tuptable.h:217

References Assert, TupleTableSlotOps::copy_minimal_tuple, fb(), TupleTableSlotOps::get_minimal_tuple, TTS_EMPTY, and TupleTableSlot::tts_ops.

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

◆ ExecForceStoreHeapTuple()

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

Definition at line 1741 of file execTuples.c.

1744{
1745 if (TTS_IS_HEAPTUPLE(slot))
1746 {
1747 ExecStoreHeapTuple(tuple, slot, shouldFree);
1748 }
1749 else if (TTS_IS_BUFFERTUPLE(slot))
1750 {
1753
1754 ExecClearTuple(slot);
1755 slot->tts_flags &= ~TTS_FLAG_EMPTY;
1757 bslot->base.tuple = heap_copytuple(tuple);
1760
1761 if (shouldFree)
1762 pfree(tuple);
1763 }
1764 else
1765 {
1766 ExecClearTuple(slot);
1768 slot->tts_values, slot->tts_isnull);
1770
1771 if (shouldFree)
1772 {
1773 ExecMaterializeSlot(slot);
1774 pfree(tuple);
1775 }
1776 }
1777}
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
HeapTuple heap_copytuple(HeapTuple tuple)
Definition heaptuple.c:686
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition heaptuple.c:1254
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
MemoryContext tts_mcxt
Definition tuptable.h:141
uint16 tts_flags
Definition tuptable.h:124
#define TTS_FLAG_SHOULDFREE
Definition tuptable.h:95
#define TTS_IS_BUFFERTUPLE(slot)
Definition tuptable.h:256
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition tuptable.h:495
#define TTS_IS_HEAPTUPLE(slot)
Definition tuptable.h:254

References ExecClearTuple(), ExecMaterializeSlot(), ExecStoreHeapTuple(), ExecStoreVirtualTuple(), fb(), heap_copytuple(), heap_deform_tuple(), MemoryContextSwitchTo(), pfree(), TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TTS_IS_BUFFERTUPLE, TTS_IS_HEAPTUPLE, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

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

◆ ExecForceStoreMinimalTuple()

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

Definition at line 1784 of file execTuples.c.

1787{
1788 if (TTS_IS_MINIMALTUPLE(slot))
1789 {
1791 }
1792 else
1793 {
1794 HeapTupleData htup;
1795
1796 ExecClearTuple(slot);
1797
1798 htup.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
1799 htup.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
1801 slot->tts_values, slot->tts_isnull);
1803
1804 if (shouldFree)
1805 {
1806 ExecMaterializeSlot(slot);
1807 pfree(mtup);
1808 }
1809 }
1810}
static void tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
Definition execTuples.c:682
HeapTupleHeaderData * HeapTupleHeader
Definition htup.h:23
#define MINIMAL_TUPLE_OFFSET
uint32 t_len
Definition htup.h:64
HeapTupleHeader t_data
Definition htup.h:68
#define TTS_IS_MINIMALTUPLE(slot)
Definition tuptable.h:255

References ExecClearTuple(), ExecMaterializeSlot(), ExecStoreVirtualTuple(), fb(), heap_deform_tuple(), MINIMAL_TUPLE_OFFSET, pfree(), HeapTupleData::t_data, HeapTupleData::t_len, TTS_IS_MINIMALTUPLE, TupleTableSlot::tts_isnull, tts_minimal_store_tuple(), TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by ExecHashJoinGetSavedTuple(), ExecParallelHashJoinNewBatch(), ExecParallelHashJoinOuterGetTuple(), and tuplestore_gettupleslot_force().

◆ ExecInitExtraTupleSlot()

◆ ExecInitNullTupleSlot()

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

Definition at line 2120 of file execTuples.c.

2122{
2123 TupleTableSlot *slot = ExecInitExtraTupleSlot(estate, tupType, tts_ops);
2124
2125 return ExecStoreAllNullTuple(slot);
2126}
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)

References ExecInitExtraTupleSlot(), ExecStoreAllNullTuple(), and fb().

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

◆ ExecInitResultSlot()

void ExecInitResultSlot ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

Definition at line 2051 of file execTuples.c.

2052{
2053 TupleTableSlot *slot;
2054
2055 slot = ExecAllocTableSlot(&planstate->state->es_tupleTable,
2056 planstate->ps_ResultTupleDesc, tts_ops, 0);
2057 planstate->ps_ResultTupleSlot = slot;
2058
2059 planstate->resultopsfixed = planstate->ps_ResultTupleDesc != NULL;
2060 planstate->resultops = tts_ops;
2061 planstate->resultopsset = true;
2062}
const TupleTableSlotOps * resultops
Definition execnodes.h:1281
bool resultopsset
Definition execnodes.h:1289
EState * state
Definition execnodes.h:1204
TupleDesc ps_ResultTupleDesc
Definition execnodes.h:1241
TupleTableSlot * ps_ResultTupleSlot
Definition execnodes.h:1242
bool resultopsfixed
Definition execnodes.h:1285

References EState::es_tupleTable, ExecAllocTableSlot(), fb(), PlanState::ps_ResultTupleDesc, PlanState::ps_ResultTupleSlot, PlanState::resultops, PlanState::resultopsfixed, PlanState::resultopsset, and PlanState::state.

Referenced by ExecConditionalAssignProjectionInfo(), and ExecInitResultTupleSlotTL().

◆ ExecInitResultTupleSlotTL()

void ExecInitResultTupleSlotTL ( PlanState planstate,
const TupleTableSlotOps tts_ops 
)

◆ ExecInitResultTypeTL()

◆ ExecInitScanTupleSlot()

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

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)

Definition at line 1457 of file execTuples.c.

1459{
1460 ListCell *lc;
1461
1462 foreach(lc, tupleTable)
1463 {
1465
1466 /* Always release resources and reset the slot to empty */
1467 ExecClearTuple(slot);
1468 slot->tts_ops->release(slot);
1469 if (slot->tts_tupleDescriptor)
1470 {
1472 slot->tts_tupleDescriptor = NULL;
1473 }
1474
1475 /* If shouldFree, release memory occupied by the slot itself */
1476 if (shouldFree)
1477 {
1478 if (!TTS_FIXED(slot))
1479 {
1480 if (slot->tts_values)
1481 pfree(slot->tts_values);
1482 if (slot->tts_isnull)
1483 pfree(slot->tts_isnull);
1484 }
1485 pfree(slot);
1486 }
1487 }
1488
1489 /* If shouldFree, release the list structure */
1490 if (shouldFree)
1492}
void list_free(List *list)
Definition list.c:1546
#define lfirst_node(type, lc)
Definition pg_list.h:176

References ExecClearTuple(), fb(), lfirst_node, list_free(), pfree(), TupleTableSlotOps::release, ReleaseTupleDesc, TTS_FIXED, TupleTableSlot::tts_isnull, TupleTableSlot::tts_ops, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by afterTriggerInvokeEvents(), CopyFrom(), EvalPlanQualEnd(), ExecEndPlan(), and finish_edata().

◆ ExecSetSlotDescriptor()

void ExecSetSlotDescriptor ( TupleTableSlot slot,
TupleDesc  tupdesc 
)

Definition at line 1555 of file execTuples.c.

1557{
1558 Assert(!TTS_FIXED(slot));
1559
1560 /* For safety, make sure slot is empty before changing it */
1561 ExecClearTuple(slot);
1562
1563 /*
1564 * Release any old descriptor. Also release old Datum/isnull arrays if
1565 * present (we don't bother to check if they could be re-used).
1566 */
1567 if (slot->tts_tupleDescriptor)
1569
1570 if (slot->tts_values)
1571 pfree(slot->tts_values);
1572 if (slot->tts_isnull)
1573 pfree(slot->tts_isnull);
1574
1575 /*
1576 * Install the new descriptor; if it's refcounted, bump its refcount.
1577 */
1578 slot->tts_tupleDescriptor = tupdesc;
1579 PinTupleDesc(tupdesc);
1580
1581 /*
1582 * Allocate Datum/isnull arrays of the appropriate size. These must have
1583 * the same lifetime as the slot, so allocate in the slot's own context.
1584 */
1585 slot->tts_values = (Datum *)
1586 MemoryContextAlloc(slot->tts_mcxt, tupdesc->natts * sizeof(Datum));
1587
1588 /*
1589 * We round the size of tts_isnull up to the next highest multiple of 8.
1590 * This is needed as populate_isnull_array() operates on 8 elements at a
1591 * time when converting a tuple's NULL bitmap into a boolean array.
1592 */
1593 slot->tts_isnull = (bool *)
1594 MemoryContextAlloc(slot->tts_mcxt, TYPEALIGN(8, tupdesc->natts * sizeof(bool)));
1595}
#define TYPEALIGN(ALIGNVAL, LEN)
Definition c.h:889
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1235
#define PinTupleDesc(tupdesc)
Definition tupdesc.h:234

References Assert, ExecClearTuple(), MemoryContextAlloc(), TupleDescData::natts, pfree(), PinTupleDesc, ReleaseTupleDesc, TTS_FIXED, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and TYPEALIGN.

Referenced by ExecAssignScanType(), ExecInitJunkFilter(), and ExecInitJunkFilterConversion().

◆ ExecStoreAllNullTuple()

TupleTableSlot * ExecStoreAllNullTuple ( TupleTableSlot slot)

Definition at line 1848 of file execTuples.c.

1849{
1850 /*
1851 * sanity checks
1852 */
1853 Assert(slot != NULL);
1855
1856 /* Clear any old contents */
1857 ExecClearTuple(slot);
1858
1859 /*
1860 * Fill all the columns of the virtual tuple with nulls
1861 */
1862 MemSet(slot->tts_values, 0,
1863 slot->tts_tupleDescriptor->natts * sizeof(Datum));
1864 memset(slot->tts_isnull, true,
1865 slot->tts_tupleDescriptor->natts * sizeof(bool));
1866
1867 return ExecStoreVirtualTuple(slot);
1868}
#define MemSet(start, val, len)
Definition c.h:1107

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

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

◆ ExecStoreBufferHeapTuple()

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

Definition at line 1664 of file execTuples.c.

1667{
1668 /*
1669 * sanity checks
1670 */
1671 Assert(tuple != NULL);
1672 Assert(slot != NULL);
1674 Assert(BufferIsValid(buffer));
1675
1676 if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1677 elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1678 tts_buffer_heap_store_tuple(slot, tuple, buffer, false);
1679
1680 slot->tts_tableOid = tuple->t_tableOid;
1681
1682 return slot;
1683}
static bool BufferIsValid(Buffer bufnum)
Definition bufmgr.h:419
#define unlikely(x)
Definition c.h:438
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
static void tts_buffer_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, Buffer buffer, bool transfer_pin)
Definition execTuples.c:944
Oid t_tableOid
Definition htup.h:66

References Assert, BufferIsValid(), elog, ERROR, fb(), HeapTupleData::t_tableOid, tts_buffer_heap_store_tuple(), TTS_IS_BUFFERTUPLE, TupleTableSlot::tts_tableOid, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by heap_getnextslot(), heap_getnextslot_tidrange(), heapam_index_build_range_scan(), heapam_index_fetch_tuple(), heapam_scan_analyze_next_tuple(), heapam_scan_bitmap_next_tuple(), and heapam_scan_sample_next_tuple().

◆ ExecStoreHeapTuple()

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

Definition at line 1624 of file execTuples.c.

1627{
1628 /*
1629 * sanity checks
1630 */
1631 Assert(tuple != NULL);
1632 Assert(slot != NULL);
1634
1635 if (unlikely(!TTS_IS_HEAPTUPLE(slot)))
1636 elog(ERROR, "trying to store a heap tuple into wrong type of slot");
1637 tts_heap_store_tuple(slot, tuple, shouldFree);
1638
1639 slot->tts_tableOid = tuple->t_tableOid;
1640
1641 return slot;
1642}
static void tts_heap_store_tuple(TupleTableSlot *slot, HeapTuple tuple, bool shouldFree)
Definition execTuples.c:487

References Assert, elog, ERROR, fb(), HeapTupleData::t_tableOid, tts_heap_store_tuple(), TTS_IS_HEAPTUPLE, TupleTableSlot::tts_tableOid, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by CatalogIndexInsert(), comparetup_cluster_tiebreak(), compute_expr_stats(), compute_index_stats(), ExecForceStoreHeapTuple(), ExecuteCallStmt(), get_returning_data(), heapam_index_validate_scan(), make_build_data(), pgoutput_change(), postgresIterateForeignScan(), repack_store_change(), ri_FastPathBatchFlush(), ri_FastPathFlushArray(), ri_FastPathFlushLoop(), and tts_heap_copyslot().

◆ ExecStoreHeapTupleDatum()

void ExecStoreHeapTupleDatum ( Datum  data,
TupleTableSlot slot 
)

Definition at line 1878 of file execTuples.c.

1879{
1880 HeapTupleData tuple = {0};
1881 HeapTupleHeader td;
1882
1884
1886 tuple.t_self = td->t_ctid;
1887 tuple.t_data = td;
1888
1889 ExecClearTuple(slot);
1890
1892 slot->tts_values, slot->tts_isnull);
1894}
#define DatumGetHeapTupleHeader(X)
Definition fmgr.h:296
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
const void * data
ItemPointerData t_self
Definition htup.h:65
ItemPointerData t_ctid

References data, DatumGetHeapTupleHeader, ExecClearTuple(), ExecStoreVirtualTuple(), heap_deform_tuple(), HeapTupleHeaderGetDatumLength(), HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by EvalPlanQualFetchRowMark().

◆ ExecStoreMinimalTuple()

◆ ExecStorePinnedBufferHeapTuple()

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

Definition at line 1690 of file execTuples.c.

1693{
1694 /*
1695 * sanity checks
1696 */
1697 Assert(tuple != NULL);
1698 Assert(slot != NULL);
1700 Assert(BufferIsValid(buffer));
1701
1702 if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1703 elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1704 tts_buffer_heap_store_tuple(slot, tuple, buffer, true);
1705
1706 slot->tts_tableOid = tuple->t_tableOid;
1707
1708 return slot;
1709}

References Assert, BufferIsValid(), elog, ERROR, fb(), HeapTupleData::t_tableOid, tts_buffer_heap_store_tuple(), TTS_IS_BUFFERTUPLE, TupleTableSlot::tts_tableOid, TupleTableSlot::tts_tupleDescriptor, and unlikely.

Referenced by heapam_fetch_row_version(), and heapam_tuple_lock().

◆ ExecStoreVirtualTuple()

TupleTableSlot * ExecStoreVirtualTuple ( TupleTableSlot slot)

Definition at line 1824 of file execTuples.c.

1825{
1826 /*
1827 * sanity checks
1828 */
1829 Assert(slot != NULL);
1831 Assert(TTS_EMPTY(slot));
1832
1833 slot->tts_flags &= ~TTS_FLAG_EMPTY;
1834 slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
1835
1836 return slot;
1837}
AttrNumber tts_nvalid
Definition tuptable.h:126

References Assert, fb(), TupleDescData::natts, TTS_EMPTY, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, and TupleTableSlot::tts_tupleDescriptor.

Referenced by agg_retrieve_hash_table_in_memory(), apply_returning_filter(), ATRewriteTable(), CopyFrom(), copyTemplateDependencies(), DefineTSConfiguration(), do_tup_output(), EnumValuesCreate(), ExecComputeStoredGenerated(), ExecEvalAggOrderedTransTuple(), ExecEvalPreOrderedDistinctMulti(), ExecFilterJunk(), ExecForceStoreHeapTuple(), ExecForceStoreMinimalTuple(), ExecProjectSRF(), ExecSort(), ExecStoreAllNullTuple(), ExecStoreHeapTupleDatum(), execute_attr_map_slot(), fileIterateForeignScan(), FunctionNext(), hashagg_spill_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), InsertPgAttributeTuples(), MakeConfigurationMapping(), MergePartitionsMoveRows(), ordered_set_transition_multi(), pgoutput_row_filter(), prepare_hash_slot(), prepare_probe_slot(), recordMultipleDependencies(), RI_Initial_Check(), RI_PartitionRemove_Check(), slot_modify_data(), slot_store_data(), SplitPartitionMoveRows(), StoreIndexTuple(), and ValuesNext().

◆ ExecTypeFromExprList()

TupleDesc ExecTypeFromExprList ( List exprList)

Definition at line 2266 of file execTuples.c.

2267{
2269 ListCell *lc;
2270 int cur_resno = 1;
2271
2273
2274 foreach(lc, exprList)
2275 {
2276 Node *e = lfirst(lc);
2277
2279 cur_resno,
2280 NULL,
2281 exprType(e),
2282 exprTypmod(e),
2283 0);
2285 cur_resno,
2286 exprCollation(e));
2287 cur_resno++;
2288 }
2289
2291
2292 return typeInfo;
2293}
Oid exprType(const Node *expr)
Definition nodeFuncs.c:42
int32 exprTypmod(const Node *expr)
Definition nodeFuncs.c:304
Oid exprCollation(const Node *expr)
Definition nodeFuncs.c:826
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
e
Definition nodes.h:135
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition tupdesc.c:1093
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:909

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

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

◆ ExecTypeFromTL()

◆ ExecTypeFromTLInternal()

static TupleDesc ExecTypeFromTLInternal ( List targetList,
bool  skipjunk 
)
static

Definition at line 2223 of file execTuples.c.

2224{
2226 ListCell *l;
2227 int len;
2228 int cur_resno = 1;
2229
2230 if (skipjunk)
2231 len = ExecCleanTargetListLength(targetList);
2232 else
2233 len = ExecTargetListLength(targetList);
2235
2236 foreach(l, targetList)
2237 {
2238 TargetEntry *tle = lfirst(l);
2239
2240 if (skipjunk && tle->resjunk)
2241 continue;
2243 cur_resno,
2244 tle->resname,
2245 exprType((Node *) tle->expr),
2246 exprTypmod((Node *) tle->expr),
2247 0);
2249 cur_resno,
2250 exprCollation((Node *) tle->expr));
2251 cur_resno++;
2252 }
2253
2255
2256 return typeInfo;
2257}
int ExecTargetListLength(List *targetlist)
Definition execUtils.c:1201
int ExecCleanTargetListLength(List *targetlist)
Definition execUtils.c:1211

References CreateTemplateTupleDesc(), ExecCleanTargetListLength(), ExecTargetListLength(), exprCollation(), exprType(), exprTypmod(), fb(), len, lfirst, TupleDescFinalize(), TupleDescInitEntry(), and TupleDescInitEntryCollation().

Referenced by ExecCleanTypeFromTL(), and ExecTypeFromTL().

◆ ExecTypeSetColNames()

void ExecTypeSetColNames ( TupleDesc  typeInfo,
List namesList 
)

Definition at line 2301 of file execTuples.c.

2302{
2303 int colno = 0;
2304 ListCell *lc;
2305
2306 /* It's only OK to change col names in a not-yet-blessed RECORD type */
2307 Assert(typeInfo->tdtypeid == RECORDOID);
2308 Assert(typeInfo->tdtypmod < 0);
2309
2310 foreach(lc, namesList)
2311 {
2312 char *cname = strVal(lfirst(lc));
2313 Form_pg_attribute attr;
2314
2315 /* Guard against too-long names list (probably can't happen) */
2316 if (colno >= typeInfo->natts)
2317 break;
2318 attr = TupleDescAttr(typeInfo, colno);
2319 colno++;
2320
2321 /*
2322 * Do nothing for empty aliases or dropped columns (these cases
2323 * probably can't arise in RECORD types, either)
2324 */
2325 if (cname[0] == '\0' || attr->attisdropped)
2326 continue;
2327
2328 /* OK, assign the column name */
2329 namestrcpy(&(attr->attname), cname);
2330 }
2331}
void namestrcpy(Name name, const char *str)
Definition name.c:233
FormData_pg_attribute * Form_pg_attribute
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178
#define strVal(v)
Definition value.h:82

References Assert, fb(), lfirst, namestrcpy(), strVal, and TupleDescAttr().

Referenced by ExecEvalWholeRowVar(), and ExecInitExprRec().

◆ HeapTupleHeaderGetDatum()

Datum HeapTupleHeaderGetDatum ( HeapTupleHeader  tuple)

Definition at line 2501 of file execTuples.c.

2502{
2503 Datum result;
2504 TupleDesc tupDesc;
2505
2506 /* No work if there are no external TOAST pointers in the tuple */
2507 if (!HeapTupleHeaderHasExternal(tuple))
2508 return PointerGetDatum(tuple);
2509
2510 /* Use the type data saved by heap_form_tuple to look up the rowtype */
2513
2514 /* And do the flattening */
2517 tupDesc);
2518
2519 ReleaseTupleDesc(tupDesc);
2520
2521 return result;
2522}
uint32 result
Datum toast_flatten_tuple_to_datum(HeapTupleHeader tup, uint32 tup_len, TupleDesc tupleDesc)
Definition heaptoast.c:449
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
#define HeapTupleHeaderHasExternal(tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition typcache.c:1940

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

Referenced by HeapTupleGetDatum(), populate_composite(), and populate_recordset_record().

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

TupleTableSlot * MakeTupleTableSlot ( TupleDesc  tupleDesc,
const TupleTableSlotOps tts_ops,
uint16  flags 
)

Definition at line 1358 of file execTuples.c.

1360{
1361 Size basesz,
1362 allocsz;
1363 TupleTableSlot *slot;
1364
1365 basesz = tts_ops->base_slot_size;
1366
1367 /* Ensure callers don't have any way to set transient flags permanently */
1368 flags &= ~TTS_FLAGS_TRANSIENT;
1369
1370 /*
1371 * When a fixed descriptor is specified, we can reduce overhead by
1372 * allocating the entire slot in one go.
1373 *
1374 * We round the size of tts_isnull up to the next highest multiple of 8.
1375 * This is needed as populate_isnull_array() operates on 8 elements at a
1376 * time when converting a tuple's NULL bitmap into a boolean array.
1377 */
1378 if (tupleDesc)
1380 MAXALIGN(tupleDesc->natts * sizeof(Datum)) +
1381 TYPEALIGN(8, tupleDesc->natts * sizeof(bool));
1382 else
1383 allocsz = basesz;
1384
1385 slot = palloc0(allocsz);
1386 /* const for optimization purposes, OK to modify at allocation time */
1387 *((const TupleTableSlotOps **) &slot->tts_ops) = tts_ops;
1388 slot->type = T_TupleTableSlot;
1389 slot->tts_flags = TTS_FLAG_EMPTY | flags;
1390 if (tupleDesc != NULL)
1391 slot->tts_flags |= TTS_FLAG_FIXED;
1394 slot->tts_nvalid = 0;
1395
1396 if (tupleDesc != NULL)
1397 {
1398 slot->tts_values = (Datum *)
1399 (((char *) slot)
1400 + MAXALIGN(basesz));
1401
1402 slot->tts_isnull = (bool *)
1403 (((char *) slot)
1404 + MAXALIGN(basesz)
1405 + MAXALIGN(tupleDesc->natts * sizeof(Datum)));
1406
1408
1409 /*
1410 * Precalculate the maximum guaranteed attribute that has to exist in
1411 * every tuple which gets deformed into this slot. When the
1412 * TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS flag is enabled, we simply take
1413 * the pre-calculated value from the tupleDesc, otherwise the
1414 * optimization is disabled, and we set the value to 0.
1415 */
1416 if ((flags & TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS) != 0)
1417 slot->tts_first_nonguaranteed = tupleDesc->firstNonGuaranteedAttr;
1418 else
1419 slot->tts_first_nonguaranteed = 0;
1420 }
1421
1422 /*
1423 * And allow slot type specific initialization.
1424 */
1425 slot->tts_ops->init(slot);
1426
1427 return slot;
1428}
#define MAXALIGN(LEN)
Definition c.h:896
size_t Size
Definition c.h:689
void * palloc0(Size size)
Definition mcxt.c:1420
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
size_t base_slot_size
Definition tuptable.h:150
void(* init)(TupleTableSlot *slot)
Definition tuptable.h:153
NodeTag type
Definition tuptable.h:122
int tts_first_nonguaranteed
Definition tuptable.h:136
#define TTS_FLAG_EMPTY
Definition tuptable.h:91
#define TTS_FLAG_FIXED
Definition tuptable.h:107
#define TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS
Definition tuptable.h:102

References TupleTableSlotOps::base_slot_size, CurrentMemoryContext, fb(), TupleTableSlotOps::init, MAXALIGN, palloc0(), PinTupleDesc, TupleTableSlot::tts_first_nonguaranteed, TTS_FLAG_EMPTY, TTS_FLAG_FIXED, TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_ops, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleTableSlot::type, and TYPEALIGN.

Referenced by ExecAllocTableSlot(), ExecConstraints(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), MakeSingleTupleTableSlot(), pgoutput_change(), and ReportNotNullViolationError().

◆ slot_deform_heap_tuple()

static pg_attribute_always_inline void slot_deform_heap_tuple ( TupleTableSlot slot,
HeapTuple  tuple,
uint32 offp,
int  reqnatts,
bool  support_cstring 
)
static

Definition at line 1017 of file execTuples.c.

1019{
1023 HeapTupleHeader tup = tuple->t_data;
1024 size_t attnum;
1026 int firstNonGuaranteedAttr;
1027 int firstNullAttr;
1028 int natts;
1029 Datum *values;
1030 bool *isnull;
1031 char *tp; /* ptr to tuple data */
1032 uint32 off; /* offset in tuple data */
1033
1034 /* Did someone forget to call TupleDescFinalize()? */
1035 Assert(tupleDesc->firstNonCachedOffsetAttr >= 0);
1036
1037 isnull = slot->tts_isnull;
1038
1039 /*
1040 * Some callers may form and deform tuples prior to NOT NULL constraints
1041 * being checked. Here we'd like to optimize the case where we only need
1042 * to fetch attributes before or up to the point where the attribute is
1043 * guaranteed to exist in the tuple. We rely on the slot flag being set
1044 * correctly to only enable this optimization when it's valid to do so.
1045 * This optimization allows us to save fetching the number of attributes
1046 * from the tuple and saves the additional cost of handling non-byval
1047 * attrs.
1048 */
1049 firstNonGuaranteedAttr = Min(reqnatts, slot->tts_first_nonguaranteed);
1050
1051 firstNonCacheOffsetAttr = tupleDesc->firstNonCachedOffsetAttr;
1052
1053 if (HeapTupleHasNulls(tuple))
1054 {
1056 tp = (char *) tup + MAXALIGN(offsetof(HeapTupleHeaderData, t_bits) +
1057 BITMAPLEN(natts));
1058
1059 natts = Min(natts, reqnatts);
1060 if (natts > firstNonGuaranteedAttr)
1061 {
1062 uint8 *bp = tup->t_bits;
1063
1064 /* Find the first NULL attr */
1066
1067 /*
1068 * And populate the isnull array for all attributes being fetched
1069 * from the tuple.
1070 */
1071 populate_isnull_array(bp, natts, isnull);
1072 }
1073 else
1074 {
1075 /* Otherwise all required columns are guaranteed to exist */
1076 firstNullAttr = natts;
1077
1078 /*
1079 * Check TupleDescFinalize() didn't get confused when setting
1080 * firstNonGuaranteedAttr. There should never be a NULL in a
1081 * guaranteed column.
1082 */
1083 Assert(first_null_attr(tup->t_bits, natts) >= firstNullAttr);
1084 }
1085 }
1086 else
1087 {
1088 tp = (char *) tup + MAXALIGN(offsetof(HeapTupleHeaderData, t_bits));
1089
1090 /*
1091 * We only need to look at the tuple's natts if we need more than the
1092 * guaranteed number of columns
1093 */
1094 if (reqnatts > firstNonGuaranteedAttr)
1096 else
1097 {
1098 /* No need to access the number of attributes in the tuple */
1099 natts = reqnatts;
1100 }
1101
1102 /* All attrs can be fetched without checking for NULLs */
1103 firstNullAttr = natts;
1104 }
1105
1106 attnum = slot->tts_nvalid;
1107 values = slot->tts_values;
1108 slot->tts_nvalid = reqnatts;
1109
1110 /*
1111 * We store the tupleDesc's CompactAttribute array in 'cattrs' as gcc
1112 * seems to be unwilling to optimize accessing the CompactAttribute
1113 * element efficiently when accessing it via TupleDescCompactAttr().
1114 */
1115 cattrs = tupleDesc->compact_attrs;
1116
1117 /* Ensure we calculated tp correctly */
1118 Assert(tp == (char *) tup + tup->t_hoff);
1119
1120 if (attnum < firstNonGuaranteedAttr)
1121 {
1122 int attlen;
1123
1124 do
1125 {
1126 isnull[attnum] = false;
1127 cattr = &cattrs[attnum];
1128 attlen = cattr->attlen;
1129
1130 /* We don't expect any non-byval types */
1131 pg_assume(attlen > 0);
1132 Assert(cattr->attbyval == true);
1133
1134 off = cattr->attcacheoff;
1135 values[attnum] = fetch_att_noerr(tp + off, true, attlen);
1136 attnum++;
1137 } while (attnum < firstNonGuaranteedAttr);
1138
1139 off += attlen;
1140
1141 if (attnum == reqnatts)
1142 goto done;
1143 }
1144 else
1145 {
1146 /*
1147 * We may be incrementally deforming the tuple, so set 'off' to the
1148 * previously cached value. This may be 0, if the slot has just
1149 * received a new tuple.
1150 */
1151 off = *offp;
1152
1153 /* We expect *offp to be set to 0 when attnum == 0 */
1154 Assert(off == 0 || attnum > 0);
1155 }
1156
1157 /* We can use attcacheoff up until the first NULL */
1159
1160 /*
1161 * Handle the portion of the tuple that we have cached the offset for up
1162 * to the first NULL attribute. The offset is effectively fixed for
1163 * these, so we can use the CompactAttribute's attcacheoff.
1164 */
1166 {
1167 int attlen;
1168
1169 do
1170 {
1171 isnull[attnum] = false;
1172 cattr = &cattrs[attnum];
1173 attlen = cattr->attlen;
1174 off = cattr->attcacheoff;
1175 values[attnum] = fetch_att_noerr(tp + off,
1176 cattr->attbyval,
1177 attlen);
1178 attnum++;
1179 } while (attnum < firstNonCacheOffsetAttr);
1180
1181 /*
1182 * Point the offset after the end of the last attribute with a cached
1183 * offset. We expect the final cached offset attribute to have a
1184 * fixed width, so just add the attlen to the attcacheoff
1185 */
1186 Assert(attlen > 0);
1187 off += attlen;
1188 }
1189
1190 /*
1191 * Handle any portion of the tuple that doesn't have a fixed offset up
1192 * until the first NULL attribute. This loop only differs from the one
1193 * after it by the NULL checks.
1194 */
1195 for (; attnum < firstNullAttr; attnum++)
1196 {
1197 int attlen;
1198
1199 isnull[attnum] = false;
1200 cattr = &cattrs[attnum];
1201 attlen = cattr->attlen;
1202
1203 /*
1204 * Only emit the cstring-related code in align_fetch_then_add() when
1205 * cstring support is needed. We assume support_cstring will be
1206 * passed as a const to allow the compiler to eliminate this branch.
1207 */
1208 if (!support_cstring)
1209 pg_assume(attlen > 0 || attlen == -1);
1210
1211 /* align 'off', fetch the datum, and increment off beyond the datum */
1213 &off,
1214 cattr->attbyval,
1215 attlen,
1216 cattr->attalignby);
1217 }
1218
1219 /*
1220 * Now handle any remaining attributes in the tuple up to the requested
1221 * attnum. This time, include NULL checks as we're now at the first NULL
1222 * attribute.
1223 */
1224 for (; attnum < natts; attnum++)
1225 {
1226 int attlen;
1227
1228 if (isnull[attnum])
1229 {
1230 values[attnum] = (Datum) 0;
1231 continue;
1232 }
1233
1234 cattr = &cattrs[attnum];
1235 attlen = cattr->attlen;
1236
1237 /* As above, only emit cstring code when needed. */
1238 if (!support_cstring)
1239 pg_assume(attlen > 0 || attlen == -1);
1240
1241 /* align 'off', fetch the datum, and increment off beyond the datum */
1243 &off,
1244 cattr->attbyval,
1245 attlen,
1246 cattr->attalignby);
1247 }
1248
1249 /* Fetch any missing attrs and raise an error if reqnatts is invalid */
1250 if (unlikely(attnum < reqnatts))
1251 {
1252 /*
1253 * Cache the offset before calling the function to allow the compiler
1254 * to implement a tail-call optimization
1255 */
1256 *offp = off;
1258 return;
1259 }
1260done:
1261
1262 /* Save current offset for next execution */
1263 *offp = off;
1264}
#define Min(x, y)
Definition c.h:1091
uint8_t uint8
Definition c.h:622
#define pg_assume(expr)
Definition c.h:423
uint32_t uint32
Definition c.h:624
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
#define HeapTupleHeaderGetNatts(tup)
static bool HeapTupleHasNulls(const HeapTupleData *tuple)
static int BITMAPLEN(int NATTS)
int16 attnum
int16 attlen
static void populate_isnull_array(const uint8 *bits, int natts, bool *isnull)
Definition tupmacs.h:43
static Datum align_fetch_then_add(const char *tupptr, uint32 *off, bool attbyval, int attlen, uint8 attalignby)
Definition tupmacs.h:172
static Datum fetch_att_noerr(const void *T, bool attbyval, int attlen)
Definition tupmacs.h:137
static int first_null_attr(const uint8 *bits, int natts)
Definition tupmacs.h:244

References align_fetch_then_add(), Assert, attlen, attnum, BITMAPLEN(), fb(), fetch_att_noerr(), first_null_attr(), HeapTupleHasNulls(), HeapTupleHeaderGetNatts, MAXALIGN, Min, pg_assume, populate_isnull_array(), slot_getmissingattrs(), HeapTupleData::t_data, TupleTableSlot::tts_first_nonguaranteed, TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, unlikely, and values.

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

◆ slot_getmissingattrs()

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

Definition at line 2141 of file execTuples.c.

2142{
2144
2145 /* Check for invalid attnums */
2147 elog(ERROR, "invalid attribute number %d", lastAttNum);
2148
2149 if (slot->tts_tupleDescriptor->constr)
2151
2152 if (!attrmiss)
2153 {
2154 /* no missing values array at all, so just fill everything in as NULL */
2155 for (int attnum = startAttNum; attnum < lastAttNum; attnum++)
2156 {
2157 slot->tts_values[attnum] = (Datum) 0;
2158 slot->tts_isnull[attnum] = true;
2159 }
2160 }
2161 else
2162 {
2163 /* use attrmiss to set the missing values */
2164 for (int attnum = startAttNum; attnum < lastAttNum; attnum++)
2165 {
2166 slot->tts_values[attnum] = attrmiss[attnum].am_value;
2167 slot->tts_isnull[attnum] = !attrmiss[attnum].am_present;
2168 }
2169 }
2170}
struct AttrMissing * missing
Definition tupdesc.h:42
TupleConstr * constr
Definition tupdesc.h:159

References attnum, TupleDescData::constr, elog, ERROR, fb(), TupleConstr::missing, TupleDescData::natts, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and unlikely.

Referenced by slot_deform_heap_tuple().

◆ slot_getsomeattrs_int()

void slot_getsomeattrs_int ( TupleTableSlot slot,
int  attnum 
)

Definition at line 2177 of file execTuples.c.

2178{
2179 /* Check for caller errors */
2180 Assert(slot->tts_nvalid < attnum); /* checked in slot_getsomeattrs */
2181 Assert(attnum > 0);
2182
2183 /* Fetch as many attributes as possible from the underlying tuple. */
2184 slot->tts_ops->getsomeattrs(slot, attnum);
2185
2186 /*
2187 * Avoid putting new code here as that would prevent the compiler from
2188 * using the sibling call optimization for the above function.
2189 */
2190}
void(* getsomeattrs)(TupleTableSlot *slot, int natts)
Definition tuptable.h:175

References Assert, attnum, TupleTableSlotOps::getsomeattrs, TupleTableSlot::tts_nvalid, and TupleTableSlot::tts_ops.

◆ tts_buffer_heap_clear()

static void tts_buffer_heap_clear ( TupleTableSlot slot)
static

Definition at line 721 of file execTuples.c.

722{
724
725 /*
726 * Free the memory for heap tuple if allowed. A tuple coming from buffer
727 * can never be freed. But we may have materialized a tuple from buffer.
728 * Such a tuple can be freed.
729 */
730 if (TTS_SHOULDFREE(slot))
731 {
732 /* We should have unpinned the buffer while materializing the tuple. */
733 Assert(!BufferIsValid(bslot->buffer));
734
735 heap_freetuple(bslot->base.tuple);
737 }
738
739 if (BufferIsValid(bslot->buffer))
740 ReleaseBuffer(bslot->buffer);
741
742 slot->tts_nvalid = 0;
743 slot->tts_flags |= TTS_FLAG_EMPTY;
745 bslot->base.tuple = NULL;
746 bslot->base.off = 0;
747 bslot->buffer = InvalidBuffer;
748}
#define InvalidBuffer
Definition buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5595
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1372
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition itemptr.h:184
ItemPointerData tts_tid
Definition tuptable.h:142
#define TTS_SHOULDFREE(slot)
Definition tuptable.h:96

References Assert, BufferIsValid(), fb(), heap_freetuple(), InvalidBuffer, ItemPointerSetInvalid(), ReleaseBuffer(), TTS_FLAG_EMPTY, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

◆ tts_buffer_heap_copy_heap_tuple()

static HeapTuple tts_buffer_heap_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 918 of file execTuples.c.

919{
921
922 Assert(!TTS_EMPTY(slot));
923
924 if (!bslot->base.tuple)
926
927 return heap_copytuple(bslot->base.tuple);
928}
static void tts_buffer_heap_materialize(TupleTableSlot *slot)
Definition execTuples.c:804

References Assert, fb(), heap_copytuple(), tts_buffer_heap_materialize(), and TTS_EMPTY.

◆ tts_buffer_heap_copy_minimal_tuple()

static MinimalTuple tts_buffer_heap_copy_minimal_tuple ( TupleTableSlot slot,
Size  extra 
)
static

Definition at line 931 of file execTuples.c.

932{
934
935 Assert(!TTS_EMPTY(slot));
936
937 if (!bslot->base.tuple)
939
940 return minimal_tuple_from_heap_tuple(bslot->base.tuple, extra);
941}
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup, Size extra)
Definition heaptuple.c:1523

References Assert, fb(), minimal_tuple_from_heap_tuple(), tts_buffer_heap_materialize(), and TTS_EMPTY.

◆ tts_buffer_heap_copyslot()

static void tts_buffer_heap_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 863 of file execTuples.c.

864{
867
868 /*
869 * If the source slot is of a different kind, or is a buffer slot that has
870 * been materialized / is virtual, make a new copy of the tuple. Otherwise
871 * make a new reference to the in-buffer tuple.
872 */
873 if (dstslot->tts_ops != srcslot->tts_ops ||
875 !bsrcslot->base.tuple)
876 {
878
879 ExecClearTuple(dstslot);
880 dstslot->tts_flags &= ~TTS_FLAG_EMPTY;
883 dstslot->tts_flags |= TTS_FLAG_SHOULDFREE;
885 }
886 else
887 {
888 Assert(BufferIsValid(bsrcslot->buffer));
889
890 tts_buffer_heap_store_tuple(dstslot, bsrcslot->base.tuple,
891 bsrcslot->buffer, false);
892
893 /*
894 * The HeapTupleData portion of the source tuple might be shorter
895 * lived than the destination slot. Therefore copy the HeapTuple into
896 * our slot's tupdata, which is guaranteed to live long enough (but
897 * will still point into the buffer).
898 */
899 memcpy(&bdstslot->base.tupdata, bdstslot->base.tuple, sizeof(HeapTupleData));
900 bdstslot->base.tuple = &bdstslot->base.tupdata;
901 }
902}
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition tuptable.h:504

References Assert, BufferIsValid(), ExecClearTuple(), ExecCopySlotHeapTuple(), fb(), memcpy(), MemoryContextSwitchTo(), tts_buffer_heap_store_tuple(), TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_ops, and TTS_SHOULDFREE.

◆ tts_buffer_heap_get_heap_tuple()

static HeapTuple tts_buffer_heap_get_heap_tuple ( TupleTableSlot slot)
static

Definition at line 905 of file execTuples.c.

906{
908
909 Assert(!TTS_EMPTY(slot));
910
911 if (!bslot->base.tuple)
913
914 return bslot->base.tuple;
915}

References Assert, fb(), tts_buffer_heap_materialize(), and TTS_EMPTY.

◆ tts_buffer_heap_getsomeattrs()

static void tts_buffer_heap_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 751 of file execTuples.c.

752{
754
755 Assert(!TTS_EMPTY(slot));
756
757 slot_deform_heap_tuple(slot, bslot->base.tuple, &bslot->base.off, natts, false);
758}
static pg_attribute_always_inline void slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp, int reqnatts, bool support_cstring)

References Assert, fb(), slot_deform_heap_tuple(), and TTS_EMPTY.

◆ tts_buffer_heap_getsysattr()

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

Definition at line 761 of file execTuples.c.

762{
764
765 Assert(!TTS_EMPTY(slot));
766
767 /*
768 * In some code paths it's possible to get here with a non-materialized
769 * slot, in which case we can't retrieve system columns.
770 */
771 if (!bslot->base.tuple)
774 errmsg("cannot retrieve a system column in this context")));
775
776 return heap_getsysattr(bslot->base.tuple, attnum,
777 slot->tts_tupleDescriptor, isnull);
778}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition heaptuple.c:633
static char * errmsg

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

◆ tts_buffer_heap_init()

static void tts_buffer_heap_init ( TupleTableSlot slot)
static

Definition at line 711 of file execTuples.c.

712{
713}

◆ tts_buffer_heap_materialize()

static void tts_buffer_heap_materialize ( TupleTableSlot slot)
static

Definition at line 804 of file execTuples.c.

805{
808
809 Assert(!TTS_EMPTY(slot));
810
811 /* If slot has its tuple already materialized, nothing to do. */
812 if (TTS_SHOULDFREE(slot))
813 return;
814
816
817 /*
818 * Have to deform from scratch, otherwise tts_values[] entries could point
819 * into the non-materialized tuple (which might be gone when accessed).
820 */
821 bslot->base.off = 0;
822 slot->tts_nvalid = 0;
823
824 if (!bslot->base.tuple)
825 {
826 /*
827 * Normally BufferHeapTupleTableSlot should have a tuple + buffer
828 * associated with it, unless it's materialized (which would've
829 * returned above). But when it's useful to allow storing virtual
830 * tuples in a buffer slot, which then also needs to be
831 * materializable.
832 */
833 bslot->base.tuple = heap_form_tuple(slot->tts_tupleDescriptor,
834 slot->tts_values,
835 slot->tts_isnull);
836 }
837 else
838 {
839 bslot->base.tuple = heap_copytuple(bslot->base.tuple);
840
841 /*
842 * A heap tuple stored in a BufferHeapTupleTableSlot should have a
843 * buffer associated with it, unless it's materialized or virtual.
844 */
845 if (likely(BufferIsValid(bslot->buffer)))
846 ReleaseBuffer(bslot->buffer);
847 bslot->buffer = InvalidBuffer;
848 }
849
850 /*
851 * We don't set TTS_FLAG_SHOULDFREE until after releasing the buffer, if
852 * any. This avoids having a transient state that would fall foul of our
853 * assertions that a slot with TTS_FLAG_SHOULDFREE doesn't own a buffer.
854 * In the unlikely event that ReleaseBuffer() above errors out, we'd
855 * effectively leak the copied tuple, but that seems fairly harmless.
856 */
858
860}
#define likely(x)
Definition c.h:437

References Assert, BufferIsValid(), fb(), heap_copytuple(), heap_form_tuple(), InvalidBuffer, likely, MemoryContextSwitchTo(), ReleaseBuffer(), TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by tts_buffer_heap_copy_heap_tuple(), tts_buffer_heap_copy_minimal_tuple(), and tts_buffer_heap_get_heap_tuple().

◆ tts_buffer_heap_release()

static void tts_buffer_heap_release ( TupleTableSlot slot)
static

Definition at line 716 of file execTuples.c.

717{
718}

◆ tts_buffer_heap_store_tuple()

static void tts_buffer_heap_store_tuple ( TupleTableSlot slot,
HeapTuple  tuple,
Buffer  buffer,
bool  transfer_pin 
)
inlinestatic

Definition at line 944 of file execTuples.c.

946{
948
949 if (TTS_SHOULDFREE(slot))
950 {
951 /* materialized slot shouldn't have a buffer to release */
952 Assert(!BufferIsValid(bslot->buffer));
953
954 heap_freetuple(bslot->base.tuple);
956 }
957
958 slot->tts_flags &= ~TTS_FLAG_EMPTY;
959 slot->tts_nvalid = 0;
960 bslot->base.tuple = tuple;
961 bslot->base.off = 0;
962 slot->tts_tid = tuple->t_self;
963
964 /*
965 * If tuple is on a disk page, keep the page pinned as long as we hold a
966 * pointer into it. We assume the caller already has such a pin. If
967 * transfer_pin is true, we'll transfer that pin to this slot, if not
968 * we'll pin it again ourselves.
969 *
970 * This is coded to optimize the case where the slot previously held a
971 * tuple on the same disk page: in that case releasing and re-acquiring
972 * the pin is a waste of cycles. This is a common situation during
973 * seqscans, so it's worth troubling over.
974 */
975 if (bslot->buffer != buffer)
976 {
977 if (BufferIsValid(bslot->buffer))
978 ReleaseBuffer(bslot->buffer);
979
980 bslot->buffer = buffer;
981
982 if (!transfer_pin && BufferIsValid(buffer))
983 IncrBufferRefCount(buffer);
984 }
985 else if (transfer_pin && BufferIsValid(buffer))
986 {
987 /*
988 * In transfer_pin mode the caller won't know about the same-page
989 * optimization, so we gotta release its pin.
990 */
991 ReleaseBuffer(buffer);
992 }
993}
void IncrBufferRefCount(Buffer buffer)
Definition bufmgr.c:5679

References Assert, BufferIsValid(), fb(), heap_freetuple(), IncrBufferRefCount(), ReleaseBuffer(), HeapTupleData::t_self, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

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

◆ tts_buffer_is_current_xact_tuple()

static bool tts_buffer_is_current_xact_tuple ( TupleTableSlot slot)
static

Definition at line 781 of file execTuples.c.

782{
784 TransactionId xmin;
785
786 Assert(!TTS_EMPTY(slot));
787
788 /*
789 * In some code paths it's possible to get here with a non-materialized
790 * slot, in which case we can't check if tuple is created by the current
791 * transaction.
792 */
793 if (!bslot->base.tuple)
796 errmsg("don't have a storage tuple in this context")));
797
798 xmin = HeapTupleHeaderGetRawXmin(bslot->base.tuple->t_data);
799
801}
uint32 TransactionId
Definition c.h:736
static TransactionId HeapTupleHeaderGetRawXmin(const HeapTupleHeaderData *tup)
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
Definition xact.c:943

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

◆ tts_heap_clear()

static void tts_heap_clear ( TupleTableSlot slot)
static

Definition at line 327 of file execTuples.c.

328{
330
331 /* Free the memory for the heap tuple if it's allowed. */
332 if (TTS_SHOULDFREE(slot))
333 {
334 heap_freetuple(hslot->tuple);
336 }
337
338 slot->tts_nvalid = 0;
339 slot->tts_flags |= TTS_FLAG_EMPTY;
341 hslot->off = 0;
342 hslot->tuple = NULL;
343}

References fb(), heap_freetuple(), ItemPointerSetInvalid(), TTS_FLAG_EMPTY, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

Referenced by tts_heap_store_tuple().

◆ tts_heap_copy_heap_tuple()

static HeapTuple tts_heap_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 464 of file execTuples.c.

465{
467
468 Assert(!TTS_EMPTY(slot));
469 if (!hslot->tuple)
471
472 return heap_copytuple(hslot->tuple);
473}
static void tts_heap_materialize(TupleTableSlot *slot)
Definition execTuples.c:399

References Assert, fb(), heap_copytuple(), TTS_EMPTY, and tts_heap_materialize().

◆ tts_heap_copy_minimal_tuple()

static MinimalTuple tts_heap_copy_minimal_tuple ( TupleTableSlot slot,
Size  extra 
)
static

Definition at line 476 of file execTuples.c.

477{
479
480 if (!hslot->tuple)
482
483 return minimal_tuple_from_heap_tuple(hslot->tuple, extra);
484}

References fb(), minimal_tuple_from_heap_tuple(), and tts_heap_materialize().

◆ tts_heap_copyslot()

static void tts_heap_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 439 of file execTuples.c.

440{
441 HeapTuple tuple;
442 MemoryContext oldcontext;
443
444 oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt);
446 MemoryContextSwitchTo(oldcontext);
447
448 ExecStoreHeapTuple(tuple, dstslot, true);
449}

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

◆ tts_heap_get_heap_tuple()

static HeapTuple tts_heap_get_heap_tuple ( TupleTableSlot slot)
static

Definition at line 452 of file execTuples.c.

453{
455
456 Assert(!TTS_EMPTY(slot));
457 if (!hslot->tuple)
459
460 return hslot->tuple;
461}

References Assert, fb(), TTS_EMPTY, and tts_heap_materialize().

◆ tts_heap_getsomeattrs()

static void tts_heap_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 346 of file execTuples.c.

347{
349
350 Assert(!TTS_EMPTY(slot));
351
352 slot_deform_heap_tuple(slot, hslot->tuple, &hslot->off, natts, false);
353}

References Assert, fb(), slot_deform_heap_tuple(), and TTS_EMPTY.

◆ tts_heap_getsysattr()

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

Definition at line 356 of file execTuples.c.

357{
359
360 Assert(!TTS_EMPTY(slot));
361
362 /*
363 * In some code paths it's possible to get here with a non-materialized
364 * slot, in which case we can't retrieve system columns.
365 */
366 if (!hslot->tuple)
369 errmsg("cannot retrieve a system column in this context")));
370
371 return heap_getsysattr(hslot->tuple, attnum,
372 slot->tts_tupleDescriptor, isnull);
373}

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

◆ tts_heap_init()

static void tts_heap_init ( TupleTableSlot slot)
static

Definition at line 317 of file execTuples.c.

318{
319}

◆ tts_heap_is_current_xact_tuple()

static bool tts_heap_is_current_xact_tuple ( TupleTableSlot slot)
static

Definition at line 376 of file execTuples.c.

377{
379 TransactionId xmin;
380
381 Assert(!TTS_EMPTY(slot));
382
383 /*
384 * In some code paths it's possible to get here with a non-materialized
385 * slot, in which case we can't check if tuple is created by the current
386 * transaction.
387 */
388 if (!hslot->tuple)
391 errmsg("don't have a storage tuple in this context")));
392
393 xmin = HeapTupleHeaderGetRawXmin(hslot->tuple->t_data);
394
396}

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

◆ tts_heap_materialize()

static void tts_heap_materialize ( TupleTableSlot slot)
static

Definition at line 399 of file execTuples.c.

400{
403
404 Assert(!TTS_EMPTY(slot));
405
406 /* If slot has its tuple already materialized, nothing to do. */
407 if (TTS_SHOULDFREE(slot))
408 return;
409
411
412 /*
413 * Have to deform from scratch, otherwise tts_values[] entries could point
414 * into the non-materialized tuple (which might be gone when accessed).
415 */
416 slot->tts_nvalid = 0;
417 hslot->off = 0;
418
419 if (!hslot->tuple)
421 slot->tts_values,
422 slot->tts_isnull);
423 else
424 {
425 /*
426 * The tuple contained in this slot is not allocated in the memory
427 * context of the given slot (else it would have TTS_FLAG_SHOULDFREE
428 * set). Copy the tuple into the given slot's memory context.
429 */
430 hslot->tuple = heap_copytuple(hslot->tuple);
431 }
432
434
436}

References Assert, fb(), heap_copytuple(), heap_form_tuple(), MemoryContextSwitchTo(), TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by tts_heap_copy_heap_tuple(), tts_heap_copy_minimal_tuple(), and tts_heap_get_heap_tuple().

◆ tts_heap_release()

static void tts_heap_release ( TupleTableSlot slot)
static

Definition at line 322 of file execTuples.c.

323{
324}

◆ tts_heap_store_tuple()

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

Definition at line 487 of file execTuples.c.

488{
490
491 tts_heap_clear(slot);
492
493 slot->tts_nvalid = 0;
494 hslot->tuple = tuple;
495 hslot->off = 0;
497 slot->tts_tid = tuple->t_self;
498
499 if (shouldFree)
501}
static void tts_heap_clear(TupleTableSlot *slot)
Definition execTuples.c:327

References fb(), HeapTupleData::t_self, TTS_FLAG_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, tts_heap_clear(), TupleTableSlot::tts_nvalid, and TupleTableSlot::tts_tid.

Referenced by ExecStoreHeapTuple().

◆ tts_minimal_clear()

static void tts_minimal_clear ( TupleTableSlot slot)
static

Definition at line 526 of file execTuples.c.

527{
529
530 if (TTS_SHOULDFREE(slot))
531 {
534 }
535
536 slot->tts_nvalid = 0;
537 slot->tts_flags |= TTS_FLAG_EMPTY;
539 mslot->off = 0;
540 mslot->mintuple = NULL;
541}
void heap_free_minimal_tuple(MinimalTuple mtup)
Definition heaptuple.c:1466

References fb(), heap_free_minimal_tuple(), ItemPointerSetInvalid(), TTS_FLAG_EMPTY, TupleTableSlot::tts_flags, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, and TupleTableSlot::tts_tid.

Referenced by tts_minimal_store_tuple().

◆ tts_minimal_copy_heap_tuple()

static HeapTuple tts_minimal_copy_heap_tuple ( TupleTableSlot slot)
static

Definition at line 660 of file execTuples.c.

661{
663
664 if (!mslot->mintuple)
666
667 return heap_tuple_from_minimal_tuple(mslot->mintuple);
668}
static void tts_minimal_materialize(TupleTableSlot *slot)
Definition execTuples.c:587
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
Definition heaptuple.c:1501

References fb(), heap_tuple_from_minimal_tuple(), and tts_minimal_materialize().

◆ tts_minimal_copy_minimal_tuple()

static MinimalTuple tts_minimal_copy_minimal_tuple ( TupleTableSlot slot,
Size  extra 
)
static

Definition at line 671 of file execTuples.c.

672{
674
675 if (!mslot->mintuple)
677
678 return heap_copy_minimal_tuple(mslot->mintuple, extra);
679}
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup, Size extra)
Definition heaptuple.c:1478

References fb(), heap_copy_minimal_tuple(), and tts_minimal_materialize().

◆ tts_minimal_copyslot()

static void tts_minimal_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 636 of file execTuples.c.

637{
638 MemoryContext oldcontext;
639 MinimalTuple mintuple;
640
641 oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt);
643 MemoryContextSwitchTo(oldcontext);
644
645 ExecStoreMinimalTuple(mintuple, dstslot, true);
646}
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
static MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition tuptable.h:515

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

◆ tts_minimal_get_minimal_tuple()

static MinimalTuple tts_minimal_get_minimal_tuple ( TupleTableSlot slot)
static

Definition at line 649 of file execTuples.c.

650{
652
653 if (!mslot->mintuple)
655
656 return mslot->mintuple;
657}

References fb(), and tts_minimal_materialize().

◆ tts_minimal_getsomeattrs()

static void tts_minimal_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 544 of file execTuples.c.

545{
547
548 Assert(!TTS_EMPTY(slot));
549
550 slot_deform_heap_tuple(slot, mslot->tuple, &mslot->off, natts, true);
551}

References Assert, fb(), slot_deform_heap_tuple(), and TTS_EMPTY.

◆ tts_minimal_getsysattr()

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

Definition at line 558 of file execTuples.c.

559{
560 Assert(!TTS_EMPTY(slot));
561
564 errmsg("cannot retrieve a system column in this context")));
565
566 return 0; /* silence compiler warnings */
567}

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

◆ tts_minimal_init()

static void tts_minimal_init ( TupleTableSlot slot)
static

Definition at line 509 of file execTuples.c.

510{
512
513 /*
514 * Initialize the heap tuple pointer to access attributes of the minimal
515 * tuple contained in the slot as if it's a heap tuple.
516 */
517 mslot->tuple = &mslot->minhdr;
518}

References fb().

◆ tts_minimal_is_current_xact_tuple()

static bool tts_minimal_is_current_xact_tuple ( TupleTableSlot slot)
static

Definition at line 575 of file execTuples.c.

576{
577 Assert(!TTS_EMPTY(slot));
578
581 errmsg("don't have transaction information for this type of tuple")));
582
583 return false; /* silence compiler warnings */
584}

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

◆ tts_minimal_materialize()

static void tts_minimal_materialize ( TupleTableSlot slot)
static

Definition at line 587 of file execTuples.c.

588{
591
592 Assert(!TTS_EMPTY(slot));
593
594 /* If slot has its tuple already materialized, nothing to do. */
595 if (TTS_SHOULDFREE(slot))
596 return;
597
599
600 /*
601 * Have to deform from scratch, otherwise tts_values[] entries could point
602 * into the non-materialized tuple (which might be gone when accessed).
603 */
604 slot->tts_nvalid = 0;
605 mslot->off = 0;
606
607 if (!mslot->mintuple)
608 {
610 slot->tts_values,
611 slot->tts_isnull,
612 0);
613 }
614 else
615 {
616 /*
617 * The minimal tuple contained in this slot is not allocated in the
618 * memory context of the given slot (else it would have
619 * TTS_FLAG_SHOULDFREE set). Copy the minimal tuple into the given
620 * slot's memory context.
621 */
622 mslot->mintuple = heap_copy_minimal_tuple(mslot->mintuple, 0);
623 }
624
626
627 Assert(mslot->tuple == &mslot->minhdr);
628
629 mslot->minhdr.t_len = mslot->mintuple->t_len + MINIMAL_TUPLE_OFFSET;
630 mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mslot->mintuple - MINIMAL_TUPLE_OFFSET);
631
633}
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull, Size extra)
Definition heaptuple.c:1390

References Assert, fb(), heap_copy_minimal_tuple(), heap_form_minimal_tuple(), MemoryContextSwitchTo(), MINIMAL_TUPLE_OFFSET, TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TupleTableSlot::tts_nvalid, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by tts_minimal_copy_heap_tuple(), tts_minimal_copy_minimal_tuple(), and tts_minimal_get_minimal_tuple().

◆ tts_minimal_release()

static void tts_minimal_release ( TupleTableSlot slot)
static

Definition at line 521 of file execTuples.c.

522{
523}

◆ tts_minimal_store_tuple()

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

Definition at line 682 of file execTuples.c.

683{
685
686 tts_minimal_clear(slot);
687
688 Assert(!TTS_SHOULDFREE(slot));
689 Assert(TTS_EMPTY(slot));
690
691 slot->tts_flags &= ~TTS_FLAG_EMPTY;
692 slot->tts_nvalid = 0;
693 mslot->off = 0;
694
695 mslot->mintuple = mtup;
696 Assert(mslot->tuple == &mslot->minhdr);
697 mslot->minhdr.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
698 mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
699 /* no need to set t_self or t_tableOid since we won't allow access */
700
701 if (shouldFree)
703}
static void tts_minimal_clear(TupleTableSlot *slot)
Definition execTuples.c:526

References Assert, fb(), MINIMAL_TUPLE_OFFSET, TTS_EMPTY, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, tts_minimal_clear(), TupleTableSlot::tts_nvalid, and TTS_SHOULDFREE.

Referenced by ExecForceStoreMinimalTuple(), and ExecStoreMinimalTuple().

◆ tts_virtual_clear()

static void tts_virtual_clear ( TupleTableSlot slot)
static

◆ tts_virtual_copy_heap_tuple()

static HeapTuple tts_virtual_copy_heap_tuple ( TupleTableSlot slot)
static

◆ tts_virtual_copy_minimal_tuple()

static MinimalTuple tts_virtual_copy_minimal_tuple ( TupleTableSlot slot,
Size  extra 
)
static

◆ tts_virtual_copyslot()

static void tts_virtual_copyslot ( TupleTableSlot dstslot,
TupleTableSlot srcslot 
)
static

Definition at line 269 of file execTuples.c.

270{
271 TupleDesc srcdesc = srcslot->tts_tupleDescriptor;
272
273 tts_virtual_clear(dstslot);
274
276
277 for (int natt = 0; natt < srcdesc->natts; natt++)
278 {
279 dstslot->tts_values[natt] = srcslot->tts_values[natt];
280 dstslot->tts_isnull[natt] = srcslot->tts_isnull[natt];
281 }
282
283 dstslot->tts_nvalid = srcdesc->natts;
284 dstslot->tts_flags &= ~TTS_FLAG_EMPTY;
285
286 /* make sure storage doesn't depend on external memory */
288}
static void tts_virtual_clear(TupleTableSlot *slot)
Definition execTuples.c:108
static void tts_virtual_materialize(TupleTableSlot *slot)
Definition execTuples.c:176
static void slot_getallattrs(TupleTableSlot *slot)
Definition tuptable.h:390

References fb(), slot_getallattrs(), TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_nvalid, TupleTableSlot::tts_values, tts_virtual_clear(), and tts_virtual_materialize().

◆ tts_virtual_getsomeattrs()

static void tts_virtual_getsomeattrs ( TupleTableSlot slot,
int  natts 
)
static

Definition at line 130 of file execTuples.c.

131{
132 elog(ERROR, "getsomeattrs is not required to be called on a virtual tuple table slot");
133}

References elog, and ERROR.

◆ tts_virtual_getsysattr()

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

Definition at line 141 of file execTuples.c.

142{
143 Assert(!TTS_EMPTY(slot));
144
147 errmsg("cannot retrieve a system column in this context")));
148
149 return 0; /* silence compiler warnings */
150}

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

◆ tts_virtual_init()

static void tts_virtual_init ( TupleTableSlot slot)
static

Definition at line 98 of file execTuples.c.

99{
100}

◆ tts_virtual_is_current_xact_tuple()

static bool tts_virtual_is_current_xact_tuple ( TupleTableSlot slot)
static

Definition at line 157 of file execTuples.c.

158{
159 Assert(!TTS_EMPTY(slot));
160
163 errmsg("don't have transaction information for this type of tuple")));
164
165 return false; /* silence compiler warnings */
166}

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

◆ tts_virtual_materialize()

static void tts_virtual_materialize ( TupleTableSlot slot)
static

Definition at line 176 of file execTuples.c.

177{
179 TupleDesc desc = slot->tts_tupleDescriptor;
180 Size sz = 0;
181 char *data;
182
183 /* already materialized */
184 if (TTS_SHOULDFREE(slot))
185 return;
186
187 /* compute size of memory required */
188 for (int natt = 0; natt < desc->natts; natt++)
189 {
191 Datum val;
192
193 if (att->attbyval || slot->tts_isnull[natt])
194 continue;
195
196 val = slot->tts_values[natt];
197
198 if (att->attlen == -1 &&
200 {
201 /*
202 * We want to flatten the expanded value so that the materialized
203 * slot doesn't depend on it.
204 */
207 }
208 else
209 {
212 }
213 }
214
215 /* all data is byval */
216 if (sz == 0)
217 return;
218
219 /* allocate memory */
220 vslot->data = data = MemoryContextAlloc(slot->tts_mcxt, sz);
222
223 /* and copy all attributes into the pre-allocated space */
224 for (int natt = 0; natt < desc->natts; natt++)
225 {
227 Datum val;
228
229 if (att->attbyval || slot->tts_isnull[natt])
230 continue;
231
232 val = slot->tts_values[natt];
233
234 if (att->attlen == -1 &&
236 {
237 Size data_length;
238
239 /*
240 * We want to flatten the expanded value so that the materialized
241 * slot doesn't depend on it.
242 */
244
245 data = (char *) att_nominal_alignby(data,
246 att->attalignby);
247 data_length = EOH_get_flat_size(eoh);
248 EOH_flatten_into(eoh, data, data_length);
249
251 data += data_length;
252 }
253 else
254 {
255 Size data_length = 0;
256
257 data = (char *) att_nominal_alignby(data, att->attalignby);
258 data_length = att_addlength_datum(data_length, att->attlen, val);
259
260 memcpy(data, DatumGetPointer(val), data_length);
261
263 data += data_length;
264 }
265 }
266}
ExpandedObjectHeader * DatumGetEOHP(Datum d)
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
long val
Definition informix.c:689
uint8 attalignby
Definition tupdesc.h:74
#define att_nominal_alignby(cur_offset, attalignby)
Definition tupmacs.h:411
#define att_addlength_datum(cur_offset, attlen, attdatum)
Definition tupmacs.h:419
static bool VARATT_IS_EXTERNAL_EXPANDED(const void *PTR)
Definition varatt.h:389

References att_addlength_datum, att_nominal_alignby, CompactAttribute::attalignby, CompactAttribute::attbyval, CompactAttribute::attlen, data, DatumGetEOHP(), DatumGetPointer(), EOH_flatten_into(), EOH_get_flat_size(), fb(), memcpy(), MemoryContextAlloc(), TupleDescData::natts, PointerGetDatum, TTS_FLAG_SHOULDFREE, TupleTableSlot::tts_flags, TupleTableSlot::tts_isnull, TupleTableSlot::tts_mcxt, TTS_SHOULDFREE, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescCompactAttr(), val, and VARATT_IS_EXTERNAL_EXPANDED().

Referenced by tts_virtual_copyslot().

◆ tts_virtual_release()

static void tts_virtual_release ( TupleTableSlot slot)
static

Definition at line 103 of file execTuples.c.

104{
105}

◆ TupleDescGetAttInMetadata()

AttInMetadata * TupleDescGetAttInMetadata ( TupleDesc  tupdesc)

Definition at line 2363 of file execTuples.c.

2364{
2365 int natts = tupdesc->natts;
2366 int i;
2367 Oid atttypeid;
2370 Oid *attioparams;
2371 int32 *atttypmods;
2372 AttInMetadata *attinmeta;
2373
2374 attinmeta = palloc_object(AttInMetadata);
2375
2376 /* "Bless" the tupledesc so that we can make rowtype datums with it */
2377 attinmeta->tupdesc = BlessTupleDesc(tupdesc);
2378
2379 /*
2380 * Gather info needed later to call the "in" function for each attribute
2381 */
2382 attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
2383 attioparams = (Oid *) palloc0(natts * sizeof(Oid));
2384 atttypmods = (int32 *) palloc0(natts * sizeof(int32));
2385
2386 for (i = 0; i < natts; i++)
2387 {
2388 Form_pg_attribute att = TupleDescAttr(tupdesc, i);
2389
2390 /* Ignore dropped attributes */
2391 if (!att->attisdropped)
2392 {
2393 atttypeid = att->atttypid;
2394 getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
2396 atttypmods[i] = att->atttypmod;
2397 }
2398 }
2399 attinmeta->attinfuncs = attinfuncinfo;
2400 attinmeta->attioparams = attioparams;
2401 attinmeta->atttypmods = atttypmods;
2402
2403 return attinmeta;
2404}
int32_t int32
Definition c.h:620
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition fmgr.c:129
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition lsyscache.c:3182
unsigned int Oid

References AttInMetadata::attinfuncs, AttInMetadata::attioparams, AttInMetadata::atttypmods, BlessTupleDesc(), fb(), fmgr_info(), getTypeInputInfo(), i, TupleDescData::natts, palloc0(), palloc_object, AttInMetadata::tupdesc, and TupleDescAttr().

Referenced by bt_metap(), bt_multi_page_stats(), bt_page_stats_internal(), build_pgstattuple_type(), connectby_text(), connectby_text_serial(), create_foreign_modify(), crosstab(), dblink_get_pkey(), get_crosstab_tuplestore(), hash_page_items(), libpqrcv_processTuples(), materializeQueryResult(), materializeResult(), pg_get_keywords(), pg_get_multixact_members(), pg_stats_ext_mcvlist_items(), pgp_armor_headers(), pgrowlocks(), pgstatindex_impl(), pltcl_build_tuple_result(), pltcl_func_handler(), pltcl_init_tuple_store(), postgresAcquireSampleRowsFunc(), postgresBeginDirectModify(), postgresBeginForeignScan(), prs_setup_firstcall(), show_all_settings(), storeRow(), ts_setup_firstcall(), tt_setup_firstcall(), and xpath_table().

Variable Documentation

◆ TTSOpsBufferHeapTuple

const TupleTableSlotOps TTSOpsBufferHeapTuple
Initial value:
= {
.base_slot_size = sizeof(BufferHeapTupleTableSlot),
.is_current_xact_tuple = tts_buffer_is_current_xact_tuple,
.get_heap_tuple = tts_buffer_heap_get_heap_tuple,
.get_minimal_tuple = NULL,
.copy_heap_tuple = tts_buffer_heap_copy_heap_tuple,
.copy_minimal_tuple = tts_buffer_heap_copy_minimal_tuple
}
static void tts_buffer_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition execTuples.c:863
static HeapTuple tts_buffer_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition execTuples.c:918
static void tts_buffer_heap_clear(TupleTableSlot *slot)
Definition execTuples.c:721
static Datum tts_buffer_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition execTuples.c:761
static bool tts_buffer_is_current_xact_tuple(TupleTableSlot *slot)
Definition execTuples.c:781
static HeapTuple tts_buffer_heap_get_heap_tuple(TupleTableSlot *slot)
Definition execTuples.c:905
static void tts_buffer_heap_release(TupleTableSlot *slot)
Definition execTuples.c:716
static MinimalTuple tts_buffer_heap_copy_minimal_tuple(TupleTableSlot *slot, Size extra)
Definition execTuples.c:931
static void tts_buffer_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition execTuples.c:751
static void tts_buffer_heap_init(TupleTableSlot *slot)
Definition execTuples.c:711
#define init()

Definition at line 87 of file execTuples.c.

Referenced by CheckOpSlotCompatibility(), heapam_slot_callbacks(), and slot_compile_deform().

◆ TTSOpsHeapTuple

const TupleTableSlotOps TTSOpsHeapTuple
Initial value:
= {
.base_slot_size = sizeof(HeapTupleTableSlot),
.release = tts_heap_release,
.clear = tts_heap_clear,
.getsomeattrs = tts_heap_getsomeattrs,
.getsysattr = tts_heap_getsysattr,
.is_current_xact_tuple = tts_heap_is_current_xact_tuple,
.materialize = tts_heap_materialize,
.copyslot = tts_heap_copyslot,
.get_heap_tuple = tts_heap_get_heap_tuple,
.get_minimal_tuple = NULL,
.copy_heap_tuple = tts_heap_copy_heap_tuple,
.copy_minimal_tuple = tts_heap_copy_minimal_tuple
}
static Datum tts_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition execTuples.c:356
static void tts_heap_init(TupleTableSlot *slot)
Definition execTuples.c:317
static HeapTuple tts_heap_copy_heap_tuple(TupleTableSlot *slot)
Definition execTuples.c:464
static MinimalTuple tts_heap_copy_minimal_tuple(TupleTableSlot *slot, Size extra)
Definition execTuples.c:476
static HeapTuple tts_heap_get_heap_tuple(TupleTableSlot *slot)
Definition execTuples.c:452
static void tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition execTuples.c:439
static void tts_heap_getsomeattrs(TupleTableSlot *slot, int natts)
Definition execTuples.c:346
static void tts_heap_release(TupleTableSlot *slot)
Definition execTuples.c:322
static bool tts_heap_is_current_xact_tuple(TupleTableSlot *slot)
Definition execTuples.c:376

Definition at line 85 of file execTuples.c.

Referenced by CatalogIndexInsert(), CheckOpSlotCompatibility(), compute_expr_stats(), compute_index_stats(), copyTemplateDependencies(), DefineTSConfiguration(), EnumValuesCreate(), ExecInitForeignScan(), ExecuteCallStmt(), heapam_index_validate_scan(), init_tuple_slot(), InsertPgAttributeTuples(), make_build_data(), MakeConfigurationMapping(), recordMultipleDependencies(), repack_store_change(), ri_FastPathGetEntry(), slot_compile_deform(), table_slot_callbacks(), and tuplesort_begin_cluster().

◆ TTSOpsMinimalTuple

const TupleTableSlotOps TTSOpsMinimalTuple
Initial value:
= {
.base_slot_size = sizeof(MinimalTupleTableSlot),
.release = tts_minimal_release,
.getsomeattrs = tts_minimal_getsomeattrs,
.getsysattr = tts_minimal_getsysattr,
.is_current_xact_tuple = tts_minimal_is_current_xact_tuple,
.materialize = tts_minimal_materialize,
.copyslot = tts_minimal_copyslot,
.get_heap_tuple = NULL,
.get_minimal_tuple = tts_minimal_get_minimal_tuple,
.copy_heap_tuple = tts_minimal_copy_heap_tuple,
.copy_minimal_tuple = tts_minimal_copy_minimal_tuple
}
static HeapTuple tts_minimal_copy_heap_tuple(TupleTableSlot *slot)
Definition execTuples.c:660
static void tts_minimal_init(TupleTableSlot *slot)
Definition execTuples.c:509
static MinimalTuple tts_minimal_get_minimal_tuple(TupleTableSlot *slot)
Definition execTuples.c:649
static void tts_minimal_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition execTuples.c:636
static void tts_minimal_release(TupleTableSlot *slot)
Definition execTuples.c:521
static Datum tts_minimal_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition execTuples.c:558
static bool tts_minimal_is_current_xact_tuple(TupleTableSlot *slot)
Definition execTuples.c:575
static MinimalTuple tts_minimal_copy_minimal_tuple(TupleTableSlot *slot, Size extra)
Definition execTuples.c:671
static void tts_minimal_getsomeattrs(TupleTableSlot *slot, int natts)
Definition execTuples.c:544

Definition at line 86 of file execTuples.c.

Referenced by afterTriggerInvokeEvents(), build_pertrans_for_aggref(), BuildTupleHashTable(), check_pub_dead_tuple_retention(), check_publications(), check_publications_origin_sequences(), check_publications_origin_tables(), copy_sequences(), ExecInitAgg(), ExecInitCteScan(), ExecInitFunctionScan(), ExecInitGather(), ExecInitHash(), ExecInitIncrementalSort(), ExecInitMaterial(), ExecInitMemoize(), ExecInitNamedTuplestoreScan(), ExecInitSetOp(), ExecInitSort(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitUnique(), ExecInitWindowAgg(), ExecInitWorkTableScan(), ExecPrepareTuplestoreResult(), fetch_relation_list(), fetch_remote_slots(), fetch_remote_table_info(), find_hash_columns(), gather_merge_setup(), hashagg_recompile_expressions(), hypothetical_dense_rank_final(), init_execution_state(), ordered_set_startup(), RunFromStore(), slot_compile_deform(), and validate_remote_info().

◆ TTSOpsVirtual

const TupleTableSlotOps TTSOpsVirtual
Initial value:
= {
.base_slot_size = sizeof(VirtualTupleTableSlot),
.release = tts_virtual_release,
.getsomeattrs = tts_virtual_getsomeattrs,
.getsysattr = tts_virtual_getsysattr,
.materialize = tts_virtual_materialize,
.is_current_xact_tuple = tts_virtual_is_current_xact_tuple,
.copyslot = tts_virtual_copyslot,
.get_heap_tuple = NULL,
.get_minimal_tuple = NULL,
.copy_heap_tuple = tts_virtual_copy_heap_tuple,
.copy_minimal_tuple = tts_virtual_copy_minimal_tuple
}
static MinimalTuple tts_virtual_copy_minimal_tuple(TupleTableSlot *slot, Size extra)
Definition execTuples.c:301
static HeapTuple tts_virtual_copy_heap_tuple(TupleTableSlot *slot)
Definition execTuples.c:291
static void tts_virtual_release(TupleTableSlot *slot)
Definition execTuples.c:103
static void tts_virtual_init(TupleTableSlot *slot)
Definition execTuples.c:98
static void tts_virtual_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition execTuples.c:269
static bool tts_virtual_is_current_xact_tuple(TupleTableSlot *slot)
Definition execTuples.c:157
static void tts_virtual_getsomeattrs(TupleTableSlot *slot, int natts)
Definition execTuples.c:130
static Datum tts_virtual_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition execTuples.c:141

Definition at line 84 of file execTuples.c.

Referenced by apply_concurrent_changes(), apply_handle_delete(), apply_handle_insert(), apply_handle_update(), buildSubPlanHash(), CheckOpSlotCompatibility(), CreateReplicationSlot(), ExecComputeSlotInfo(), ExecConditionalAssignProjectionInfo(), ExecConstraints(), ExecGetResultSlotOps(), ExecInitAgg(), ExecInitAppend(), ExecInitCustomScan(), ExecInitForPortionOf(), ExecInitGroup(), ExecInitHashJoin(), ExecInitIndexOnlyScan(), ExecInitJunkFilter(), ExecInitJunkFilterConversion(), ExecInitMemoize(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNestLoop(), ExecInitPartitionDispatchInfo(), ExecInitProjectSet(), ExecInitResult(), ExecInitSort(), ExecInitSubPlan(), ExecInitValuesScan(), ExecInitWholeRowVar(), ExecInitWindowAgg(), ExecPartitionCheckEmitError(), ExecWaitStmt(), ExecWithCheckOptions(), ExplainQuery(), GetAfterTriggersStoreSlot(), IdentifySystem(), InitPlan(), llvm_compile_expr(), pgoutput_change(), pgoutput_row_filter(), ReadReplicationSlot(), ReportNotNullViolationError(), RI_Initial_Check(), RI_PartitionRemove_Check(), SendTablespaceList(), SendXlogRecPtrResult(), ShowAllGUCConfig(), ShowGUCConfigOption(), slot_compile_deform(), StartReplication(), table_slot_callbacks(), and tstoreStartupReceiver().