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

Go to the source code of this file.

Data Structures

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

Macros

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

Typedefs

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

Functions

TupleTableSlotMakeTupleTableSlot (TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops, 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)
 
void ExecForceStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecStoreBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlotExecStorePinnedBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlotExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlotExecStoreVirtualTuple (TupleTableSlot *slot)
 
TupleTableSlotExecStoreAllNullTuple (TupleTableSlot *slot)
 
void ExecStoreHeapTupleDatum (Datum data, TupleTableSlot *slot)
 
HeapTuple ExecFetchSlotHeapTuple (TupleTableSlot *slot, bool materialize, bool *shouldFree)
 
MinimalTuple ExecFetchSlotMinimalTuple (TupleTableSlot *slot, bool *shouldFree)
 
Datum ExecFetchSlotHeapTupleDatum (TupleTableSlot *slot)
 
void slot_getmissingattrs (TupleTableSlot *slot, int startAttNum, int lastAttNum)
 
void slot_getsomeattrs_int (TupleTableSlot *slot, int attnum)
 
static void slot_getsomeattrs (TupleTableSlot *slot, int attnum)
 
static void slot_getallattrs (TupleTableSlot *slot)
 
static bool slot_attisnull (TupleTableSlot *slot, int attnum)
 
static Datum slot_getattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static Datum slot_getsysattr (TupleTableSlot *slot, int attnum, bool *isnull)
 
static bool slot_is_current_xact_tuple (TupleTableSlot *slot)
 
static TupleTableSlotExecClearTuple (TupleTableSlot *slot)
 
static void ExecMaterializeSlot (TupleTableSlot *slot)
 
static HeapTuple ExecCopySlotHeapTuple (TupleTableSlot *slot)
 
static MinimalTuple ExecCopySlotMinimalTuple (TupleTableSlot *slot)
 
static MinimalTuple ExecCopySlotMinimalTupleExtra (TupleTableSlot *slot, Size extra)
 
static TupleTableSlotExecCopySlot (TupleTableSlot *dstslot, TupleTableSlot *srcslot)
 

Variables

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

Macro Definition Documentation

◆ FIELDNO_HEAPTUPLETABLESLOT_OFF

#define FIELDNO_HEAPTUPLETABLESLOT_OFF   2

Definition at line 280 of file tuptable.h.

◆ FIELDNO_HEAPTUPLETABLESLOT_TUPLE

#define FIELDNO_HEAPTUPLETABLESLOT_TUPLE   1

Definition at line 278 of file tuptable.h.

◆ FIELDNO_MINIMALTUPLETABLESLOT_OFF

#define FIELDNO_MINIMALTUPLETABLESLOT_OFF   4

Definition at line 318 of file tuptable.h.

◆ FIELDNO_MINIMALTUPLETABLESLOT_TUPLE

#define FIELDNO_MINIMALTUPLETABLESLOT_TUPLE   1

Definition at line 314 of file tuptable.h.

◆ FIELDNO_TUPLETABLESLOT_FLAGS

#define FIELDNO_TUPLETABLESLOT_FLAGS   1

Definition at line 123 of file tuptable.h.

◆ FIELDNO_TUPLETABLESLOT_ISNULL

#define FIELDNO_TUPLETABLESLOT_ISNULL   6

Definition at line 132 of file tuptable.h.

◆ FIELDNO_TUPLETABLESLOT_NVALID

#define FIELDNO_TUPLETABLESLOT_NVALID   2

Definition at line 125 of file tuptable.h.

◆ FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR

#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR   4

Definition at line 128 of file tuptable.h.

◆ FIELDNO_TUPLETABLESLOT_VALUES

#define FIELDNO_TUPLETABLESLOT_VALUES   5

Definition at line 130 of file tuptable.h.

◆ TTS_EMPTY

#define TTS_EMPTY (   slot)    (((slot)->tts_flags & TTS_FLAG_EMPTY) != 0)

Definition at line 92 of file tuptable.h.

◆ TTS_FIXED

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

Definition at line 108 of file tuptable.h.

◆ TTS_FLAG_EMPTY

#define TTS_FLAG_EMPTY   (1 << 1)

Definition at line 91 of file tuptable.h.

◆ TTS_FLAG_FIXED

#define TTS_FLAG_FIXED   (1 << 4)

Definition at line 107 of file tuptable.h.

◆ TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS

#define TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS   (1 << 3)

Definition at line 102 of file tuptable.h.

◆ TTS_FLAG_SHOULDFREE

#define TTS_FLAG_SHOULDFREE   (1 << 2)

Definition at line 95 of file tuptable.h.

◆ TTS_FLAGS_TRANSIENT

#define TTS_FLAGS_TRANSIENT   (TTS_FLAG_EMPTY|TTS_FLAG_SHOULDFREE)

Definition at line 114 of file tuptable.h.

◆ TTS_IS_BUFFERTUPLE

#define TTS_IS_BUFFERTUPLE (   slot)    ((slot)->tts_ops == &TTSOpsBufferHeapTuple)

Definition at line 256 of file tuptable.h.

