PostgreSQL Source Code git master
Loading...
Searching...
No Matches
tableam.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * tableam.h
4 * POSTGRES table access method definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/access/tableam.h
11 *
12 * NOTES
13 * See tableam.sgml for higher level documentation.
14 *
15 *-------------------------------------------------------------------------
16 */
17#ifndef TABLEAM_H
18#define TABLEAM_H
19
20#include "access/relscan.h"
21#include "access/sdir.h"
22#include "access/xact.h"
23#include "executor/tuptable.h"
24#include "storage/read_stream.h"
25#include "utils/rel.h"
26#include "utils/snapshot.h"
27
28
29#define DEFAULT_TABLE_ACCESS_METHOD "heap"
30
31/* GUCs */
34
35
36/* forward references in this file */
38typedef struct IndexInfo IndexInfo;
40typedef struct ScanKeyData ScanKeyData;
43
44/*
45 * Bitmask values for the flags argument to the scan_begin callback.
46 */
47typedef enum ScanOptions
48{
50
51 /* one of SO_TYPE_* may be specified */
58
59 /* several of SO_ALLOW_* may be specified */
60 /* allow or disallow use of access strategy */
62 /* report location to syncscan logic? */
63 SO_ALLOW_SYNC = 1 << 7,
64 /* verify visibility page-at-a-time? */
66
67 /* unregister snapshot at scan end? */
69
70 /* set if the query doesn't modify the relation */
72
73 /* collect scan instrumentation */
76
77/*
78 * Mask of flags that are set internally by the table scan functions and
79 * shouldn't be passed by callers. Some of these are effectively set by callers
80 * through parameters to table scan functions (e.g. SO_ALLOW_STRAT/allow_strat),
81 * however, for now, retain tight control over them and don't allow users to
82 * pass these themselves to table scan functions.
83 */
84#define SO_INTERNAL_FLAGS \
85 (SO_TYPE_SEQSCAN | SO_TYPE_BITMAPSCAN | SO_TYPE_SAMPLESCAN | \
86 SO_TYPE_TIDSCAN | SO_TYPE_TIDRANGESCAN | SO_TYPE_ANALYZE | \
87 SO_ALLOW_STRAT | SO_ALLOW_SYNC | SO_ALLOW_PAGEMODE | \
88 SO_TEMP_SNAPSHOT)
89
90/*
91 * Result codes for table_{update,delete,lock_tuple}, and for visibility
92 * routines inside table AMs.
93 */
94typedef enum TM_Result
95{
96 /*
97 * Signals that the action succeeded (i.e. update/delete performed, lock
98 * was acquired)
99 */
101
102 /* The affected tuple wasn't visible to the relevant snapshot */
104
105 /* The affected tuple was already modified by the calling backend */
107
108 /*
109 * The affected tuple was updated by another transaction. This includes
110 * the case where tuple was moved to another partition.
111 */
113
114 /* The affected tuple was deleted by another transaction */
116
117 /*
118 * The affected tuple is currently being modified by another session. This
119 * will only be returned if table_(update/delete/lock_tuple) are
120 * instructed not to wait.
121 */
123
124 /* lock couldn't be acquired, action skipped. Only used by lock_tuple */
127
128/*
129 * Result codes for table_update(..., update_indexes*..).
130 * Used to determine which indexes to update.
131 */
133{
134 /* No indexed columns were updated (incl. TID addressing of tuple) */
136
137 /* A non-summarizing indexed column was updated, or the TID has changed */
139
140 /* Only summarized columns were updated, TID is unchanged */
143
144/*
145 * When table_tuple_update, table_tuple_delete, or table_tuple_lock fail
146 * because the target tuple is already outdated, they fill in this struct to
147 * provide information to the caller about what happened. When those functions
148 * succeed, the contents of this struct should not be relied upon, except for
149 * `traversed`, which may be set in both success and failure cases.
150 *
151 * ctid is the target's ctid link: it is the same as the target's TID if the
152 * target was deleted, or the location of the replacement tuple if the target
153 * was updated.
154 *
155 * xmax is the outdating transaction's XID. If the caller wants to visit the
156 * replacement tuple, it must check that this matches before believing the
157 * replacement is really a match. This is InvalidTransactionId if the target
158 * was !LP_NORMAL (expected only for a TID retrieved from syscache).
159 *
160 * cmax is the outdating command's CID, but only when the failure code is
161 * TM_SelfModified (i.e., something in the current transaction outdated the
162 * tuple); otherwise cmax is zero. (We make this restriction because
163 * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
164 * transactions.)
165 *
166 * traversed indicates if an update chain was followed in order to try to lock
167 * the target tuple. (This may be set in both success and failure cases.)
168 */
176
177/*
178 * State used when calling table_index_delete_tuples().
179 *
180 * Represents the status of table tuples, referenced by table TID and taken by
181 * index AM from index tuples. State consists of high level parameters of the
182 * deletion operation, plus two mutable palloc()'d arrays for information
183 * about the status of individual table tuples. These are conceptually one
184 * single array. Using two arrays keeps the TM_IndexDelete struct small,
185 * which makes sorting the first array (the deltids array) fast.
186 *
187 * Some index AM callers perform simple index tuple deletion (by specifying
188 * bottomup = false), and include only known-dead deltids. These known-dead
189 * entries are all marked knowndeletable = true directly (typically these are
190 * TIDs from LP_DEAD-marked index tuples), but that isn't strictly required.
191 *
192 * Callers that specify bottomup = true are "bottom-up index deletion"
193 * callers. The considerations for the tableam are more subtle with these
194 * callers because they ask the tableam to perform highly speculative work,
195 * and might only expect the tableam to check a small fraction of all entries.
196 * Caller is not allowed to specify knowndeletable = true for any entry
197 * because everything is highly speculative. Bottom-up caller provides
198 * context and hints to tableam -- see comments below for details on how index
199 * AMs and tableams should coordinate during bottom-up index deletion.
200 *
201 * Simple index deletion callers may ask the tableam to perform speculative
202 * work, too. This is a little like bottom-up deletion, but not too much.
203 * The tableam will only perform speculative work when it's practically free
204 * to do so in passing for simple deletion caller (while always performing
205 * whatever work is needed to enable knowndeletable/LP_DEAD index tuples to
206 * be deleted within index AM). This is the real reason why it's possible for
207 * simple index deletion caller to specify knowndeletable = false up front
208 * (this means "check if it's possible for me to delete corresponding index
209 * tuple when it's cheap to do so in passing"). The index AM should only
210 * include "extra" entries for index tuples whose TIDs point to a table block
211 * that tableam is expected to have to visit anyway (in the event of a block
212 * orientated tableam). The tableam isn't strictly obligated to check these
213 * "extra" TIDs, but a block-based AM should always manage to do so in
214 * practice.
215 *
216 * The final contents of the deltids/status arrays are interesting to callers
217 * that ask tableam to perform speculative work (i.e. when _any_ items have
218 * knowndeletable set to false up front). These index AM callers will
219 * naturally need to consult final state to determine which index tuples are
220 * in fact deletable.
221 *
222 * The index AM can keep track of which index tuple relates to which deltid by
223 * setting idxoffnum (and/or relying on each entry being uniquely identifiable
224 * using tid), which is important when the final contents of the array will
225 * need to be interpreted -- the array can shrink from initial size after
226 * tableam processing and/or have entries in a new order (tableam may sort
227 * deltids array for its own reasons). Bottom-up callers may find that final
228 * ndeltids is 0 on return from call to tableam, in which case no index tuple
229 * deletions are possible. Simple deletion callers can rely on any entries
230 * they know to be deletable appearing in the final array as deletable.
231 */
232typedef struct TM_IndexDelete
233{
234 ItemPointerData tid; /* table TID from index tuple */
235 int16 id; /* Offset into TM_IndexStatus array */
237
238typedef struct TM_IndexStatus
239{
240 OffsetNumber idxoffnum; /* Index am page offset number */
241 bool knowndeletable; /* Currently known to be deletable? */
242
243 /* Bottom-up index deletion specific fields follow */
244 bool promising; /* Promising (duplicate) index tuple? */
245 int16 freespace; /* Space freed in index if deleted */
247
248/*
249 * Index AM/tableam coordination is central to the design of bottom-up index
250 * deletion. The index AM provides hints about where to look to the tableam
251 * by marking some entries as "promising". Index AM does this with duplicate
252 * index tuples that are strongly suspected to be old versions left behind by
253 * UPDATEs that did not logically modify indexed values. Index AM may find it
254 * helpful to only mark entries as promising when they're thought to have been
255 * affected by such an UPDATE in the recent past.
256 *
257 * Bottom-up index deletion casts a wide net at first, usually by including
258 * all TIDs on a target index page. It is up to the tableam to worry about
259 * the cost of checking transaction status information. The tableam is in
260 * control, but needs careful guidance from the index AM. Index AM requests
261 * that bottomupfreespace target be met, while tableam measures progress
262 * towards that goal by tallying the per-entry freespace value for known
263 * deletable entries. (All !bottomup callers can just set these space related
264 * fields to zero.)
265 */
266typedef struct TM_IndexDeleteOp
267{
268 Relation irel; /* Target index relation */
269 BlockNumber iblknum; /* Index block number (for error reports) */
270 bool bottomup; /* Bottom-up (not simple) deletion? */
271 int bottomupfreespace; /* Bottom-up space target */
272
273 /* Mutable per-TID information follows (index AM initializes entries) */
274 int ndeltids; /* Current # of deltids/status elements */
278
279/*
280 * "options" flag bits for table_tuple_insert. Access methods may define
281 * their own bits for internal use, as long as they don't collide with these.
282 */
283/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
284#define TABLE_INSERT_SKIP_FSM 0x0002
285#define TABLE_INSERT_FROZEN 0x0004
286#define TABLE_INSERT_NO_LOGICAL 0x0008
287
288/* "options" flag bits for table_tuple_delete */
289#define TABLE_DELETE_CHANGING_PARTITION (1 << 0)
290#define TABLE_DELETE_NO_LOGICAL (1 << 1)
291
292/* "options" flag bits for table_tuple_update */
293#define TABLE_UPDATE_NO_LOGICAL (1 << 0)
294
295/* flag bits for table_tuple_lock */
296/* Follow tuples whose update is in progress if lock modes don't conflict */
297#define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS (1 << 0)
298/* Follow update chain and lock latest version of tuple */
299#define TUPLE_LOCK_FLAG_FIND_LAST_VERSION (1 << 1)
300
301
302/* Typedef for callback function for table_index_build_scan */
304 ItemPointer tid,
305 Datum *values,
306 bool *isnull,
307 bool tupleIsAlive,
308 void *state);
309
310/*
311 * API struct for a table AM. Note this must be allocated in a
312 * server-lifetime manner, typically as a static const struct, which then gets
313 * returned by FormData_pg_am.amhandler.
314 *
315 * In most cases it's not appropriate to call the callbacks directly, use the
316 * table_* wrapper functions instead.
317 *
318 * GetTableAmRoutine() asserts that required callbacks are filled in, remember
319 * to update when adding a callback.
320 */
321typedef struct TableAmRoutine
322{
323 /* this must be set to T_TableAmRoutine */
325
326
327 /* ------------------------------------------------------------------------
328 * Slot related callbacks.
329 * ------------------------------------------------------------------------
330 */
331
332 /*
333 * Return slot implementation suitable for storing a tuple of this AM.
334 */
335 const TupleTableSlotOps *(*slot_callbacks) (Relation rel);
336
337
338 /* ------------------------------------------------------------------------
339 * Table scan callbacks.
340 * ------------------------------------------------------------------------
341 */
342
343 /*
344 * Start a scan of `rel`. The callback has to return a TableScanDesc,
345 * which will typically be embedded in a larger, AM specific, struct.
346 *
347 * If nkeys != 0, the results need to be filtered by those scan keys.
348 *
349 * pscan, if not NULL, will have already been initialized with
350 * parallelscan_initialize(), and has to be for the same relation. Will
351 * only be set coming from table_beginscan_parallel().
352 *
353 * `flags` is a bitmask indicating the type of scan (ScanOptions's
354 * SO_TYPE_*, currently only one may be specified), options controlling
355 * the scan's behaviour (ScanOptions's SO_ALLOW_*, several may be
356 * specified, an AM may ignore unsupported ones), whether the snapshot
357 * needs to be deallocated at scan_end (ScanOptions's SO_TEMP_SNAPSHOT),
358 * and any number of the other ScanOptions values.
359 */
361 Snapshot snapshot,
362 int nkeys, ScanKeyData *key,
364 uint32 flags);
365
366 /*
367 * Release resources and deallocate scan. If TableScanDesc.temp_snap,
368 * TableScanDesc.rs_snapshot needs to be unregistered.
369 */
371
372 /*
373 * Restart relation scan. If set_params is set to true, allow_{strat,
374 * sync, pagemode} (see scan_begin) changes should be taken into account.
375 */
377 bool set_params, bool allow_strat,
378 bool allow_sync, bool allow_pagemode);
379
380 /*
381 * Return next tuple from `scan`, store in slot.
382 */
384 ScanDirection direction,
385 TupleTableSlot *slot);
386
387 /*-----------
388 * Optional functions to provide scanning for ranges of ItemPointers.
389 * Implementations must either provide both of these functions, or neither
390 * of them.
391 *
392 * Implementations of scan_set_tidrange must themselves handle
393 * ItemPointers of any value. i.e, they must handle each of the following:
394 *
395 * 1) mintid or maxtid is beyond the end of the table; and
396 * 2) mintid is above maxtid; and
397 * 3) item offset for mintid or maxtid is beyond the maximum offset
398 * allowed by the AM.
399 *
400 * Implementations can assume that scan_set_tidrange is always called
401 * before scan_getnextslot_tidrange or after scan_rescan and before any
402 * further calls to scan_getnextslot_tidrange.
403 */
407
408 /*
409 * Return next tuple from `scan` that's in the range of TIDs defined by
410 * scan_set_tidrange.
411 */
413 ScanDirection direction,
414 TupleTableSlot *slot);
415
416 /* ------------------------------------------------------------------------
417 * Parallel table scan related functions.
418 * ------------------------------------------------------------------------
419 */
420
421 /*
422 * Estimate the size of shared memory needed for a parallel scan of this
423 * relation. The snapshot does not need to be accounted for.
424 */
426
427 /*
428 * Initialize ParallelTableScanDesc for a parallel scan of this relation.
429 * `pscan` will be sized according to parallelscan_estimate() for the same
430 * relation.
431 */
434
435 /*
436 * Reinitialize `pscan` for a new scan. `rel` will be the same relation as
437 * when `pscan` was initialized by parallelscan_initialize.
438 */
441
442
443 /* ------------------------------------------------------------------------
444 * Index Scan Callbacks
445 * ------------------------------------------------------------------------
446 */
447
448 /*
449 * Prepare to fetch tuples from the relation, as needed when fetching
450 * tuples for an index scan. The callback has to return an
451 * IndexFetchTableData, which the AM will typically embed in a larger
452 * structure with additional information.
453 *
454 * flags is a bitmask of ScanOptions affecting underlying table scan
455 * behavior. See scan_begin() for more information on passing these.
456 *
457 * Tuples for an index scan can then be fetched via index_fetch_tuple.
458 */
459 struct IndexFetchTableData *(*index_fetch_begin) (Relation rel, uint32 flags);
460
461 /*
462 * Reset index fetch. Typically this will release cross index fetch
463 * resources held in IndexFetchTableData.
464 */
466
467 /*
468 * Release resources and deallocate index fetch.
469 */
471
472 /*
473 * Fetch tuple at `tid` into `slot`, after doing a visibility test
474 * according to `snapshot`. If a tuple was found and passed the visibility
475 * test, return true, false otherwise.
476 *
477 * Note that AMs that do not necessarily update indexes when indexed
478 * columns do not change, need to return the current/correct version of
479 * the tuple that is visible to the snapshot, even if the tid points to an
480 * older version of the tuple.
481 *
482 * *call_again is false on the first call to index_fetch_tuple for a tid.
483 * If there potentially is another tuple matching the tid, *call_again
484 * needs to be set to true by index_fetch_tuple, signaling to the caller
485 * that index_fetch_tuple should be called again for the same tid.
486 *
487 * *all_dead, if all_dead is not NULL, should be set to true by
488 * index_fetch_tuple iff it is guaranteed that no backend needs to see
489 * that tuple. Index AMs can use that to avoid returning that tid in
490 * future searches.
491 */
493 ItemPointer tid,
494 Snapshot snapshot,
495 TupleTableSlot *slot,
496 bool *call_again, bool *all_dead);
497
498
499 /* ------------------------------------------------------------------------
500 * Callbacks for non-modifying operations on individual tuples
501 * ------------------------------------------------------------------------
502 */
503
504 /*
505 * Fetch tuple at `tid` into `slot`, after doing a visibility test
506 * according to `snapshot`. If a tuple was found and passed the visibility
507 * test, returns true, false otherwise.
508 */
510 ItemPointer tid,
511 Snapshot snapshot,
512 TupleTableSlot *slot);
513
514 /*
515 * Is tid valid for a scan of this relation.
516 */
518 ItemPointer tid);
519
520 /*
521 * Return the latest version of the tuple at `tid`, by updating `tid` to
522 * point at the newest version.
523 */
525 ItemPointer tid);
526
527 /*
528 * Does the tuple in `slot` satisfy `snapshot`? The slot needs to be of
529 * the appropriate type for the AM.
530 */
532 TupleTableSlot *slot,
533 Snapshot snapshot);
534
535 /* see table_index_delete_tuples() */
538
539
540 /* ------------------------------------------------------------------------
541 * Manipulations of physical tuples.
542 * ------------------------------------------------------------------------
543 */
544
545 /* see table_tuple_insert() for reference about parameters */
548 BulkInsertStateData *bistate);
549
550 /* see table_tuple_insert_speculative() for reference about parameters */
552 TupleTableSlot *slot,
555 BulkInsertStateData *bistate,
557
558 /* see table_tuple_complete_speculative() for reference about parameters */
560 TupleTableSlot *slot,
562 bool succeeded);
563
564 /* see table_multi_insert() for reference about parameters */
565 void (*multi_insert) (Relation rel, TupleTableSlot **slots, int nslots,
567
568 /* see table_tuple_delete() for reference about parameters */
570 ItemPointer tid,
573 Snapshot snapshot,
575 bool wait,
576 TM_FailureData *tmfd);
577
578 /* see table_tuple_update() for reference about parameters */
581 TupleTableSlot *slot,
584 Snapshot snapshot,
586 bool wait,
587 TM_FailureData *tmfd,
588 LockTupleMode *lockmode,
590
591 /* see table_tuple_lock() for reference about parameters */
593 ItemPointer tid,
594 Snapshot snapshot,
595 TupleTableSlot *slot,
599 uint8 flags,
600 TM_FailureData *tmfd);
601
602 /*
603 * Perform operations necessary to complete insertions made via
604 * tuple_insert and multi_insert with a BulkInsertState specified. In-tree
605 * access methods ceased to use this.
606 *
607 * Typically callers of tuple_insert and multi_insert will just pass all
608 * the flags that apply to them, and each AM has to decide which of them
609 * make sense for it, and then only take actions in finish_bulk_insert for
610 * those flags, and ignore others.
611 *
612 * Optional callback.
613 */
615
616
617 /* ------------------------------------------------------------------------
618 * DDL related functionality.
619 * ------------------------------------------------------------------------
620 */
621
622 /*
623 * This callback needs to create new relation storage for `rel`, with
624 * appropriate durability behaviour for `persistence`.
625 *
626 * Note that only the subset of the relcache filled by
627 * RelationBuildLocalRelation() can be relied upon and that the relation's
628 * catalog entries will either not yet exist (new relation), or will still
629 * reference the old relfilelocator.
630 *
631 * As output *freezeXid, *minmulti must be set to the values appropriate
632 * for pg_class.{relfrozenxid, relminmxid}. For AMs that don't need those
633 * fields to be filled they can be set to InvalidTransactionId and
634 * InvalidMultiXactId, respectively.
635 *
636 * See also table_relation_set_new_filelocator().
637 */
640 char persistence,
643
644 /*
645 * This callback needs to remove all contents from `rel`'s current
646 * relfilelocator. No provisions for transactional behaviour need to be
647 * made. Often this can be implemented by truncating the underlying
648 * storage to its minimal size.
649 *
650 * See also table_relation_nontransactional_truncate().
651 */
653
654 /*
655 * See table_relation_copy_data().
656 *
657 * This can typically be implemented by directly copying the underlying
658 * storage, unless it contains references to the tablespace internally.
659 */
662
663 /* See table_relation_copy_for_cluster() */
667 bool use_sort,
668 TransactionId OldestXmin,
669 Snapshot snapshot,
672 double *num_tuples,
673 double *tups_vacuumed,
674 double *tups_recently_dead);
675
676 /*
677 * React to VACUUM command on the relation. The VACUUM can be triggered by
678 * a user or by autovacuum. The specific actions performed by the AM will
679 * depend heavily on the individual AM.
680 *
681 * On entry a transaction is already established, and the relation is
682 * locked with a ShareUpdateExclusive lock.
683 *
684 * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through
685 * this routine, even if (for ANALYZE) it is part of the same VACUUM
686 * command.
687 *
688 * There probably, in the future, needs to be a separate callback to
689 * integrate with autovacuum's scheduling.
690 */
692 const VacuumParams *params,
693 BufferAccessStrategy bstrategy);
694
695 /*
696 * Prepare to analyze block `blockno` of `scan`. The scan has been started
697 * with table_beginscan_analyze(). See also
698 * table_scan_analyze_next_block().
699 *
700 * The callback may acquire resources like locks that are held until
701 * table_scan_analyze_next_tuple() returns false. It e.g. can make sense
702 * to hold a lock until all tuples on a block have been analyzed by
703 * scan_analyze_next_tuple.
704 *
705 * The callback can return false if the block is not suitable for
706 * sampling, e.g. because it's a metapage that could never contain tuples.
707 *
708 * XXX: This obviously is primarily suited for block-based AMs. It's not
709 * clear what a good interface for non block based AMs would be, so there
710 * isn't one yet.
711 */
713 ReadStream *stream);
714
715 /*
716 * See table_scan_analyze_next_tuple().
717 *
718 * Not every AM might have a meaningful concept of dead rows, in which
719 * case it's OK to not increment *deadrows - but note that that may
720 * influence autovacuum scheduling (see comment for relation_vacuum
721 * callback).
722 */
724 double *liverows,
725 double *deadrows,
726 TupleTableSlot *slot);
727
728 /* see table_index_build_range_scan for reference about parameters */
732 bool allow_sync,
733 bool anyvisible,
734 bool progress,
738 void *callback_state,
739 TableScanDesc scan);
740
741 /* see table_index_validate_scan for reference about parameters */
745 Snapshot snapshot,
747
748
749 /* ------------------------------------------------------------------------
750 * Miscellaneous functions.
751 * ------------------------------------------------------------------------
752 */
753
754 /*
755 * See table_relation_size().
756 *
757 * Note that currently a few callers use the MAIN_FORKNUM size to figure
758 * out the range of potentially interesting blocks (brin, analyze). It's
759 * probable that we'll need to revise the interface for those at some
760 * point.
761 */
763
764
765 /*
766 * This callback should return true if the relation requires a TOAST table
767 * and false if it does not. It may wish to examine the relation's tuple
768 * descriptor before making a decision, but if it uses some other method
769 * of storing large values (or if it does not support them) it can simply
770 * return false.
771 */
773
774 /*
775 * This callback should return the OID of the table AM that implements
776 * TOAST tables for this AM. If the relation_needs_toast_table callback
777 * always returns false, this callback is not required.
778 */
780
781 /*
782 * This callback is invoked when detoasting a value stored in a toast
783 * table implemented by this AM. See table_relation_fetch_toast_slice()
784 * for more details.
785 */
790 varlena *result);
791
792
793 /* ------------------------------------------------------------------------
794 * Planner related functions.
795 * ------------------------------------------------------------------------
796 */
797
798 /*
799 * See table_relation_estimate_size().
800 *
801 * While block oriented, it shouldn't be too hard for an AM that doesn't
802 * internally use blocks to convert into a usable representation.
803 *
804 * This differs from the relation_size callback by returning size
805 * estimates (both relation size and tuple count) for planning purposes,
806 * rather than returning a currently correct estimate.
807 */
809 BlockNumber *pages, double *tuples,
810 double *allvisfrac);
811
812
813 /* ------------------------------------------------------------------------
814 * Executor related functions.
815 * ------------------------------------------------------------------------
816 */
817
818 /*
819 * Fetch the next tuple of a bitmap table scan into `slot` and return true
820 * if a visible tuple was found, false otherwise.
821 *
822 * `lossy_pages` is incremented if the bitmap is lossy for the selected
823 * page; otherwise, `exact_pages` is incremented. These are tracked for
824 * display in EXPLAIN ANALYZE output.
825 *
826 * Prefetching additional data from the bitmap is left to the table AM.
827 *
828 * This is an optional callback.
829 */
831 TupleTableSlot *slot,
832 bool *recheck,
833 uint64 *lossy_pages,
834 uint64 *exact_pages);
835
836 /*
837 * Prepare to fetch tuples from the next block in a sample scan. Return
838 * false if the sample scan is finished, true otherwise. `scan` was
839 * started via table_beginscan_sampling().
840 *
841 * Typically this will first determine the target block by calling the
842 * TsmRoutine's NextSampleBlock() callback if not NULL, or alternatively
843 * perform a sequential scan over all blocks. The determined block is
844 * then typically read and pinned.
845 *
846 * As the TsmRoutine interface is block based, a block needs to be passed
847 * to NextSampleBlock(). If that's not appropriate for an AM, it
848 * internally needs to perform mapping between the internal and a block
849 * based representation.
850 *
851 * Note that it's not acceptable to hold deadlock prone resources such as
852 * lwlocks until scan_sample_next_tuple() has exhausted the tuples on the
853 * block - the tuple is likely to be returned to an upper query node, and
854 * the next call could be off a long while. Holding buffer pins and such
855 * is obviously OK.
856 *
857 * Currently it is required to implement this interface, as there's no
858 * alternative way (contrary e.g. to bitmap scans) to implement sample
859 * scans. If infeasible to implement, the AM may raise an error.
860 */
863
864 /*
865 * This callback, only called after scan_sample_next_block has returned
866 * true, should determine the next tuple to be returned from the selected
867 * block using the TsmRoutine's NextSampleTuple() callback.
868 *
869 * The callback needs to perform visibility checks, and only return
870 * visible tuples. That obviously can mean calling NextSampleTuple()
871 * multiple times.
872 *
873 * The TsmRoutine interface assumes that there's a maximum offset on a
874 * given page, so if that doesn't apply to an AM, it needs to emulate that
875 * assumption somehow.
876 */
879 TupleTableSlot *slot);
880
882
883
884/* ----------------------------------------------------------------------------
885 * Slot functions.
886 * ----------------------------------------------------------------------------
887 */
888
889/*
890 * Returns slot callbacks suitable for holding tuples of the appropriate type
891 * for the relation. Works for tables, views, foreign tables and partitioned
892 * tables.
893 */
894extern const TupleTableSlotOps *table_slot_callbacks(Relation relation);
895
896/*
897 * Returns slot using the callbacks returned by table_slot_callbacks(), and
898 * registers it on *reglist.
899 */
901
902
903/* ----------------------------------------------------------------------------
904 * Table scan functions.
905 * ----------------------------------------------------------------------------
906 */
907
908/*
909 * A wrapper around the Table Access Method scan_begin callback, to centralize
910 * error checking. All calls to ->scan_begin() should go through this
911 * function.
912 *
913 * The caller-provided user_flags are validated against SO_INTERNAL_FLAGS to
914 * catch callers that accidentally pass scan-type or other internal flags.
915 */
916static TableScanDesc
920{
922 Assert((flags & ~SO_INTERNAL_FLAGS) == 0);
923 flags |= user_flags;
924
925 /*
926 * We don't allow scans to be started while CheckXidAlive is set, except
927 * via systable_beginscan() et al. See detailed comments in xact.c where
928 * these variables are declared.
929 */
931 elog(ERROR, "scan started during logical decoding");
932
933 return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, pscan, flags);
934}
935
936/*
937 * Start a scan of `rel`. Returned tuples pass a visibility test of
938 * `snapshot`, and if nkeys != 0, the results are filtered by those scan keys.
939 *
940 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
941 */
942static inline TableScanDesc
952
953/*
954 * Like table_beginscan(), but for scanning catalog. It'll automatically use a
955 * snapshot appropriate for scanning catalog relations.
956 */
957extern TableScanDesc table_beginscan_catalog(Relation relation, int nkeys,
958 ScanKeyData *key);
959
960/*
961 * Like table_beginscan(), but table_beginscan_strat() offers an extended API
962 * that lets the caller control whether a nondefault buffer access strategy
963 * can be used, and whether syncscan can be chosen (possibly resulting in the
964 * scan not starting from block zero). Both of these default to true with
965 * plain table_beginscan.
966 */
967static inline TableScanDesc
969 int nkeys, ScanKeyData *key,
970 bool allow_strat, bool allow_sync)
971{
973
974 if (allow_strat)
976 if (allow_sync)
978
979 return table_beginscan_common(rel, snapshot, nkeys, key, NULL,
980 flags, SO_NONE);
981}
982
983/*
984 * table_beginscan_bm is an alternative entry point for setting up a
985 * TableScanDesc for a bitmap heap scan. Although that scan technology is
986 * really quite unlike a standard seqscan, there is just enough commonality to
987 * make it worth using the same data structure.
988 *
989 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
990 */
991static inline TableScanDesc
993 int nkeys, ScanKeyData *key, uint32 flags)
994{
996
997 return table_beginscan_common(rel, snapshot, nkeys, key, NULL,
999}
1000
1001/*
1002 * table_beginscan_sampling is an alternative entry point for setting up a
1003 * TableScanDesc for a TABLESAMPLE scan. As with bitmap scans, it's worth
1004 * using the same data structure although the behavior is rather different.
1005 * In addition to the options offered by table_beginscan_strat, this call
1006 * also allows control of whether page-mode visibility checking is used.
1007 *
1008 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
1009 */
1010static inline TableScanDesc
1012 int nkeys, ScanKeyData *key,
1013 bool allow_strat, bool allow_sync,
1015{
1017
1018 if (allow_strat)
1020 if (allow_sync)
1022 if (allow_pagemode)
1024
1025 return table_beginscan_common(rel, snapshot, nkeys, key, NULL,
1027}
1028
1029/*
1030 * table_beginscan_tid is an alternative entry point for setting up a
1031 * TableScanDesc for a Tid scan. As with bitmap scans, it's worth using
1032 * the same data structure although the behavior is rather different.
1033 */
1034static inline TableScanDesc
1036{
1038
1039 return table_beginscan_common(rel, snapshot, 0, NULL, NULL,
1040 flags, SO_NONE);
1041}
1042
1043/*
1044 * table_beginscan_analyze is an alternative entry point for setting up a
1045 * TableScanDesc for an ANALYZE scan. As with bitmap scans, it's worth using
1046 * the same data structure although the behavior is rather different.
1047 */
1048static inline TableScanDesc
1056
1057/*
1058 * End relation scan.
1059 */
1060static inline void
1062{
1063 scan->rs_rd->rd_tableam->scan_end(scan);
1064}
1065
1066/*
1067 * Restart a relation scan.
1068 */
1069static inline void
1071{
1072 scan->rs_rd->rd_tableam->scan_rescan(scan, key, false, false, false, false);
1073}
1074
1075/*
1076 * Restart a relation scan after changing params.
1077 *
1078 * This call allows changing the buffer strategy, syncscan, and pagemode
1079 * options before starting a fresh scan. Note that although the actual use of
1080 * syncscan might change (effectively, enabling or disabling reporting), the
1081 * previously selected startblock will be kept.
1082 */
1083static inline void
1085 bool allow_strat, bool allow_sync, bool allow_pagemode)
1086{
1087 scan->rs_rd->rd_tableam->scan_rescan(scan, key, true,
1090}
1091
1092/*
1093 * Return next tuple from `scan`, store in slot.
1094 */
1095static inline bool
1097{
1098 slot->tts_tableOid = RelationGetRelid(sscan->rs_rd);
1099
1100 /* We don't expect actual scans using NoMovementScanDirection */
1101 Assert(direction == ForwardScanDirection ||
1102 direction == BackwardScanDirection);
1103
1104 return sscan->rs_rd->rd_tableam->scan_getnextslot(sscan, direction, slot);
1105}
1106
1107/* ----------------------------------------------------------------------------
1108 * TID Range scanning related functions.
1109 * ----------------------------------------------------------------------------
1110 */
1111
1112/*
1113 * table_beginscan_tidrange is the entry point for setting up a TableScanDesc
1114 * for a TID range scan.
1115 *
1116 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
1117 */
1118static inline TableScanDesc
1122{
1125
1126 sscan = table_beginscan_common(rel, snapshot, 0, NULL, NULL,
1128
1129 /* Set the range of TIDs to scan */
1130 sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
1131
1132 return sscan;
1133}
1134
1135/*
1136 * table_rescan_tidrange resets the scan position and sets the minimum and
1137 * maximum TID range to scan for a TableScanDesc created by
1138 * table_beginscan_tidrange.
1139 */
1140static inline void
1143{
1144 /* Ensure table_beginscan_tidrange() was used. */
1145 Assert((sscan->rs_flags & SO_TYPE_TIDRANGESCAN) != 0);
1146
1147 sscan->rs_rd->rd_tableam->scan_rescan(sscan, NULL, false, false, false, false);
1148 sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
1149}
1150
1151/*
1152 * Fetch the next tuple from `sscan` for a TID range scan created by
1153 * table_beginscan_tidrange(). Stores the tuple in `slot` and returns true,
1154 * or returns false if no more tuples exist in the range.
1155 */
1156static inline bool
1158 TupleTableSlot *slot)
1159{
1160 /* Ensure table_beginscan_tidrange() was used. */
1161 Assert((sscan->rs_flags & SO_TYPE_TIDRANGESCAN) != 0);
1162
1163 /* We don't expect actual scans using NoMovementScanDirection */
1164 Assert(direction == ForwardScanDirection ||
1165 direction == BackwardScanDirection);
1166
1167 return sscan->rs_rd->rd_tableam->scan_getnextslot_tidrange(sscan,
1168 direction,
1169 slot);
1170}
1171
1172
1173/* ----------------------------------------------------------------------------
1174 * Parallel table scan related functions.
1175 * ----------------------------------------------------------------------------
1176 */
1177
1178/*
1179 * Estimate the size of shared memory needed for a parallel scan of this
1180 * relation.
1181 */
1183
1184/*
1185 * Initialize ParallelTableScanDesc for a parallel scan of this
1186 * relation. `pscan` needs to be sized according to parallelscan_estimate()
1187 * for the same relation. Call this just once in the leader process; then,
1188 * individual workers attach via table_beginscan_parallel.
1189 */
1192 Snapshot snapshot);
1193
1194/*
1195 * Begin a parallel scan. `pscan` needs to have been initialized with
1196 * table_parallelscan_initialize(), for the same relation. The initialization
1197 * does not need to have happened in this backend.
1198 *
1199 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
1200 *
1201 * Caller must hold a suitable lock on the relation.
1202 */
1205 uint32 flags);
1206
1207/*
1208 * Begin a parallel tid range scan. `pscan` needs to have been initialized
1209 * with table_parallelscan_initialize(), for the same relation. The
1210 * initialization does not need to have happened in this backend.
1211 *
1212 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
1213 *
1214 * Caller must hold a suitable lock on the relation.
1215 */
1218 uint32 flags);
1219
1220/*
1221 * Restart a parallel scan. Call this in the leader process. Caller is
1222 * responsible for making sure that all workers have finished the scan
1223 * beforehand.
1224 */
1225static inline void
1230
1231
1232/* ----------------------------------------------------------------------------
1233 * Index scan related functions.
1234 * ----------------------------------------------------------------------------
1235 */
1236
1237/*
1238 * Prepare to fetch tuples from the relation, as needed when fetching tuples
1239 * for an index scan.
1240 *
1241 * flags is a bitmask of ScanOptions. No SO_INTERNAL_FLAGS are permitted.
1242 *
1243 * Tuples for an index scan can then be fetched via table_index_fetch_tuple().
1244 */
1245static inline IndexFetchTableData *
1247{
1248 Assert((flags & SO_INTERNAL_FLAGS) == 0);
1249
1250 /*
1251 * We don't allow scans to be started while CheckXidAlive is set, except
1252 * via systable_beginscan() et al. See detailed comments in xact.c where
1253 * these variables are declared.
1254 */
1256 elog(ERROR, "scan started during logical decoding");
1257
1259}
1260
1261/*
1262 * Reset index fetch. Typically this will release cross index fetch resources
1263 * held in IndexFetchTableData.
1264 */
1265static inline void
1270
1271/*
1272 * Release resources and deallocate index fetch.
1273 */
1274static inline void
1276{
1277 scan->rel->rd_tableam->index_fetch_end(scan);
1278}
1279
1280/*
1281 * Fetches, as part of an index scan, tuple at `tid` into `slot`, after doing
1282 * a visibility test according to `snapshot`. If a tuple was found and passed
1283 * the visibility test, returns true, false otherwise. Note that *tid may be
1284 * modified when we return true (see later remarks on multiple row versions
1285 * reachable via a single index entry).
1286 *
1287 * *call_again needs to be false on the first call to table_index_fetch_tuple() for
1288 * a tid. If there potentially is another tuple matching the tid, *call_again
1289 * will be set to true, signaling that table_index_fetch_tuple() should be called
1290 * again for the same tid.
1291 *
1292 * *all_dead, if all_dead is not NULL, will be set to true by
1293 * table_index_fetch_tuple() iff it is guaranteed that no backend needs to see
1294 * that tuple. Index AMs can use that to avoid returning that tid in future
1295 * searches.
1296 *
1297 * The difference between this function and table_tuple_fetch_row_version()
1298 * is that this function returns the currently visible version of a row if
1299 * the AM supports storing multiple row versions reachable via a single index
1300 * entry (like heap's HOT). Whereas table_tuple_fetch_row_version() only
1301 * evaluates the tuple exactly at `tid`. Outside of index entry ->table tuple
1302 * lookups, table_tuple_fetch_row_version() is what's usually needed.
1303 */
1304static inline bool
1306 ItemPointer tid,
1307 Snapshot snapshot,
1308 TupleTableSlot *slot,
1309 bool *call_again, bool *all_dead)
1310{
1311 return scan->rel->rd_tableam->index_fetch_tuple(scan, tid, snapshot,
1312 slot, call_again,
1313 all_dead);
1314}
1315
1316/*
1317 * This is a convenience wrapper around table_index_fetch_tuple() which
1318 * returns whether there are table tuple items corresponding to an index
1319 * entry. This likely is only useful to verify if there's a conflict in a
1320 * unique index.
1321 */
1323 ItemPointer tid,
1324 Snapshot snapshot,
1325 bool *all_dead);
1326
1327
1328/* ------------------------------------------------------------------------
1329 * Functions for non-modifying operations on individual tuples
1330 * ------------------------------------------------------------------------
1331 */
1332
1333
1334/*
1335 * Fetch tuple at `tid` into `slot`, after doing a visibility test according to
1336 * `snapshot`. If a tuple was found and passed the visibility test, returns
1337 * true, false otherwise.
1338 *
1339 * See table_index_fetch_tuple's comment about what the difference between
1340 * these functions is. It is correct to use this function outside of index
1341 * entry->table tuple lookups.
1342 */
1343static inline bool
1345 ItemPointer tid,
1346 Snapshot snapshot,
1347 TupleTableSlot *slot)
1348{
1349 /*
1350 * We don't expect direct calls to table_tuple_fetch_row_version with
1351 * valid CheckXidAlive for catalog or regular tables. See detailed
1352 * comments in xact.c where these variables are declared.
1353 */
1355 elog(ERROR, "unexpected table_tuple_fetch_row_version call during logical decoding");
1356
1357 return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot);
1358}
1359
1360/*
1361 * Verify that `tid` is a potentially valid tuple identifier. That doesn't
1362 * mean that the pointed to row needs to exist or be visible, but that
1363 * attempting to fetch the row (e.g. with table_tuple_get_latest_tid() or
1364 * table_tuple_fetch_row_version()) should not error out if called with that
1365 * tid.
1366 *
1367 * `scan` needs to have been started via table_beginscan().
1368 */
1369static inline bool
1371{
1372 return scan->rs_rd->rd_tableam->tuple_tid_valid(scan, tid);
1373}
1374
1375/*
1376 * Return the latest version of the tuple at `tid`, by updating `tid` to
1377 * point at the newest version.
1378 */
1380
1381/*
1382 * Return true iff tuple in slot satisfies the snapshot.
1383 *
1384 * This assumes the slot's tuple is valid, and of the appropriate type for the
1385 * AM.
1386 *
1387 * Some AMs might modify the data underlying the tuple as a side-effect. If so
1388 * they ought to mark the relevant buffer dirty.
1389 */
1390static inline bool
1392 Snapshot snapshot)
1393{
1394 return rel->rd_tableam->tuple_satisfies_snapshot(rel, slot, snapshot);
1395}
1396
1397/*
1398 * Determine which index tuples are safe to delete based on their table TID.
1399 *
1400 * Determines which entries from index AM caller's TM_IndexDeleteOp state
1401 * point to vacuumable table tuples. Entries that are found by tableam to be
1402 * vacuumable are naturally safe for index AM to delete, and so get directly
1403 * marked as deletable. See comments above TM_IndexDelete and comments above
1404 * TM_IndexDeleteOp for full details.
1405 *
1406 * Returns a snapshotConflictHorizon transaction ID that caller places in
1407 * its index deletion WAL record. This might be used during subsequent REDO
1408 * of the WAL record when in Hot Standby mode -- a recovery conflict for the
1409 * index deletion operation might be required on the standby.
1410 */
1411static inline TransactionId
1416
1417
1418/* ----------------------------------------------------------------------------
1419 * Functions for manipulations of physical tuples.
1420 * ----------------------------------------------------------------------------
1421 */
1422
1423/*
1424 * Insert a tuple from a slot into table AM routine.
1425 *
1426 * The options bitmask allows the caller to specify options that may change the
1427 * behaviour of the AM. The AM will ignore options that it does not support.
1428 *
1429 * If the TABLE_INSERT_SKIP_FSM option is specified, AMs are free to not reuse
1430 * free space in the relation. This can save some cycles when we know the
1431 * relation is new and doesn't contain useful amounts of free space.
1432 * TABLE_INSERT_SKIP_FSM is commonly passed directly to
1433 * RelationGetBufferForTuple. See that method for more information.
1434 *
1435 * TABLE_INSERT_FROZEN should only be specified for inserts into
1436 * relation storage created during the current subtransaction and when
1437 * there are no prior snapshots or pre-existing portals open.
1438 * This causes rows to be frozen, which is an MVCC violation and
1439 * requires explicit options chosen by user.
1440 *
1441 * TABLE_INSERT_NO_LOGICAL force-disables the emitting of logical decoding
1442 * information for the tuple. This should solely be used during table rewrites
1443 * where RelationIsLogicallyLogged(relation) is not yet accurate for the new
1444 * relation.
1445 *
1446 * Note that most of these options will be applied when inserting into the
1447 * heap's TOAST table, too, if the tuple requires any out-of-line data.
1448 *
1449 * The BulkInsertState object (if any; bistate can be NULL for default
1450 * behavior) is also just passed through to RelationGetBufferForTuple. If
1451 * `bistate` is provided, table_finish_bulk_insert() needs to be called.
1452 *
1453 * On return the slot's tts_tid and tts_tableOid are updated to reflect the
1454 * insertion. But note that any toasting of fields within the slot is NOT
1455 * reflected in the slots contents.
1456 */
1457static inline void
1464
1465/*
1466 * Perform a "speculative insertion". These can be backed out afterwards
1467 * without aborting the whole transaction. Other sessions can wait for the
1468 * speculative insertion to be confirmed, turning it into a regular tuple, or
1469 * aborted, as if it never existed. Speculatively inserted tuples behave as
1470 * "value locks" of short duration, used to implement INSERT .. ON CONFLICT.
1471 *
1472 * A transaction having performed a speculative insertion has to either abort,
1473 * or finish the speculative insertion with
1474 * table_tuple_complete_speculative(succeeded = ...).
1475 */
1476static inline void
1485
1486/*
1487 * Complete "speculative insertion" started in the same transaction. If
1488 * succeeded is true, the tuple is fully inserted, if false, it's removed.
1489 */
1490static inline void
1497
1498/*
1499 * Insert multiple tuples into a table.
1500 *
1501 * This is like table_tuple_insert(), but inserts multiple tuples in one
1502 * operation. That's often faster than calling table_tuple_insert() in a loop,
1503 * because e.g. the AM can reduce WAL logging and page locking overhead.
1504 *
1505 * Except for taking `nslots` tuples as input, and an array of TupleTableSlots
1506 * in `slots`, the parameters for table_multi_insert() are the same as for
1507 * table_tuple_insert().
1508 *
1509 * Note: this leaks memory into the current memory context. You can create a
1510 * temporary context before calling this, if that's a problem.
1511 */
1512static inline void
1515{
1516 rel->rd_tableam->multi_insert(rel, slots, nslots,
1517 cid, options, bistate);
1518}
1519
1520/*
1521 * Delete a tuple.
1522 *
1523 * NB: do not call this directly unless prepared to deal with
1524 * concurrent-update conditions. Use simple_table_tuple_delete instead.
1525 *
1526 * Input parameters:
1527 * rel - table to be modified (caller must hold suitable lock)
1528 * tid - TID of tuple to be deleted
1529 * cid - delete command ID (used for visibility test, and stored into
1530 * cmax if successful)
1531 * options - bitmask of options. Supported values:
1532 * TABLE_DELETE_CHANGING_PARTITION: the tuple is being moved to another
1533 * partition table due to an update of the partition key.
1534 * crosscheck - if not InvalidSnapshot, also check tuple against this
1535 * wait - true if should wait for any conflicting update to commit/abort
1536 *
1537 * Output parameters:
1538 * tmfd - filled in failure cases (see below)
1539 *
1540 * Normal, successful return value is TM_Ok, which means we did actually
1541 * delete it. Failure return codes are TM_SelfModified, TM_Updated, and
1542 * TM_BeingModified (the last only possible if wait == false).
1543 *
1544 * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1545 * t_xmax, and, if possible, t_cmax. See comments for struct
1546 * TM_FailureData for additional info.
1547 */
1548static inline TM_Result
1551 bool wait, TM_FailureData *tmfd)
1552{
1553 return rel->rd_tableam->tuple_delete(rel, tid, cid, options,
1554 snapshot, crosscheck,
1555 wait, tmfd);
1556}
1557
1558/*
1559 * Update a tuple.
1560 *
1561 * NB: do not call this directly unless you are prepared to deal with
1562 * concurrent-update conditions. Use simple_table_tuple_update instead.
1563 *
1564 * Input parameters:
1565 * rel - table to be modified (caller must hold suitable lock)
1566 * otid - TID of old tuple to be replaced
1567 * cid - update command ID (used for visibility test, and stored into
1568 * cmax/cmin if successful)
1569 * options - bitmask of options. No values are currently recognized.
1570 * crosscheck - if not InvalidSnapshot, also check old tuple against this
1571 * options - These allow the caller to specify options that may change the
1572 * behavior of the AM. The AM will ignore options that it does not support.
1573 * TABLE_UPDATE_WAIT -- set if should wait for any conflicting update to
1574 * commit/abort
1575 * TABLE_UPDATE_NO_LOGICAL -- force-disables the emitting of logical
1576 * decoding information for the tuple.
1577 *
1578 * Output parameters:
1579 * slot - newly constructed tuple data to store
1580 * tmfd - filled in failure cases (see below)
1581 * lockmode - filled with lock mode acquired on tuple
1582 * update_indexes - in success cases this is set if new index entries
1583 * are required for this tuple; see TU_UpdateIndexes
1584 *
1585 * Normal, successful return value is TM_Ok, which means we did actually
1586 * update it. Failure return codes are TM_SelfModified, TM_Updated, and
1587 * TM_BeingModified (the last only possible if wait == false).
1588 *
1589 * On success, the slot's tts_tid and tts_tableOid are updated to match the new
1590 * stored tuple; in particular, slot->tts_tid is set to the TID where the
1591 * new tuple was inserted, and its HEAP_ONLY_TUPLE flag is set iff a HOT
1592 * update was done. However, any TOAST changes in the new tuple's
1593 * data are not reflected into *newtup.
1594 *
1595 * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1596 * t_xmax, and, if possible, t_cmax. See comments for struct TM_FailureData
1597 * for additional info.
1598 */
1599static inline TM_Result
1602 Snapshot snapshot, Snapshot crosscheck,
1603 bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
1605{
1606 return rel->rd_tableam->tuple_update(rel, otid, slot,
1607 cid, options, snapshot, crosscheck,
1608 wait, tmfd,
1609 lockmode, update_indexes);
1610}
1611
1612/*
1613 * Lock a tuple in the specified mode.
1614 *
1615 * Input parameters:
1616 * rel: relation containing tuple (caller must hold suitable lock)
1617 * tid: TID of tuple to lock (updated if an update chain was followed)
1618 * snapshot: snapshot to use for visibility determinations
1619 * cid: current command ID (used for visibility test, and stored into
1620 * tuple's cmax if lock is successful)
1621 * mode: lock mode desired
1622 * wait_policy: what to do if tuple lock is not available
1623 * flags:
1624 * If TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS, follow the update chain to
1625 * also lock descendant tuples if lock modes don't conflict.
1626 * If TUPLE_LOCK_FLAG_FIND_LAST_VERSION, follow the update chain and lock
1627 * latest version.
1628 *
1629 * Output parameters:
1630 * *slot: contains the target tuple
1631 * *tmfd: filled in failure cases (see below)
1632 *
1633 * Function result may be:
1634 * TM_Ok: lock was successfully acquired
1635 * TM_Invisible: lock failed because tuple was never visible to us
1636 * TM_SelfModified: lock failed because tuple updated by self
1637 * TM_Updated: lock failed because tuple updated by other xact
1638 * TM_Deleted: lock failed because tuple deleted by other xact
1639 * TM_WouldBlock: lock couldn't be acquired and wait_policy is skip
1640 *
1641 * In the failure cases other than TM_Invisible and TM_Deleted, the routine
1642 * fills *tmfd with the tuple's t_ctid, t_xmax, and, if possible, t_cmax.
1643 * Additionally, in both success and failure cases, tmfd->traversed is set if
1644 * an update chain was followed. See comments for struct TM_FailureData for
1645 * additional info.
1646 */
1647static inline TM_Result
1651 TM_FailureData *tmfd)
1652{
1653 return rel->rd_tableam->tuple_lock(rel, tid, snapshot, slot,
1655 flags, tmfd);
1656}
1657
1658/*
1659 * Perform operations necessary to complete insertions made via
1660 * tuple_insert and multi_insert with a BulkInsertState specified.
1661 */
1662static inline void
1669
1670
1671/* ------------------------------------------------------------------------
1672 * DDL related functionality.
1673 * ------------------------------------------------------------------------
1674 */
1675
1676/*
1677 * Create storage for `rel` in `newrlocator`, with persistence set to
1678 * `persistence`.
1679 *
1680 * This is used both during relation creation and various DDL operations to
1681 * create new rel storage that can be filled from scratch. When creating
1682 * new storage for an existing relfilelocator, this should be called before the
1683 * relcache entry has been updated.
1684 *
1685 * *freezeXid, *minmulti are set to the xid / multixact horizon for the table
1686 * that pg_class.{relfrozenxid, relminmxid} have to be set to.
1687 */
1688static inline void
1699
1700/*
1701 * Remove all table contents from `rel`, in a non-transactional manner.
1702 * Non-transactional meaning that there's no need to support rollbacks. This
1703 * commonly only is used to perform truncations for relation storage created in
1704 * the current transaction.
1705 */
1706static inline void
1711
1712/*
1713 * Copy data from `rel` into the new relfilelocator `newrlocator`. The new
1714 * relfilelocator may not have storage associated before this function is
1715 * called. This is only supposed to be used for low level operations like
1716 * changing a relation's tablespace.
1717 */
1718static inline void
1723
1724/*
1725 * Copy data from `OldTable` into `NewTable`, as part of a CLUSTER or VACUUM
1726 * FULL.
1727 *
1728 * Additional Input parameters:
1729 * - use_sort - if true, the table contents are sorted appropriate for
1730 * `OldIndex`; if false and OldIndex is not InvalidOid, the data is copied
1731 * in that index's order; if false and OldIndex is InvalidOid, no sorting is
1732 * performed
1733 * - OldIndex - see use_sort
1734 * - OldestXmin - computed by vacuum_get_cutoffs(), even when
1735 * not needed for the relation's AM
1736 * - *xid_cutoff - ditto
1737 * - *multi_cutoff - ditto
1738 * - snapshot - if != NULL, ignore data changes done by transactions that this
1739 * (MVCC) snapshot considers still in-progress or in the future.
1740 *
1741 * Output parameters:
1742 * - *xid_cutoff - rel's new relfrozenxid value, may be invalid
1743 * - *multi_cutoff - rel's new relminmxid value, may be invalid
1744 * - *tups_vacuumed - stats, for logging, if appropriate for AM
1745 * - *tups_recently_dead - stats, for logging, if appropriate for AM
1746 */
1747static inline void
1750 bool use_sort,
1751 TransactionId OldestXmin,
1752 Snapshot snapshot,
1755 double *num_tuples,
1756 double *tups_vacuumed,
1757 double *tups_recently_dead)
1758{
1759 OldTable->rd_tableam->relation_copy_for_cluster(OldTable, NewTable, OldIndex,
1760 use_sort, OldestXmin,
1761 snapshot,
1763 num_tuples, tups_vacuumed,
1765}
1766
1767/*
1768 * Perform VACUUM on the relation. The VACUUM can be triggered by a user or by
1769 * autovacuum. The specific actions performed by the AM will depend heavily on
1770 * the individual AM.
1771 *
1772 * On entry a transaction needs to already been established, and the
1773 * table is locked with a ShareUpdateExclusive lock.
1774 *
1775 * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through this
1776 * routine, even if (for ANALYZE) it is part of the same VACUUM command.
1777 */
1778static inline void
1780 BufferAccessStrategy bstrategy)
1781{
1782 rel->rd_tableam->relation_vacuum(rel, params, bstrategy);
1783}
1784
1785/*
1786 * Prepare to analyze the next block in the read stream. The scan needs to
1787 * have been started with table_beginscan_analyze(). Note that this routine
1788 * might acquire resources like locks that are held until
1789 * table_scan_analyze_next_tuple() returns false.
1790 *
1791 * Returns false if block is unsuitable for sampling, true otherwise.
1792 */
1793static inline bool
1795{
1796 return scan->rs_rd->rd_tableam->scan_analyze_next_block(scan, stream);
1797}
1798
1799/*
1800 * Iterate over tuples in the block selected with
1801 * table_scan_analyze_next_block() (which needs to have returned true, and
1802 * this routine may not have returned false for the same block before). If a
1803 * tuple that's suitable for sampling is found, true is returned and a tuple
1804 * is stored in `slot`.
1805 *
1806 * *liverows and *deadrows are incremented according to the encountered
1807 * tuples.
1808 */
1809static inline bool
1811 double *liverows, double *deadrows,
1812 TupleTableSlot *slot)
1813{
1814 return scan->rs_rd->rd_tableam->scan_analyze_next_tuple(scan,
1816 slot);
1817}
1818
1819/*
1820 * table_index_build_scan - scan the table to find tuples to be indexed
1821 *
1822 * This is called back from an access-method-specific index build procedure
1823 * after the AM has done whatever setup it needs. The parent table relation
1824 * is scanned to find tuples that should be entered into the index. Each
1825 * such tuple is passed to the AM's callback routine, which does the right
1826 * things to add it to the new index. After we return, the AM's index
1827 * build procedure does whatever cleanup it needs.
1828 *
1829 * The total count of live tuples is returned. This is for updating pg_class
1830 * statistics. (It's annoying not to be able to do that here, but we want to
1831 * merge that update with others; see index_update_stats.) Note that the
1832 * index AM itself must keep track of the number of index tuples; we don't do
1833 * so here because the AM might reject some of the tuples for its own reasons,
1834 * such as being unable to store NULLs.
1835 *
1836 * If 'progress', the PROGRESS_SCAN_BLOCKS_TOTAL counter is updated when
1837 * starting the scan, and PROGRESS_SCAN_BLOCKS_DONE is updated as we go along.
1838 *
1839 * A side effect is to set indexInfo->ii_BrokenHotChain to true if we detect
1840 * any potentially broken HOT chains. Currently, we set this if there are any
1841 * RECENTLY_DEAD or DELETE_IN_PROGRESS entries in a HOT chain, without trying
1842 * very hard to detect whether they're really incompatible with the chain tip.
1843 * This only really makes sense for heap AM, it might need to be generalized
1844 * for other AMs later.
1845 */
1846static inline double
1850 bool allow_sync,
1851 bool progress,
1853 void *callback_state,
1854 TableScanDesc scan)
1855{
1856 return table_rel->rd_tableam->index_build_range_scan(table_rel,
1857 index_rel,
1858 index_info,
1859 allow_sync,
1860 false,
1861 progress,
1862 0,
1864 callback,
1865 callback_state,
1866 scan);
1867}
1868
1869/*
1870 * As table_index_build_scan(), except that instead of scanning the complete
1871 * table, only the given number of blocks are scanned. Scan to end-of-rel can
1872 * be signaled by passing InvalidBlockNumber as numblocks. Note that
1873 * restricting the range to scan cannot be done when requesting syncscan.
1874 *
1875 * When "anyvisible" mode is requested, all tuples visible to any transaction
1876 * are indexed and counted as live, including those inserted or deleted by
1877 * transactions that are still in progress.
1878 */
1879static inline double
1883 bool allow_sync,
1884 bool anyvisible,
1885 bool progress,
1889 void *callback_state,
1890 TableScanDesc scan)
1891{
1892 return table_rel->rd_tableam->index_build_range_scan(table_rel,
1893 index_rel,
1894 index_info,
1895 allow_sync,
1896 anyvisible,
1897 progress,
1899 numblocks,
1900 callback,
1901 callback_state,
1902 scan);
1903}
1904
1905/*
1906 * table_index_validate_scan - second table scan for concurrent index build
1907 *
1908 * See validate_index() for an explanation.
1909 */
1910static inline void
1914 Snapshot snapshot,
1916{
1917 table_rel->rd_tableam->index_validate_scan(table_rel,
1918 index_rel,
1919 index_info,
1920 snapshot,
1921 state);
1922}
1923
1924
1925/* ----------------------------------------------------------------------------
1926 * Miscellaneous functionality
1927 * ----------------------------------------------------------------------------
1928 */
1929
1930/*
1931 * Return the current size of `rel` in bytes. If `forkNumber` is
1932 * InvalidForkNumber, return the relation's overall size, otherwise the size
1933 * for the indicated fork.
1934 *
1935 * Note that the overall size might not be the equivalent of the sum of sizes
1936 * for the individual forks for some AMs, e.g. because the AMs storage does
1937 * not neatly map onto the builtin types of forks.
1938 */
1939static inline uint64
1944
1945/*
1946 * table_relation_needs_toast_table - does this relation need a toast table?
1947 */
1948static inline bool
1953
1954/*
1955 * Return the OID of the AM that should be used to implement the TOAST table
1956 * for this relation.
1957 */
1958static inline Oid
1963
1964/*
1965 * Fetch all or part of a TOAST value from a TOAST table.
1966 *
1967 * If this AM is never used to implement a TOAST table, then this callback
1968 * is not needed. But, if toasted values are ever stored in a table of this
1969 * type, then you will need this callback.
1970 *
1971 * toastrel is the relation in which the toasted value is stored.
1972 *
1973 * valueid identifies which toast value is to be fetched. For the heap,
1974 * this corresponds to the values stored in the chunk_id column.
1975 *
1976 * attrsize is the total size of the toast value to be fetched.
1977 *
1978 * sliceoffset is the offset within the toast value of the first byte that
1979 * should be fetched.
1980 *
1981 * slicelength is the number of bytes from the toast value that should be
1982 * fetched.
1983 *
1984 * result is caller-allocated space into which the fetched bytes should be
1985 * stored.
1986 */
1987static inline void
1997
1998
1999/* ----------------------------------------------------------------------------
2000 * Planner related functionality
2001 * ----------------------------------------------------------------------------
2002 */
2003
2004/*
2005 * Estimate the current size of the relation, as an AM specific workhorse for
2006 * estimate_rel_size(). Look there for an explanation of the parameters.
2007 */
2008static inline void
2010 BlockNumber *pages, double *tuples,
2011 double *allvisfrac)
2012{
2014 allvisfrac);
2015}
2016
2017
2018/* ----------------------------------------------------------------------------
2019 * Executor related functionality
2020 * ----------------------------------------------------------------------------
2021 */
2022
2023/*
2024 * Fetch / check / return tuples as part of a bitmap table scan. `scan` needs
2025 * to have been started via table_beginscan_bm(). Fetch the next tuple of a
2026 * bitmap table scan into `slot` and return true if a visible tuple was found,
2027 * false otherwise.
2028 *
2029 * `recheck` is set by the table AM to indicate whether or not the tuple in
2030 * `slot` should be rechecked. Tuples from lossy pages will always need to be
2031 * rechecked, but some non-lossy pages' tuples may also require recheck.
2032 *
2033 * `lossy_pages` is incremented if the block's representation in the bitmap is
2034 * lossy; otherwise, `exact_pages` is incremented.
2035 */
2036static inline bool
2038 TupleTableSlot *slot,
2039 bool *recheck,
2040 uint64 *lossy_pages,
2041 uint64 *exact_pages)
2042{
2043 return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
2044 slot,
2045 recheck,
2046 lossy_pages,
2047 exact_pages);
2048}
2049
2050/*
2051 * Prepare to fetch tuples from the next block in a sample scan. Returns false
2052 * if the sample scan is finished, true otherwise. `scan` needs to have been
2053 * started via table_beginscan_sampling().
2054 *
2055 * This will call the TsmRoutine's NextSampleBlock() callback if necessary
2056 * (i.e. NextSampleBlock is not NULL), or perform a sequential scan over the
2057 * underlying relation.
2058 */
2059static inline bool
2065
2066/*
2067 * Fetch the next sample tuple into `slot` and return true if a visible tuple
2068 * was found, false otherwise. table_scan_sample_next_block() needs to
2069 * previously have selected a block (i.e. returned true), and no previous
2070 * table_scan_sample_next_tuple() for the same block may have returned false.
2071 *
2072 * This will call the TsmRoutine's NextSampleTuple() callback.
2073 */
2074static inline bool
2082
2083
2084/* ----------------------------------------------------------------------------
2085 * Functions to make modifications a bit simpler.
2086 * ----------------------------------------------------------------------------
2087 */
2088
2091 Snapshot snapshot);
2093 TupleTableSlot *slot, Snapshot snapshot,
2095
2096
2097/* ----------------------------------------------------------------------------
2098 * Helper functions to implement parallel scans for block oriented AMs.
2099 * ----------------------------------------------------------------------------
2100 */
2101
2113 BlockNumber startblock,
2115
2116
2117/* ----------------------------------------------------------------------------
2118 * Helper functions to implement relation sizing for block oriented AMs.
2119 * ----------------------------------------------------------------------------
2120 */
2121
2125 BlockNumber *pages,
2126 double *tuples,
2127 double *allvisfrac,
2130
2131/* ----------------------------------------------------------------------------
2132 * Functions in tableamapi.c
2133 * ----------------------------------------------------------------------------
2134 */
2135
2136extern const TableAmRoutine *GetTableAmRoutine(Oid amhandler);
2137
2138/* ----------------------------------------------------------------------------
2139 * Functions in heapam_handler.c
2140 * ----------------------------------------------------------------------------
2141 */
2142
2143extern const TableAmRoutine *GetHeapamTableAmRoutine(void);
2144
2145#endif /* TABLEAM_H */
uint32 BlockNumber
Definition block.h:31
#define InvalidBlockNumber
Definition block.h:33
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define PGDLLIMPORT
Definition c.h:1421
uint8_t uint8
Definition c.h:622
#define Assert(condition)
Definition c.h:943
TransactionId MultiXactId
Definition c.h:746
int16_t int16
Definition c.h:619
int32_t int32
Definition c.h:620
uint64_t uint64
Definition c.h:625
#define unlikely(x)
Definition c.h:438
uint32_t uint32
Definition c.h:624
uint32 CommandId
Definition c.h:750
uint32 TransactionId
Definition c.h:736
size_t Size
Definition c.h:689
uint32 result
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
LockWaitPolicy
Definition lockoptions.h:38
LockTupleMode
Definition lockoptions.h:51
NodeTag
Definition nodes.h:27
uint16 OffsetNumber
Definition off.h:24
static PgChecksumMode mode
const void * data
static int progress
Definition pgbench.c:262
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
#define RelationGetRelid(relation)
Definition rel.h:516
ForkNumber
Definition relpath.h:56
struct TableScanDescData * TableScanDesc
Definition relscan.h:74
ScanDirection
Definition sdir.h:25
@ BackwardScanDirection
Definition sdir.h:26
@ ForwardScanDirection
Definition sdir.h:28
Definition pg_list.h:54
const struct TableAmRoutine * rd_tableam
Definition rel.h:189
TransactionId xmax
Definition tableam.h:172
CommandId cmax
Definition tableam.h:173
ItemPointerData ctid
Definition tableam.h:171
TM_IndexStatus * status
Definition tableam.h:276
int bottomupfreespace
Definition tableam.h:271
Relation irel
Definition tableam.h:268
TM_IndexDelete * deltids
Definition tableam.h:275
BlockNumber iblknum
Definition tableam.h:269
ItemPointerData tid
Definition tableam.h:234
bool knowndeletable
Definition tableam.h:241
int16 freespace
Definition tableam.h:245
OffsetNumber idxoffnum
Definition tableam.h:240
Size(* parallelscan_initialize)(Relation rel, ParallelTableScanDesc pscan)
Definition tableam.h:432
void(* relation_copy_data)(Relation rel, const RelFileLocator *newrlocator)
Definition tableam.h:660
TM_Result(* tuple_update)(Relation rel, ItemPointer otid, TupleTableSlot *slot, CommandId cid, uint32 options, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
Definition tableam.h:579
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition tableam.h:465
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition tableam.h:360
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition tableam.h:559
bool(* scan_analyze_next_tuple)(TableScanDesc scan, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition tableam.h:723
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition tableam.h:439
bool(* scan_sample_next_tuple)(TableScanDesc scan, SampleScanState *scanstate, TupleTableSlot *slot)
Definition tableam.h:877
bool(* scan_sample_next_block)(TableScanDesc scan, SampleScanState *scanstate)
Definition tableam.h:861
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
Definition tableam.h:524
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, uint32 options, BulkInsertStateData *bistate)
Definition tableam.h:546
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, TupleTableSlot *slot, bool *recheck, uint64 *lossy_pages, uint64 *exact_pages)
Definition tableam.h:830
bool(* scan_getnextslot_tidrange)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition tableam.h:412
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition tableam.h:808
bool(* relation_needs_toast_table)(Relation rel)
Definition tableam.h:772
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition tableam.h:517
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, uint32 options, BulkInsertStateData *bistate)
Definition tableam.h:565
void(* scan_end)(TableScanDesc scan)
Definition tableam.h:370
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
Definition tableam.h:762
TM_Result(* tuple_lock)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, uint8 flags, TM_FailureData *tmfd)
Definition tableam.h:592
void(* relation_fetch_toast_slice)(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, varlena *result)
Definition tableam.h:786
void(* relation_copy_for_cluster)(Relation OldTable, Relation NewTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, Snapshot snapshot, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
Definition tableam.h:664
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, uint32 options, BulkInsertStateData *bistate, uint32 specToken)
Definition tableam.h:551
void(* relation_nontransactional_truncate)(Relation rel)
Definition tableam.h:652
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, uint32 options, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd)
Definition tableam.h:569
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition tableam.h:509
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel, uint32 flags)
Definition tableam.h:459
Oid(* relation_toast_am)(Relation rel)
Definition tableam.h:779
bool(* scan_analyze_next_block)(TableScanDesc scan, ReadStream *stream)
Definition tableam.h:712
Size(* parallelscan_estimate)(Relation rel)
Definition tableam.h:425
void(* relation_set_new_filelocator)(Relation rel, const RelFileLocator *newrlocator, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition tableam.h:638
void(* scan_rescan)(TableScanDesc scan, ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition tableam.h:376
void(* scan_set_tidrange)(TableScanDesc scan, ItemPointer mintid, ItemPointer maxtid)
Definition tableam.h:404
TransactionId(* index_delete_tuples)(Relation rel, TM_IndexDeleteOp *delstate)
Definition tableam.h:536
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition tableam.h:470
bool(* index_fetch_tuple)(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition tableam.h:492
double(* index_build_range_scan)(Relation table_rel, Relation index_rel, IndexInfo *index_info, bool allow_sync, bool anyvisible, bool progress, BlockNumber start_blockno, BlockNumber numblocks, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
Definition tableam.h:729
NodeTag type
Definition tableam.h:324
void(* index_validate_scan)(Relation table_rel, Relation index_rel, IndexInfo *index_info, Snapshot snapshot, ValidateIndexState *state)
Definition tableam.h:742
void(* finish_bulk_insert)(Relation rel, uint32 options)
Definition tableam.h:614
void(* relation_vacuum)(Relation rel, const VacuumParams *params, BufferAccessStrategy bstrategy)
Definition tableam.h:691
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition tableam.h:383
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition tableam.h:531
Relation rs_rd
Definition relscan.h:36
Definition type.h:96
Definition c.h:776
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
Definition tableam.c:92
PGDLLIMPORT char * default_table_access_method
Definition tableam.c:49
ScanOptions
Definition tableam.h:48
@ SO_ALLOW_STRAT
Definition tableam.h:61
@ SO_TYPE_TIDRANGESCAN
Definition tableam.h:56
@ SO_TYPE_ANALYZE
Definition tableam.h:57
@ SO_TEMP_SNAPSHOT
Definition tableam.h:68
@ SO_TYPE_TIDSCAN
Definition tableam.h:55
@ SO_HINT_REL_READ_ONLY
Definition tableam.h:71
@ SO_ALLOW_PAGEMODE
Definition tableam.h:65
@ SO_TYPE_SAMPLESCAN
Definition tableam.h:54
@ SO_ALLOW_SYNC
Definition tableam.h:63
@ SO_NONE
Definition tableam.h:49
@ SO_TYPE_SEQSCAN
Definition tableam.h:52
@ SO_SCAN_INSTRUMENT
Definition tableam.h:74
@ SO_TYPE_BITMAPSCAN
Definition tableam.h:53
static void table_rescan_tidrange(TableScanDesc sscan, ItemPointer mintid, ItemPointer maxtid)
Definition tableam.h:1141
TU_UpdateIndexes
Definition tableam.h:133
@ TU_Summarizing
Definition tableam.h:141
@ TU_All
Definition tableam.h:138
@ TU_None
Definition tableam.h:135
static double table_index_build_range_scan(Relation table_rel, Relation index_rel, IndexInfo *index_info, bool allow_sync, bool anyvisible, bool progress, BlockNumber start_blockno, BlockNumber numblocks, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
Definition tableam.h:1880
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1061
void simple_table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot, Snapshot snapshot, TU_UpdateIndexes *update_indexes)
Definition tableam.c:361
static TableScanDesc table_beginscan_sampling(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode, uint32 flags)
Definition tableam.h:1011
bool table_index_fetch_tuple_check(Relation rel, ItemPointer tid, Snapshot snapshot, bool *all_dead)
Definition tableam.c:242
PGDLLIMPORT bool synchronize_seqscans
Definition tableam.c:50
Size table_block_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan)
Definition tableam.c:414
static void table_index_validate_scan(Relation table_rel, Relation index_rel, IndexInfo *index_info, Snapshot snapshot, ValidateIndexState *state)
Definition tableam.h:1911
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition tableam.h:1266
static uint64 table_relation_size(Relation rel, ForkNumber forkNumber)
Definition tableam.h:1940
static bool table_scan_sample_next_block(TableScanDesc scan, SampleScanState *scanstate)
Definition tableam.h:2060
TM_Result
Definition tableam.h:95
@ TM_Ok
Definition tableam.h:100
@ TM_BeingModified
Definition tableam.h:122
@ TM_Deleted
Definition tableam.h:115
@ TM_WouldBlock
Definition tableam.h:125
@ TM_Updated
Definition tableam.h:112
@ TM_SelfModified
Definition tableam.h:106
@ TM_Invisible
Definition tableam.h:103
TableScanDesc table_beginscan_parallel_tidrange(Relation relation, ParallelTableScanDesc pscan, uint32 flags)
Definition tableam.c:193
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, TupleTableSlot *slot, bool *recheck, uint64 *lossy_pages, uint64 *exact_pages)
Definition tableam.h:2037
static TM_Result table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, uint8 flags, TM_FailureData *tmfd)
Definition tableam.h:1648
void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot)
Definition tableam.c:302
static bool table_tuple_tid_valid(TableScanDesc scan, ItemPointer tid)
Definition tableam.h:1370
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, uint32 flags)
Definition tableam.h:992
static void table_rescan_set_params(TableScanDesc scan, ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition tableam.h:1084
static void table_tuple_insert_speculative(Relation rel, TupleTableSlot *slot, CommandId cid, uint32 options, BulkInsertStateData *bistate, uint32 specToken)
Definition tableam.h:1477
static bool table_scan_analyze_next_block(TableScanDesc scan, ReadStream *stream)
Definition tableam.h:1794
static bool table_relation_needs_toast_table(Relation rel)
Definition tableam.h:1949
static TableScanDesc table_beginscan_common(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags, uint32 user_flags)
Definition tableam.h:917
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc pscan, uint32 flags)
Definition tableam.c:166
static void table_tuple_complete_speculative(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition tableam.h:1491
static void table_index_fetch_end(struct IndexFetchTableData *scan)
Definition tableam.h:1275
static TableScanDesc table_beginscan_analyze(Relation rel)
Definition tableam.h:1049
const TableAmRoutine * GetTableAmRoutine(Oid amhandler)
Definition tableamapi.c:27
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition tableam.c:269
static void table_rescan(TableScanDesc scan, ScanKeyData *key)
Definition tableam.h:1070
static bool table_index_fetch_tuple(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition tableam.h:1305
const TableAmRoutine * GetHeapamTableAmRoutine(void)
void simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot)
Definition tableam.c:316
static void table_relation_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, varlena *result)
Definition tableam.h:1988
static TableScanDesc table_beginscan_tidrange(Relation rel, Snapshot snapshot, ItemPointer mintid, ItemPointer maxtid, uint32 flags)
Definition tableam.h:1119
void table_block_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition tableam.c:433
void(* IndexBuildCallback)(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
Definition tableam.h:303
uint64 table_block_relation_size(Relation rel, ForkNumber forkNumber)
Definition tableam.c:681
static void table_relation_copy_for_cluster(Relation OldTable, Relation NewTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, Snapshot snapshot, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
Definition tableam.h:1748
static void table_relation_set_new_filelocator(Relation rel, const RelFileLocator *newrlocator, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition tableam.h:1689
static bool table_scan_analyze_next_tuple(TableScanDesc scan, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition tableam.h:1810
static bool table_scan_getnextslot_tidrange(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition tableam.h:1157
static Oid table_relation_toast_am(Relation rel)
Definition tableam.h:1959
static void table_finish_bulk_insert(Relation rel, uint32 options)
Definition tableam.h:1663
static bool table_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate, TupleTableSlot *slot)
Definition tableam.h:2075
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, uint32 options, BulkInsertStateData *bistate)
Definition tableam.h:1458
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
Definition tableam.c:131
static void table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, uint32 options, BulkInsertStateData *bistate)
Definition tableam.h:1513
#define SO_INTERNAL_FLAGS
Definition tableam.h:84
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, uint32 flags)
Definition tableam.h:943
static double table_index_build_scan(Relation table_rel, Relation index_rel, IndexInfo *index_info, bool allow_sync, bool progress, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
Definition tableam.h:1847
static void table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
Definition tableam.h:1719
static TM_Result table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot, CommandId cid, uint32 options, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
Definition tableam.h:1600
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, bool allow_strat, bool allow_sync)
Definition tableam.h:968
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
Definition tableam.c:113
Size table_block_parallelscan_estimate(Relation rel)
Definition tableam.c:408
static void table_relation_estimate_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition tableam.h:2009
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition tableam.h:1096
void table_block_parallelscan_startblock_init(Relation rel, ParallelBlockTableScanWorker pbscanwork, ParallelBlockTableScanDesc pbscan, BlockNumber startblock, BlockNumber numblocks)
Definition tableam.c:453
static IndexFetchTableData * table_index_fetch_begin(Relation rel, uint32 flags)
Definition tableam.h:1246
static TM_Result table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid, uint32 options, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd)
Definition tableam.h:1549
static bool table_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition tableam.h:1391
static TransactionId table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate)
Definition tableam.h:1412
static void table_relation_nontransactional_truncate(Relation rel)
Definition tableam.h:1707
static void table_relation_vacuum(Relation rel, const VacuumParams *params, BufferAccessStrategy bstrategy)
Definition tableam.h:1779
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
Definition tableam.c:146
static bool table_tuple_fetch_row_version(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition tableam.h:1344
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition tableam.h:1226
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
Definition tableam.h:1035
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition tableam.c:59
BlockNumber table_block_parallelscan_nextpage(Relation rel, ParallelBlockTableScanWorker pbscanwork, ParallelBlockTableScanDesc pbscan)
Definition tableam.c:548
void table_block_relation_estimate_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac, Size overhead_bytes_per_tuple, Size usable_bytes_per_page)
Definition tableam.c:718
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
#define TransactionIdIsValid(xid)
Definition transam.h:41
bool bsysscan
Definition xact.c:102
TransactionId CheckXidAlive
Definition xact.c:101