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

TupleTableSlot * MakeTupleTableSlot (TupleDesc tupleDesc, const TupleTableSlotOps *tts_ops, uint16 flags)
 
TupleTableSlot * ExecAllocTableSlot (List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops, uint16 flags)
 
void ExecResetTupleTable (List *tupleTable, bool shouldFree)
 
TupleTableSlot * MakeSingleTupleTableSlot (TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
 
void ExecDropSingleTupleTableSlot (TupleTableSlot *slot)
 
void ExecSetSlotDescriptor (TupleTableSlot *slot, TupleDesc tupdesc)
 
TupleTableSlot * ExecStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreHeapTuple (HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlot * ExecStoreBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlot * ExecStorePinnedBufferHeapTuple (HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
 
TupleTableSlot * ExecStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
void ExecForceStoreMinimalTuple (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
 
TupleTableSlot * ExecStoreVirtualTuple (TupleTableSlot *slot)
 
TupleTableSlot * ExecStoreAllNullTuple (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 TupleTableSlot * ExecClearTuple (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 TupleTableSlot * ExecCopySlot (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/*
483 * ExecMaterializeSlot - force a slot into the "materialized" state.
484 *
485 * This causes the slot's tuple to be a local copy not dependent on any
486 * external storage (i.e. pointing into a Buffer, or having allocations in
487 * another memory context).
488 *
489 * A typical use for this operation is to prepare a computed tuple for being
490 * stored on disk. The original data may or may not be virtual, but in any
491 * case we need a private copy for heap_insert to scribble on.
492 */
493static inline void
495{
496 slot->tts_ops->materialize(slot);
497}
498
499/*
500 * ExecCopySlotHeapTuple - return HeapTuple allocated in caller's context
501 */
502static inline HeapTuple
504{
505 Assert(!TTS_EMPTY(slot));
506
507 return slot->tts_ops->copy_heap_tuple(slot);
508}
509
510/*
511 * ExecCopySlotMinimalTuple - return MinimalTuple allocated in caller's context
512 */
513static inline MinimalTuple
515{
516 return slot->tts_ops->copy_minimal_tuple(slot, 0);
517}
518
519/*
520 * ExecCopySlotMinimalTupleExtra - return MinimalTuple allocated in caller's
521 * context, with extra bytes (maxaligned and zeroed) before the tuple for data
522 * the caller wishes to store along with the tuple (without requiring the
523 * caller to make an additional allocation).
524 */
525static inline MinimalTuple
527{
528 return slot->tts_ops->copy_minimal_tuple(slot, extra);
529}
530
531/*
532 * ExecCopySlot - copy one slot's contents into another.
533 *
534 * If a source's system attributes are supposed to be accessed in the target
535 * slot, the target slot and source slot types need to match.
536 *
537 * Currently, 'dstslot' and 'srcslot' must have the same number of attributes.
538 * Future work could see this relaxed to allow the source to contain
539 * additional attributes and have the code here only copy over the leading
540 * attributes.
541 */
542static inline TupleTableSlot *
544{
546 Assert(srcslot != dstslot);
547 Assert(dstslot->tts_tupleDescriptor->natts ==
548 srcslot->tts_tupleDescriptor->natts);
549
550 dstslot->tts_ops->copyslot(dstslot, srcslot);
551
552 return dstslot;
553}
554
555#endif /* FRONTEND */
556
557#endif /* TUPTABLE_H */
int16 AttrNumber
Definition attnum.h:21
int Buffer
Definition buf.h:23
#define PGDLLIMPORT
Definition c.h:1478
#define Assert(condition)
Definition c.h:1002
uint16_t uint16
Definition c.h:682
uint32_t uint32
Definition c.h:683
size_t Size
Definition c.h:748
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:124
NodeTag
Definition nodes.h:27
int16 attnum
const void * data
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
#define PointerGetDatum(X)
Definition postgres.h:354
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:515
#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:504
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:527
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:544
PGDLLIMPORT const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition execTuples.c:87
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition tuptable.h:495
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 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}
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_concurrent_changes(), apply_returning_filter(), ATRewriteTable(), begin_partition(), BitmapHeapNext(), buildSubPlanHash(), 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(), repack_store_change(), 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(), ValuesNext(), and WinRowsArePeers().

◆ ExecCopySlot()

◆ ExecCopySlotHeapTuple()

◆ ExecCopySlotMinimalTuple()

static MinimalTuple ExecCopySlotMinimalTuple ( TupleTableSlot *  slot)
inlinestatic

◆ ExecCopySlotMinimalTupleExtra()

static MinimalTuple ExecCopySlotMinimalTupleExtra ( TupleTableSlot *  slot,
Size  extra 
)
inlinestatic

Definition at line 527 of file tuptable.h.

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

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

Referenced by LookupTupleHashEntry_internal().

◆ ExecDropSingleTupleTableSlot()

void ExecDropSingleTupleTableSlot ( TupleTableSlot *  slot)
extern

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}
void pfree(void *pointer)
Definition mcxt.c:1619
#define IsA(nodeptr, _type_)
Definition nodes.h:162
#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_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 
)
extern

◆ ExecFetchSlotHeapTupleDatum()

Datum ExecFetchSlotHeapTupleDatum ( TupleTableSlot *  slot)
extern

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

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}

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 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}
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
#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(), restore_tuple(), and store_returning_result().

◆ ExecForceStoreMinimalTuple()

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

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().

◆ ExecMaterializeSlot()

◆ ExecResetTupleTable()

void ExecResetTupleTable ( List *  tupleTable,
bool  shouldFree 
)
extern

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

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

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:1147

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 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:497
#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 
)
extern

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

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

◆ MakeSingleTupleTableSlot()

◆ MakeTupleTableSlot()

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

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:955
void * palloc0(Size size)
Definition mcxt.c:1420
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
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()

◆ slot_getallattrs()

◆ slot_getattr()

◆ slot_getmissingattrs()

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

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

◆ slot_getsomeattrs_int()

void slot_getsomeattrs_int ( TupleTableSlot *  slot,
int  attnum 
)
extern

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}

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