◆ TTS_IS_HEAPTUPLE

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

Definition at line 254 of file tuptable.h.

◆ TTS_IS_MINIMALTUPLE

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

Definition at line 255 of file tuptable.h.

◆ TTS_IS_VIRTUAL

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

Definition at line 253 of file tuptable.h.

◆ TTS_OBEYS_NOT_NULL_CONSTRAINTS

#define TTS_OBEYS_NOT_NULL_CONSTRAINTS (   slot)     (((slot)->tts_flags & TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS) != 0)

Definition at line 103 of file tuptable.h.

120{
122#define FIELDNO_TUPLETABLESLOT_FLAGS 1
123 uint16 tts_flags; /* Boolean states */
124#define FIELDNO_TUPLETABLESLOT_NVALID 2
125 AttrNumber tts_nvalid; /* # of valid values in tts_values */
126 const TupleTableSlotOps *const tts_ops; /* implementation of slot */
127#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR 4
128 TupleDesc tts_tupleDescriptor; /* slot's tuple descriptor */
129#define FIELDNO_TUPLETABLESLOT_VALUES 5
130 Datum *tts_values; /* current per-attribute values */
131#define FIELDNO_TUPLETABLESLOT_ISNULL 6
132 bool *tts_isnull; /* current per-attribute isnull flags. Array
133 * size must always be rounded up to the next
134 * multiple of 8 elements. */
135 int tts_first_nonguaranteed; /* The value from the TupleDesc's
136 * firstNonGuaranteedAttr, or 0
137 * when tts_flags does not contain
138 * TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS */
139
140 MemoryContext tts_mcxt; /* slot itself is in this context */
141 ItemPointerData tts_tid; /* stored tuple's tid */
142 Oid tts_tableOid; /* table oid of tuple */
144
145/* routines for a TupleTableSlot implementation */
147{
148 /* Minimum size of the slot */
149 size_t base_slot_size;
150
151 /* Initialization. */
152 void (*init) (TupleTableSlot *slot);
153
154 /* Destruction. */
155 void (*release) (TupleTableSlot *slot);
156
157 /*
158 * Clear the contents of the slot. Only the contents are expected to be
159 * cleared and not the tuple descriptor. Typically an implementation of
160 * this callback should free the memory allocated for the tuple contained
161 * in the slot.
162 */
163 void (*clear) (TupleTableSlot *slot);
164
165 /*
166 * Fill up first natts entries of tts_values and tts_isnull arrays with
167 * values from the tuple contained in the slot and set the slot's
168 * tts_nvalid to natts. The function may be called with an natts value
169 * more than the number of attributes available in the tuple, in which
170 * case the function must call slot_getmissingattrs() to populate the
171 * remaining attributes. The function must raise an ERROR if 'natts' is
172 * higher than the number of attributes in the slot's TupleDesc.
173 */
174 void (*getsomeattrs) (TupleTableSlot *slot, int natts);
175
176 /*
177 * Returns value of the given system attribute as a datum and sets isnull
178 * to false, if it's not NULL. Throws an error if the slot type does not
179 * support system attributes.
180 */
181 Datum (*getsysattr) (TupleTableSlot *slot, int attnum, bool *isnull);
182
183 /*
184 * Check if the tuple is created by the current transaction. Throws an
185 * error if the slot doesn't contain the storage tuple.
186 */
188
189 /*
190 * Make the contents of the slot solely depend on the slot, and not on
191 * underlying resources (like another memory context, buffers, etc).
192 */
194
195 /*
196 * Copy the contents of the source slot into the destination slot's own
197 * context. Invoked using callback of the destination slot. 'dstslot' and
198 * 'srcslot' can be assumed to have the same number of attributes.
199 */
201
202 /*
203 * Return a heap tuple "owned" by the slot. It is slot's responsibility to
204 * free the memory consumed by the heap tuple. If the slot can not "own" a
205 * heap tuple, it should not implement this callback and should set it as
206 * NULL.
207 */
209
210 /*
211 * Return a minimal tuple "owned" by the slot. It is slot's responsibility
212 * to free the memory consumed by the minimal tuple. If the slot can not
213 * "own" a minimal tuple, it should not implement this callback and should
214 * set it as NULL.
215 */
217
218 /*
219 * Return a copy of heap tuple representing the contents of the slot. The
220 * copy needs to be palloc'd in the current memory context. The slot
221 * itself is expected to remain unaffected. It is *not* expected to have
222 * meaningful "system columns" in the copy. The copy is not be "owned" by
223 * the slot i.e. the caller has to take responsibility to free memory
224 * consumed by the slot.
225 */
227
228 /*
229 * Return a copy of minimal tuple representing the contents of the slot.
230 * The copy needs to be palloc'd in the current memory context. The slot
231 * itself is expected to remain unaffected. It is *not* expected to have
232 * meaningful "system columns" in the copy. The copy is not be "owned" by
233 * the slot i.e. the caller has to take responsibility to free memory
234 * consumed by the slot.
235 *
236 * The copy has "extra" bytes (maxaligned and zeroed) available before the
237 * tuple, which is useful so that some callers may store extra data along
238 * with the minimal tuple without the need for an additional allocation.
239 */
241};
242
243/*
244 * Predefined TupleTableSlotOps for various types of TupleTableSlotOps. The
245 * same are used to identify the type of a given slot.
246 */
251
252#define TTS_IS_VIRTUAL(slot) ((slot)->tts_ops == &TTSOpsVirtual)
253#define TTS_IS_HEAPTUPLE(slot) ((slot)->tts_ops == &TTSOpsHeapTuple)
254#define TTS_IS_MINIMALTUPLE(slot) ((slot)->tts_ops == &TTSOpsMinimalTuple)
255#define TTS_IS_BUFFERTUPLE(slot) ((slot)->tts_ops == &TTSOpsBufferHeapTuple)
256
257
258/*
259 * Tuple table slot implementations.
260 */
261
262typedef struct VirtualTupleTableSlot
263{
264 pg_node_attr(abstract)
265
266 TupleTableSlot base;
267
268 char *data; /* data for materialized slots */
270
272{
273 pg_node_attr(abstract)
274
275 TupleTableSlot base;
276
277#define FIELDNO_HEAPTUPLETABLESLOT_TUPLE 1
278 HeapTuple tuple; /* physical tuple */
279#define FIELDNO_HEAPTUPLETABLESLOT_OFF 2
280 uint32 off; /* saved state for slot_deform_heap_tuple */
281 HeapTupleData tupdata; /* optional workspace for storing tuple */
283
284/* heap tuple residing in a buffer */
285typedef struct BufferHeapTupleTableSlot
286{
287 pg_node_attr(abstract)
288
290
291 /*
292 * If buffer is not InvalidBuffer, then the slot is holding a pin on the
293 * indicated buffer page; drop the pin when we release the slot's
294 * reference to that buffer. (TTS_FLAG_SHOULDFREE should not be set in
295 * such a case, since presumably base.tuple is pointing into the buffer.)
296 */
297 Buffer buffer; /* tuple's buffer, or InvalidBuffer */
299
301{
302 pg_node_attr(abstract)
303
304 TupleTableSlot base;
305
306 /*
307 * In a minimal slot tuple points at minhdr and the fields of that struct
308 * are set correctly for access to the minimal tuple; in particular,
309 * minhdr.t_data points MINIMAL_TUPLE_OFFSET bytes before mintuple. This
310 * allows column extraction to treat the case identically to regular
311 * physical tuples.
312 */
313#define FIELDNO_MINIMALTUPLETABLESLOT_TUPLE 1
314 HeapTuple tuple; /* tuple wrapper */
315 MinimalTuple mintuple; /* minimal tuple, or NULL if none */
316 HeapTupleData minhdr; /* workspace for minimal-tuple-only case */
317#define FIELDNO_MINIMALTUPLETABLESLOT_OFF 4
318 uint32 off; /* saved state for slot_deform_heap_tuple */
320
321/*
322 * TupIsNull -- is a TupleTableSlot empty?
323 */
324#define TupIsNull(slot) \
325 ((slot) == NULL || TTS_EMPTY(slot))
326
327/* in executor/execTuples.c */
329 const TupleTableSlotOps *tts_ops,
330 uint16 flags);
332 const TupleTableSlotOps *tts_ops,
333 uint16 flags);
336 const TupleTableSlotOps *tts_ops);
338extern void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc);
340 TupleTableSlot *slot,
341 bool shouldFree);
342extern void ExecForceStoreHeapTuple(HeapTuple tuple,
343 TupleTableSlot *slot,
344 bool shouldFree);
346 TupleTableSlot *slot,
347 Buffer buffer);
349 TupleTableSlot *slot,
350 Buffer buffer);
352 TupleTableSlot *slot,
353 bool shouldFree);
355 bool shouldFree);
359extern HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree);
361 bool *shouldFree);
363extern void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum,
364 int lastAttNum);
365extern void slot_getsomeattrs_int(TupleTableSlot *slot, int attnum);
366
367
368#ifndef FRONTEND
369
370/*
371 * This function forces the entries of the slot's Datum/isnull arrays to be
372 * valid at least up through the attnum'th entry.
373 */
374static inline void
376{
377 /* Populate slot with attributes up to 'attnum', if it's not already */
378 if (slot->tts_nvalid < attnum)
379 slot->tts_ops->getsomeattrs(slot, attnum);
380}
381
382/*
383 * slot_getallattrs
384 * This function forces all the entries of the slot's Datum/isnull
385 * arrays to be valid. The caller may then extract data directly
386 * from those arrays instead of using slot_getattr.
387 */
388static inline void
390{
392}
393
394
395/*
396 * slot_attisnull
397 *
398 * Detect whether an attribute of the slot is null, without actually fetching
399 * it.
400 */
401static inline bool
403{
404 Assert(attnum > 0);
405
406 if (attnum > slot->tts_nvalid)
408
409 return slot->tts_isnull[attnum - 1];
410}
411
412/*
413 * slot_getattr - fetch one attribute of the slot's contents.
414 */
415static inline Datum
417 bool *isnull)
418{
419 Assert(attnum > 0);
420
421 if (attnum > slot->tts_nvalid)
423
424 *isnull = slot->tts_isnull[attnum - 1];
425
426 return slot->tts_values[attnum - 1];
427}
428
429/*
430 * slot_getsysattr - fetch a system attribute of the slot's current tuple.
431 *
432 * If the slot type does not contain system attributes, this will throw an
433 * error. Hence before calling this function, callers should make sure that
434 * the slot type is the one that supports system attributes.
435 */
436static inline Datum
437slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
438{
439 Assert(attnum < 0); /* caller error */
440
442 {
443 *isnull = false;
444 return ObjectIdGetDatum(slot->tts_tableOid);
445 }
447 {
448 *isnull = false;
449 return PointerGetDatum(&slot->tts_tid);
450 }
451
452 /* Fetch the system attribute from the underlying tuple. */
453 return slot->tts_ops->getsysattr(slot, attnum, isnull);
454}
455
456/*
457 * slot_is_current_xact_tuple - check if the slot's current tuple is created
458 * by the current transaction.
459 *
460 * If the slot does not contain a storage tuple, this will throw an error.
461 * Hence before calling this function, callers should make sure that the
462 * slot type supports storage tuples and that there is currently one inside
463 * the slot.
464 */
465static inline bool
467{
468 return slot->tts_ops->is_current_xact_tuple(slot);
469}
470
471/*
472 * ExecClearTuple - clear the slot's contents
473 */
474static inline TupleTableSlot *
476{
477 slot->tts_ops->clear(slot);
478
479 return slot;
480}
481
482/* ExecMaterializeSlot - force a slot into the "materialized" state.
483 *
484 * This causes the slot's tuple to be a local copy not dependent on any
485 * external storage (i.e. pointing into a Buffer, or having allocations in
486 * another memory context).
487 *
488 * A typical use for this operation is to prepare a computed tuple for being
489 * stored on disk. The original data may or may not be virtual, but in any
490 * case we need a private copy for heap_insert to scribble on.
491 */
492static inline void
494{
495 slot->tts_ops->materialize(slot);
496}
497
498/*
499 * ExecCopySlotHeapTuple - return HeapTuple allocated in caller's context
500 */
501static inline HeapTuple
503{
504 Assert(!TTS_EMPTY(slot));
505
506 return slot->tts_ops->copy_heap_tuple(slot);
507}
508
509/*
510 * ExecCopySlotMinimalTuple - return MinimalTuple allocated in caller's context
511 */
512static inline MinimalTuple
514{
515 return slot->tts_ops->copy_minimal_tuple(slot, 0);
516}
517
518/*
519 * ExecCopySlotMinimalTupleExtra - return MinimalTuple allocated in caller's
520 * context, with extra bytes (maxaligned and zeroed) before the tuple for data
521 * the caller wishes to store along with the tuple (without requiring the
522 * caller to make an additional allocation).
523 */
524static inline MinimalTuple
526{
527 return slot->tts_ops->copy_minimal_tuple(slot, extra);
528}
529
530/*
531 * ExecCopySlot - copy one slot's contents into another.
532 *
533 * If a source's system attributes are supposed to be accessed in the target
534 * slot, the target slot and source slot types need to match.
535 *
536 * Currently, 'dstslot' and 'srcslot' must have the same number of attributes.
537 * Future work could see this relaxed to allow the source to contain
538 * additional attributes and have the code here only copy over the leading
539 * attributes.
540 */
541static inline TupleTableSlot *
543{
545 Assert(srcslot != dstslot);
546 Assert(dstslot->tts_tupleDescriptor->natts ==
547 srcslot->tts_tupleDescriptor->natts);
548
549 dstslot->tts_ops->copyslot(dstslot, srcslot);
550
551 return dstslot;
552}
553
554#endif /* FRONTEND */
555
556#endif /* TUPTABLE_H */
int16 AttrNumber
Definition attnum.h:21
int Buffer
Definition buf.h:23
#define PGDLLIMPORT
Definition c.h:1423
#define Assert(condition)
Definition c.h:945
uint16_t uint16
Definition c.h:617
uint32_t uint32
Definition c.h:618
size_t Size
Definition c.h:691
void ExecResetTupleTable(List *tupleTable, bool shouldFree)
TupleTableSlot * ExecStorePinnedBufferHeapTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
void ExecForceStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
MinimalTuple ExecFetchSlotMinimalTuple(TupleTableSlot *slot, bool *shouldFree)
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
TupleTableSlot * MakeTupleTableSlot(TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops, uint16 flags)
HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree)
void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
TupleTableSlot * ExecStoreBufferHeapTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
void ExecStoreHeapTupleDatum(Datum data, TupleTableSlot *slot)
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Datum ExecFetchSlotHeapTupleDatum(TupleTableSlot *slot)
void slot_getsomeattrs_int(TupleTableSlot *slot, int attnum)
TupleTableSlot * ExecAllocTableSlot(List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops, uint16 flags)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
void ExecForceStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
HeapTupleData * HeapTuple
Definition htup.h:71
MinimalTupleData * MinimalTuple
Definition htup.h:27
#define pg_node_attr(...)
Definition nodes.h:126
NodeTag
Definition nodes.h:27
int16 attnum
const void * data
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
Definition pg_list.h:54
Datum(* getsysattr)(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:182
size_t base_slot_size
Definition tuptable.h:150
bool(* is_current_xact_tuple)(TupleTableSlot *slot)
Definition tuptable.h:188
HeapTuple(* get_heap_tuple)(TupleTableSlot *slot)
Definition tuptable.h:209
MinimalTuple(* copy_minimal_tuple)(TupleTableSlot *slot, Size extra)
Definition tuptable.h:241
void(* init)(TupleTableSlot *slot)
Definition tuptable.h:153
void(* copyslot)(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition tuptable.h:201
void(* getsomeattrs)(TupleTableSlot *slot, int natts)
Definition tuptable.h:175
HeapTuple(* copy_heap_tuple)(TupleTableSlot *slot)
Definition tuptable.h:227
MinimalTuple(* get_minimal_tuple)(TupleTableSlot *slot)
Definition tuptable.h:217
void(* clear)(TupleTableSlot *slot)
Definition tuptable.h:164
void(* materialize)(TupleTableSlot *slot)
Definition tuptable.h:194
void(* release)(TupleTableSlot *slot)
Definition tuptable.h:156
TupleDesc tts_tupleDescriptor
Definition tuptable.h:129
const TupleTableSlotOps *const tts_ops
Definition tuptable.h:127
AttrNumber tts_nvalid
Definition tuptable.h:126
bool * tts_isnull
Definition tuptable.h:133
ItemPointerData tts_tid
Definition tuptable.h:142
Datum * tts_values
Definition tuptable.h:131
#define TableOidAttributeNumber
Definition sysattr.h:26
#define SelfItemPointerAttributeNumber
Definition sysattr.h:21
PGDLLIMPORT const TupleTableSlotOps TTSOpsMinimalTuple
Definition execTuples.c:86
static MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition tuptable.h:514
#define TTS_EMPTY(slot)
Definition tuptable.h:92
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition tuptable.h:376
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition tuptable.h:503
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:438
PGDLLIMPORT const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:417
static bool slot_is_current_xact_tuple(TupleTableSlot *slot)
Definition tuptable.h:467
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476
static MinimalTuple ExecCopySlotMinimalTupleExtra(TupleTableSlot *slot, Size extra)
Definition tuptable.h:526
PGDLLIMPORT const TupleTableSlotOps TTSOpsHeapTuple
Definition execTuples.c:85
static void slot_getallattrs(TupleTableSlot *slot)
Definition tuptable.h:390
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition tuptable.h:543
PGDLLIMPORT const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition execTuples.c:87
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition tuptable.h:494
static bool slot_attisnull(TupleTableSlot *slot, int attnum)
Definition tuptable.h:403
const char * type

◆ TTS_SHOULDFREE

#define TTS_SHOULDFREE (   slot)    (((slot)->tts_flags & TTS_FLAG_SHOULDFREE) != 0)

Definition at line 96 of file tuptable.h.

◆ TupIsNull

#define TupIsNull (   slot)     ((slot) == NULL || TTS_EMPTY(slot))

Definition at line 325 of file tuptable.h.

Typedef Documentation

◆ BufferHeapTupleTableSlot

◆ HeapTupleTableSlot

◆ MinimalTupleTableSlot

◆ TupleTableSlot

◆ TupleTableSlotOps

Definition at line 117 of file tuptable.h.

◆ VirtualTupleTableSlot

Function Documentation

◆ ExecAllocTableSlot()

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

Definition at line 1430 of file execTuples.c.

1432{
1433 TupleTableSlot *slot = MakeTupleTableSlot(desc, tts_ops, flags);
1434
1435 *tupleTable = lappend(*tupleTable, slot);
1436
1437 return slot;
1438}
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().

◆ ExecClearTuple()

static TupleTableSlot * ExecClearTuple ( TupleTableSlot slot)
inlinestatic

Definition at line 476 of file tuptable.h.

477{
478 slot->tts_ops->clear(slot);
479
480 return slot;
481}

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

Referenced by AfterTriggerExecute(), agg_retrieve_hash_table_in_memory(), apply_returning_filter(), ATRewriteTable(), begin_partition(), BitmapHeapNext(), buildSubPlanHash(), check_publications(), check_publications_origin_sequences(), check_publications_origin_tables(), CopyFrom(), CopyMultiInsertBufferFlush(), copyTemplateDependencies(), CteScanNext(), DefineTSConfiguration(), do_tup_output(), EnumValuesCreate(), eval_windowaggregates(), EvalPlanQual(), ExecAppend(), ExecAppendAsyncGetNext(), ExecARUpdateTriggers(), ExecBatchInsert(), ExecCheckTIDVisible(), ExecComputeStoredGenerated(), ExecDelete(), ExecDropSingleTupleTableSlot(), ExecEvalAggOrderedTransTuple(), ExecEvalPreOrderedDistinctMulti(), ExecFilterJunk(), ExecFindPartition(), ExecForceStoreHeapTuple(), ExecForceStoreMinimalTuple(), ExecHashJoinGetSavedTuple(), ExecHashSubPlan(), ExecIncrementalSort(), ExecInsert(), ExecLockRows(), ExecMaterial(), ExecMergeAppend(), ExecOnConflictLockRow(), ExecOnConflictSelect(), ExecOnConflictUpdate(), ExecParallelHashJoinOuterGetTuple(), ExecProject(), ExecProjectSRF(), ExecReScanAgg(), ExecReScanCteScan(), ExecReScanFunctionScan(), ExecReScanGroup(), ExecReScanIncrementalSort(), ExecReScanMaterial(), ExecReScanMergeJoin(), ExecReScanNamedTuplestoreScan(), ExecReScanSetOp(), ExecReScanSort(), ExecReScanTableFuncScan(), ExecReScanUnique(), ExecReScanValuesScan(), ExecReScanWindowAgg(), ExecReScanWorkTableScan(), ExecResetTupleTable(), ExecScanExtended(), ExecScanFetch(), ExecScanReScan(), ExecSetSlotDescriptor(), ExecSort(), ExecStoreAllNullTuple(), ExecStoreHeapTupleDatum(), ExecUnique(), execute_attr_map_slot(), ExecWindowAgg(), fetch_relation_list(), fetch_remote_slots(), fetch_remote_table_info(), fileIterateForeignScan(), finalize_aggregates(), FunctionNext(), gather_getnext(), gather_merge_clear_tuples(), gather_merge_init(), get_actual_variable_endpoint(), get_returning_data(), hashagg_spill_tuple(), heap_getnextslot(), heap_getnextslot_tidrange(), heapam_scan_analyze_next_tuple(), heapam_scan_sample_next_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), IndexNext(), IndexNextWithReorder(), IndexOnlyNext(), InsertPgAttributeTuples(), MakeConfigurationMapping(), MergePartitionsMoveRows(), ordered_set_shutdown(), ordered_set_transition_multi(), pgoutput_row_filter(), postgresIterateDirectModify(), postgresIterateForeignScan(), postquel_get_single_result(), postquel_start(), prepare_hash_slot(), prepare_probe_slot(), process_ordered_aggregate_multi(), recordMultipleDependencies(), RunFromStore(), setop_load_group(), setop_retrieve_hash_table(), setop_retrieve_sorted(), ShutdownSetExpr(), slot_modify_data(), slot_store_data(), SplitPartitionMoveRows(), StoreIndexTuple(), switchToPresortedPrefixMode(), tablesample_getnext(), tfuncLoadRows(), TidNext(), TidRangeNext(), tts_buffer_heap_copyslot(), tuplesort_gettupleslot(), tuplestore_gettupleslot(), tuplestore_gettupleslot_force(), update_frameheadpos(), update_frametailpos(), update_grouptailpos(), validate_remote_info(), ValuesNext(), and WinRowsArePeers().

◆ ExecCopySlot()

◆ ExecCopySlotHeapTuple()

◆ ExecCopySlotMinimalTuple()

static MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot slot)
inlinestatic

◆ ExecCopySlotMinimalTupleExtra()

static MinimalTuple ExecCopySlotMinimalTupleExtra ( TupleTableSlot slot,
Size  extra 
)
inlinestatic

Definition at line 526 of file tuptable.h.

527{
528 return slot->tts_ops->copy_minimal_tuple(slot, extra);
529}

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

Referenced by LookupTupleHashEntry_internal().

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot slot)
extern

Definition at line 1513 of file execTuples.c.

1514{
1515 /* This should match ExecResetTupleTable's processing of one slot */
1516 Assert(IsA(slot, TupleTableSlot));
1517 ExecClearTuple(slot);
1518 slot->tts_ops->release(slot);
1519 if (slot->tts_tupleDescriptor)
1521 if (!TTS_FIXED(slot))
1522 {
1523 if (slot->tts_values)
1524 pfree(slot->tts_values);
1525 if (slot->tts_isnull)
1526 pfree(slot->tts_isnull);
1527 }
1528 pfree(slot);
1529}
void pfree(void *pointer)
Definition mcxt.c:1616
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#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(), 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_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(), RI_Initial_Check(), RunFromStore(), SplitPartitionMoveRows(), systable_endscan(), systable_endscan_ordered(), table_index_fetch_tuple_check(), tstoreShutdownReceiver(), unique_key_recheck(), validateDomainCheckConstraint(), validateDomainNotNullConstraint(), and validateForeignKeyConstraint().

◆ ExecFetchSlotHeapTuple()

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

◆ ExecFetchSlotHeapTupleDatum()

Datum ExecFetchSlotHeapTupleDatum ( TupleTableSlot slot)
extern

Definition at line 1988 of file execTuples.c.

1989{
1990 HeapTuple tup;
1991 TupleDesc tupdesc;
1992 bool shouldFree;
1993 Datum ret;
1994
1995 /* Fetch slot's contents in regular-physical-tuple form */
1996 tup = ExecFetchSlotHeapTuple(slot, false, &shouldFree);
1997 tupdesc = slot->tts_tupleDescriptor;
1998
1999 /* Convert to Datum form */
2000 ret = heap_copy_tuple_as_datum(tup, tupdesc);
2001
2002 if (shouldFree)
2003 pfree(tup);
2004
2005 return ret;
2006}
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition heaptuple.c:1001

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 
)
extern

Definition at line 1957 of file execTuples.c.

1959{
1960 /*
1961 * sanity checks
1962 */
1963 Assert(slot != NULL);
1964 Assert(!TTS_EMPTY(slot));
1965
1966 if (slot->tts_ops->get_minimal_tuple)
1967 {
1968 if (shouldFree)
1969 *shouldFree = false;
1970 return slot->tts_ops->get_minimal_tuple(slot);
1971 }
1972 else
1973 {
1974 if (shouldFree)
1975 *shouldFree = true;
1976 return slot->tts_ops->copy_minimal_tuple(slot, 0);
1977 }
1978}

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 
)
extern

Definition at line 1734 of file execTuples.c.

1737{
1738 if (TTS_IS_HEAPTUPLE(slot))
1739 {
1740 ExecStoreHeapTuple(tuple, slot, shouldFree);
1741 }
1742 else if (TTS_IS_BUFFERTUPLE(slot))
1743 {
1746
1747 ExecClearTuple(slot);
1748 slot->tts_flags &= ~TTS_FLAG_EMPTY;
1750 bslot->base.tuple = heap_copytuple(tuple);
1753
1754 if (shouldFree)
1755 pfree(tuple);
1756 }
1757 else
1758 {
1759 ExecClearTuple(slot);
1761 slot->tts_values, slot->tts_isnull);
1763
1764 if (shouldFree)
1765 {
1766 ExecMaterializeSlot(slot);
1767 pfree(tuple);
1768 }
1769 }
1770}
HeapTuple heap_copytuple(HeapTuple tuple)
Definition heaptuple.c:698
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition heaptuple.c:1266
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
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
#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(), ExecIRDeleteTriggers(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecMergeMatched(), ExecModifyTable(), IndexNextWithReorder(), IndexOnlyNext(), and store_returning_result().

◆ ExecForceStoreMinimalTuple()

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

Definition at line 1777 of file execTuples.c.

1780{
1781 if (TTS_IS_MINIMALTUPLE(slot))
1782 {
1784 }
1785 else
1786 {
1787 HeapTupleData htup;
1788
1789 ExecClearTuple(slot);
1790
1791 htup.t_len = mtup->t_len + MINIMAL_TUPLE_OFFSET;
1792 htup.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
1794 slot->tts_values, slot->tts_isnull);
1796
1797 if (shouldFree)
1798 {
1799 ExecMaterializeSlot(slot);
1800 pfree(mtup);
1801 }
1802 }
1803}
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().

◆ ExecMaterializeSlot()

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List tupleTable,
bool  shouldFree 
)
extern

Definition at line 1450 of file execTuples.c.

1452{
1453 ListCell *lc;
1454
1455 foreach(lc, tupleTable)
1456 {
1458
1459 /* Always release resources and reset the slot to empty */
1460 ExecClearTuple(slot);
1461 slot->tts_ops->release(slot);
1462 if (slot->tts_tupleDescriptor)
1463 {
1465 slot->tts_tupleDescriptor = NULL;
1466 }
1467
1468 /* If shouldFree, release memory occupied by the slot itself */
1469 if (shouldFree)
1470 {
1471 if (!TTS_FIXED(slot))
1472 {
1473 if (slot->tts_values)
1474 pfree(slot->tts_values);
1475 if (slot->tts_isnull)
1476 pfree(slot->tts_isnull);
1477 }
1478 pfree(slot);
1479 }
1480 }
1481
1482 /* If shouldFree, release the list structure */
1483 if (shouldFree)
1485}
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 
)
extern

Definition at line 1548 of file execTuples.c.

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

Definition at line 1841 of file execTuples.c.

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

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 
)
extern

Definition at line 1657 of file execTuples.c.

1660{
1661 /*
1662 * sanity checks
1663 */
1664 Assert(tuple != NULL);
1665 Assert(slot != NULL);
1667 Assert(BufferIsValid(buffer));
1668
1669 if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1670 elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1671 tts_buffer_heap_store_tuple(slot, tuple, buffer, false);
1672
1673 slot->tts_tableOid = tuple->t_tableOid;
1674
1675 return slot;
1676}
static bool BufferIsValid(Buffer bufnum)
Definition bufmgr.h:423
#define unlikely(x)
Definition c.h:432
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
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 
)
extern

Definition at line 1617 of file execTuples.c.

1620{
1621 /*
1622 * sanity checks
1623 */
1624 Assert(tuple != NULL);
1625 Assert(slot != NULL);
1627
1628 if (unlikely(!TTS_IS_HEAPTUPLE(slot)))
1629 elog(ERROR, "trying to store a heap tuple into wrong type of slot");
1630 tts_heap_store_tuple(slot, tuple, shouldFree);
1631
1632 slot->tts_tableOid = tuple->t_tableOid;
1633
1634 return slot;
1635}
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(), and tts_heap_copyslot().

◆ ExecStoreHeapTupleDatum()

void ExecStoreHeapTupleDatum ( Datum  data,
TupleTableSlot slot 
)
extern

Definition at line 1871 of file execTuples.c.

1872{
1873 HeapTupleData tuple = {0};
1874 HeapTupleHeader td;
1875
1877
1879 tuple.t_self = td->t_ctid;
1880 tuple.t_data = td;
1881
1882 ExecClearTuple(slot);
1883
1885 slot->tts_values, slot->tts_isnull);
1887}
#define DatumGetHeapTupleHeader(X)
Definition fmgr.h:296
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
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 
)
extern

Definition at line 1683 of file execTuples.c.

1686{
1687 /*
1688 * sanity checks
1689 */
1690 Assert(tuple != NULL);
1691 Assert(slot != NULL);
1693 Assert(BufferIsValid(buffer));
1694
1695 if (unlikely(!TTS_IS_BUFFERTUPLE(slot)))
1696 elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot");
1697 tts_buffer_heap_store_tuple(slot, tuple, buffer, true);
1698
1699 slot->tts_tableOid = tuple->t_tableOid;
1700
1701 return slot;
1702}

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)
extern

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

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

Definition at line 1351 of file execTuples.c.

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

static bool slot_attisnull ( TupleTableSlot slot,
int  attnum 
)
inlinestatic

◆ slot_getallattrs()

◆ slot_getattr()

◆ slot_getmissingattrs()

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

Definition at line 2134 of file execTuples.c.

2135{
2137
2138 /* Check for invalid attnums */
2140 elog(ERROR, "invalid attribute number %d", lastAttNum);
2141
2142 if (slot->tts_tupleDescriptor->constr)
2144
2145 if (!attrmiss)
2146 {
2147 /* no missing values array at all, so just fill everything in as NULL */
2148 for (int attnum = startAttNum; attnum < lastAttNum; attnum++)
2149 {
2150 slot->tts_values[attnum] = (Datum) 0;
2151 slot->tts_isnull[attnum] = true;
2152 }
2153 }
2154 else
2155 {
2156 /* use attrmiss to set the missing values */
2157 for (int attnum = startAttNum; attnum < lastAttNum; attnum++)
2158 {
2159 slot->tts_values[attnum] = attrmiss[attnum].am_value;
2160 slot->tts_isnull[attnum] = !attrmiss[attnum].am_present;
2161 }
2162 }
2163}
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()

static void slot_getsomeattrs ( TupleTableSlot slot,
int  attnum 
)
inlinestatic

◆ slot_getsomeattrs_int()

void slot_getsomeattrs_int ( TupleTableSlot slot,
int  attnum 
)
extern

Definition at line 2170 of file execTuples.c.

2171{
2172 /* Check for caller errors */
2173 Assert(slot->tts_nvalid < attnum); /* checked in slot_getsomeattrs */
2174 Assert(attnum > 0);
2175
2176 /* Fetch as many attributes as possible from the underlying tuple. */
2177 slot->tts_ops->getsomeattrs(slot, attnum);
2178
2179 /*
2180 * Avoid putting new code here as that would prevent the compiler from
2181 * using the sibling call optimization for the above function.
2182 */
2183}

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

◆ slot_getsysattr()

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

Definition at line 438 of file tuptable.h.

439{
440 Assert(attnum < 0); /* caller error */
441
443 {
444 *isnull = false;
445 return ObjectIdGetDatum(slot->tts_tableOid);
446 }
448 {
449 *isnull = false;
450 return PointerGetDatum(&slot->tts_tid);
451 }
452
453 /* Fetch the system attribute from the underlying tuple. */
454 return slot->tts_ops->getsysattr(slot, attnum, isnull);
455}

References Assert, attnum, TupleTableSlotOps::getsysattr, ObjectIdGetDatum(), PointerGetDatum(), SelfItemPointerAttributeNumber, TableOidAttributeNumber, TupleTableSlot::tts_ops, TupleTableSlot::tts_tableOid, and TupleTableSlot::tts_tid.

Referenced by ExecCheckTupleVisible(), execCurrentOf(), ExecEvalSysVar(), ExecOnConflictLockRow(), FormIndexDatum(), and GetTupleTransactionInfo().

◆ slot_is_current_xact_tuple()

static bool slot_is_current_xact_tuple ( TupleTableSlot slot)
inlinestatic

Definition at line 467 of file tuptable.h.

468{
469 return slot->tts_ops->is_current_xact_tuple(slot);
470}

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

Referenced by RI_FKey_fk_upd_check_required().

Variable Documentation

◆ TTSOpsBufferHeapTuple

PGDLLIMPORT const TupleTableSlotOps TTSOpsBufferHeapTuple
extern

◆ TTSOpsHeapTuple

◆ TTSOpsMinimalTuple

◆ TTSOpsVirtual