1/*-------------------------------------------------------------------------
4 * POSTGRES table access method definitions.
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/tableam.h
13 * See tableam.sgml for higher level documentation.
15 *-------------------------------------------------------------------------
30 #define DEFAULT_TABLE_ACCESS_METHOD "heap"
37/* forward references in this file */
44 * Bitmask values for the flags argument to the scan_begin callback.
48 /* one of SO_TYPE_* may be specified */
56 /* several of SO_ALLOW_* may be specified */
57 /* allow or disallow use of access strategy */
59 /* report location to syncscan logic? */
61 /* verify visibility page-at-a-time? */
64 /* unregister snapshot at scan end? */
69 * Result codes for table_{update,delete,lock_tuple}, and for visibility
70 * routines inside table AMs.
75 * Signals that the action succeeded (i.e. update/delete performed, lock
80 /* The affected tuple wasn't visible to the relevant snapshot */
83 /* The affected tuple was already modified by the calling backend */
87 * The affected tuple was updated by another transaction. This includes
88 * the case where tuple was moved to another partition.
92 /* The affected tuple was deleted by another transaction */
96 * The affected tuple is currently being modified by another session. This
97 * will only be returned if table_(update/delete/lock_tuple) are
98 * instructed not to wait.
102 /* lock couldn't be acquired, action skipped. Only used by lock_tuple */
107 * Result codes for table_update(..., update_indexes*..).
108 * Used to determine which indexes to update.
112 /* No indexed columns were updated (incl. TID addressing of tuple) */
115 /* A non-summarizing indexed column was updated, or the TID has changed */
118 /* Only summarized columns were updated, TID is unchanged */
123 * When table_tuple_update, table_tuple_delete, or table_tuple_lock fail
124 * because the target tuple is already outdated, they fill in this struct to
125 * provide information to the caller about what happened. When those functions
126 * succeed, the contents of this struct should not be relied upon, except for
127 * `traversed`, which may be set in both success and failure cases.
129 * ctid is the target's ctid link: it is the same as the target's TID if the
130 * target was deleted, or the location of the replacement tuple if the target
133 * xmax is the outdating transaction's XID. If the caller wants to visit the
134 * replacement tuple, it must check that this matches before believing the
135 * replacement is really a match. This is InvalidTransactionId if the target
136 * was !LP_NORMAL (expected only for a TID retrieved from syscache).
138 * cmax is the outdating command's CID, but only when the failure code is
139 * TM_SelfModified (i.e., something in the current transaction outdated the
140 * tuple); otherwise cmax is zero. (We make this restriction because
141 * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
144 * traversed indicates if an update chain was followed in order to try to lock
145 * the target tuple. (This may be set in both success and failure cases.)
156 * State used when calling table_index_delete_tuples().
158 * Represents the status of table tuples, referenced by table TID and taken by
159 * index AM from index tuples. State consists of high level parameters of the
160 * deletion operation, plus two mutable palloc()'d arrays for information
161 * about the status of individual table tuples. These are conceptually one
162 * single array. Using two arrays keeps the TM_IndexDelete struct small,
163 * which makes sorting the first array (the deltids array) fast.
165 * Some index AM callers perform simple index tuple deletion (by specifying
166 * bottomup = false), and include only known-dead deltids. These known-dead
167 * entries are all marked knowndeletable = true directly (typically these are
168 * TIDs from LP_DEAD-marked index tuples), but that isn't strictly required.
170 * Callers that specify bottomup = true are "bottom-up index deletion"
171 * callers. The considerations for the tableam are more subtle with these
172 * callers because they ask the tableam to perform highly speculative work,
173 * and might only expect the tableam to check a small fraction of all entries.
174 * Caller is not allowed to specify knowndeletable = true for any entry
175 * because everything is highly speculative. Bottom-up caller provides
176 * context and hints to tableam -- see comments below for details on how index
177 * AMs and tableams should coordinate during bottom-up index deletion.
179 * Simple index deletion callers may ask the tableam to perform speculative
180 * work, too. This is a little like bottom-up deletion, but not too much.
181 * The tableam will only perform speculative work when it's practically free
182 * to do so in passing for simple deletion caller (while always performing
183 * whatever work is needed to enable knowndeletable/LP_DEAD index tuples to
184 * be deleted within index AM). This is the real reason why it's possible for
185 * simple index deletion caller to specify knowndeletable = false up front
186 * (this means "check if it's possible for me to delete corresponding index
187 * tuple when it's cheap to do so in passing"). The index AM should only
188 * include "extra" entries for index tuples whose TIDs point to a table block
189 * that tableam is expected to have to visit anyway (in the event of a block
190 * orientated tableam). The tableam isn't strictly obligated to check these
191 * "extra" TIDs, but a block-based AM should always manage to do so in
194 * The final contents of the deltids/status arrays are interesting to callers
195 * that ask tableam to perform speculative work (i.e. when _any_ items have
196 * knowndeletable set to false up front). These index AM callers will
197 * naturally need to consult final state to determine which index tuples are
200 * The index AM can keep track of which index tuple relates to which deltid by
201 * setting idxoffnum (and/or relying on each entry being uniquely identifiable
202 * using tid), which is important when the final contents of the array will
203 * need to be interpreted -- the array can shrink from initial size after
204 * tableam processing and/or have entries in a new order (tableam may sort
205 * deltids array for its own reasons). Bottom-up callers may find that final
206 * ndeltids is 0 on return from call to tableam, in which case no index tuple
207 * deletions are possible. Simple deletion callers can rely on any entries
208 * they know to be deletable appearing in the final array as deletable.
213 int16 id;
/* Offset into TM_IndexStatus array */
221 /* Bottom-up index deletion specific fields follow */
222 bool promising;
/* Promising (duplicate) index tuple? */
227 * Index AM/tableam coordination is central to the design of bottom-up index
228 * deletion. The index AM provides hints about where to look to the tableam
229 * by marking some entries as "promising". Index AM does this with duplicate
230 * index tuples that are strongly suspected to be old versions left behind by
231 * UPDATEs that did not logically modify indexed values. Index AM may find it
232 * helpful to only mark entries as promising when they're thought to have been
233 * affected by such an UPDATE in the recent past.
235 * Bottom-up index deletion casts a wide net at first, usually by including
236 * all TIDs on a target index page. It is up to the tableam to worry about
237 * the cost of checking transaction status information. The tableam is in
238 * control, but needs careful guidance from the index AM. Index AM requests
239 * that bottomupfreespace target be met, while tableam measures progress
240 * towards that goal by tallying the per-entry freespace value for known
241 * deletable entries. (All !bottomup callers can just set these space related
248 bool bottomup;
/* Bottom-up (not simple) deletion? */
251 /* Mutable per-TID information follows (index AM initializes entries) */
252 int ndeltids;
/* Current # of deltids/status elements */
257/* "options" flag bits for table_tuple_insert */
258/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
259 #define TABLE_INSERT_SKIP_FSM 0x0002
260 #define TABLE_INSERT_FROZEN 0x0004
261 #define TABLE_INSERT_NO_LOGICAL 0x0008
263/* flag bits for table_tuple_lock */
264/* Follow tuples whose update is in progress if lock modes don't conflict */
265 #define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS (1 << 0)
266/* Follow update chain and lock latest version of tuple */
267 #define TUPLE_LOCK_FLAG_FIND_LAST_VERSION (1 << 1)
270/* Typedef for callback function for table_index_build_scan */
279 * API struct for a table AM. Note this must be allocated in a
280 * server-lifetime manner, typically as a static const struct, which then gets
281 * returned by FormData_pg_am.amhandler.
283 * In most cases it's not appropriate to call the callbacks directly, use the
284 * table_* wrapper functions instead.
286 * GetTableAmRoutine() asserts that required callbacks are filled in, remember
287 * to update when adding a callback.
291 /* this must be set to T_TableAmRoutine */
295 /* ------------------------------------------------------------------------
296 * Slot related callbacks.
297 * ------------------------------------------------------------------------
301 * Return slot implementation suitable for storing a tuple of this AM.
306 /* ------------------------------------------------------------------------
307 * Table scan callbacks.
308 * ------------------------------------------------------------------------
312 * Start a scan of `rel`. The callback has to return a TableScanDesc,
313 * which will typically be embedded in a larger, AM specific, struct.
315 * If nkeys != 0, the results need to be filtered by those scan keys.
317 * pscan, if not NULL, will have already been initialized with
318 * parallelscan_initialize(), and has to be for the same relation. Will
319 * only be set coming from table_beginscan_parallel().
321 * `flags` is a bitmask indicating the type of scan (ScanOptions's
322 * SO_TYPE_*, currently only one may be specified), options controlling
323 * the scan's behaviour (ScanOptions's SO_ALLOW_*, several may be
324 * specified, an AM may ignore unsupported ones) and whether the snapshot
325 * needs to be deallocated at scan_end (ScanOptions's SO_TEMP_SNAPSHOT).
334 * Release resources and deallocate scan. If TableScanDesc.temp_snap,
335 * TableScanDesc.rs_snapshot needs to be unregistered.
340 * Restart relation scan. If set_params is set to true, allow_{strat,
341 * sync, pagemode} (see scan_begin) changes should be taken into account.
344 bool set_params,
bool allow_strat,
345 bool allow_sync,
bool allow_pagemode);
348 * Return next tuple from `scan`, store in slot.
355 * Optional functions to provide scanning for ranges of ItemPointers.
356 * Implementations must either provide both of these functions, or neither
359 * Implementations of scan_set_tidrange must themselves handle
360 * ItemPointers of any value. i.e, they must handle each of the following:
362 * 1) mintid or maxtid is beyond the end of the table; and
363 * 2) mintid is above maxtid; and
364 * 3) item offset for mintid or maxtid is beyond the maximum offset
367 * Implementations can assume that scan_set_tidrange is always called
368 * before scan_getnextslot_tidrange or after scan_rescan and before any
369 * further calls to scan_getnextslot_tidrange.
376 * Return next tuple from `scan` that's in the range of TIDs defined by
383 /* ------------------------------------------------------------------------
384 * Parallel table scan related functions.
385 * ------------------------------------------------------------------------
389 * Estimate the size of shared memory needed for a parallel scan of this
390 * relation. The snapshot does not need to be accounted for.
395 * Initialize ParallelTableScanDesc for a parallel scan of this relation.
396 * `pscan` will be sized according to parallelscan_estimate() for the same
403 * Reinitialize `pscan` for a new scan. `rel` will be the same relation as
404 * when `pscan` was initialized by parallelscan_initialize.
410 /* ------------------------------------------------------------------------
411 * Index Scan Callbacks
412 * ------------------------------------------------------------------------
416 * Prepare to fetch tuples from the relation, as needed when fetching
417 * tuples for an index scan. The callback has to return an
418 * IndexFetchTableData, which the AM will typically embed in a larger
419 * structure with additional information.
421 * Tuples for an index scan can then be fetched via index_fetch_tuple.
426 * Reset index fetch. Typically this will release cross index fetch
427 * resources held in IndexFetchTableData.
432 * Release resources and deallocate index fetch.
437 * Fetch tuple at `tid` into `slot`, after doing a visibility test
438 * according to `snapshot`. If a tuple was found and passed the visibility
439 * test, return true, false otherwise.
441 * Note that AMs that do not necessarily update indexes when indexed
442 * columns do not change, need to return the current/correct version of
443 * the tuple that is visible to the snapshot, even if the tid points to an
444 * older version of the tuple.
446 * *call_again is false on the first call to index_fetch_tuple for a tid.
447 * If there potentially is another tuple matching the tid, *call_again
448 * needs to be set to true by index_fetch_tuple, signaling to the caller
449 * that index_fetch_tuple should be called again for the same tid.
451 * *all_dead, if all_dead is not NULL, should be set to true by
452 * index_fetch_tuple iff it is guaranteed that no backend needs to see
453 * that tuple. Index AMs can use that to avoid returning that tid in
460 bool *call_again,
bool *all_dead);
463 /* ------------------------------------------------------------------------
464 * Callbacks for non-modifying operations on individual tuples
465 * ------------------------------------------------------------------------
469 * Fetch tuple at `tid` into `slot`, after doing a visibility test
470 * according to `snapshot`. If a tuple was found and passed the visibility
471 * test, returns true, false otherwise.
479 * Is tid valid for a scan of this relation.
485 * Return the latest version of the tuple at `tid`, by updating `tid` to
486 * point at the newest version.
492 * Does the tuple in `slot` satisfy `snapshot`? The slot needs to be of
493 * the appropriate type for the AM.
499 /* see table_index_delete_tuples() */
504 /* ------------------------------------------------------------------------
505 * Manipulations of physical tuples.
506 * ------------------------------------------------------------------------
509 /* see table_tuple_insert() for reference about parameters */
514 /* see table_tuple_insert_speculative() for reference about parameters */
522 /* see table_tuple_complete_speculative() for reference about parameters */
528 /* see table_multi_insert() for reference about parameters */
532 /* see table_tuple_delete() for reference about parameters */
542 /* see table_tuple_update() for reference about parameters */
554 /* see table_tuple_lock() for reference about parameters */
566 * Perform operations necessary to complete insertions made via
567 * tuple_insert and multi_insert with a BulkInsertState specified. In-tree
568 * access methods ceased to use this.
570 * Typically callers of tuple_insert and multi_insert will just pass all
571 * the flags that apply to them, and each AM has to decide which of them
572 * make sense for it, and then only take actions in finish_bulk_insert for
573 * those flags, and ignore others.
580 /* ------------------------------------------------------------------------
581 * DDL related functionality.
582 * ------------------------------------------------------------------------
586 * This callback needs to create new relation storage for `rel`, with
587 * appropriate durability behaviour for `persistence`.
589 * Note that only the subset of the relcache filled by
590 * RelationBuildLocalRelation() can be relied upon and that the relation's
591 * catalog entries will either not yet exist (new relation), or will still
592 * reference the old relfilelocator.
594 * As output *freezeXid, *minmulti must be set to the values appropriate
595 * for pg_class.{relfrozenxid, relminmxid}. For AMs that don't need those
596 * fields to be filled they can be set to InvalidTransactionId and
597 * InvalidMultiXactId, respectively.
599 * See also table_relation_set_new_filelocator().
608 * This callback needs to remove all contents from `rel`'s current
609 * relfilelocator. No provisions for transactional behaviour need to be
610 * made. Often this can be implemented by truncating the underlying
611 * storage to its minimal size.
613 * See also table_relation_nontransactional_truncate().
618 * See table_relation_copy_data().
620 * This can typically be implemented by directly copying the underlying
621 * storage, unless it contains references to the tablespace internally.
626 /* See table_relation_copy_for_cluster() */
635 double *tups_vacuumed,
636 double *tups_recently_dead);
639 * React to VACUUM command on the relation. The VACUUM can be triggered by
640 * a user or by autovacuum. The specific actions performed by the AM will
641 * depend heavily on the individual AM.
643 * On entry a transaction is already established, and the relation is
644 * locked with a ShareUpdateExclusive lock.
646 * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through
647 * this routine, even if (for ANALYZE) it is part of the same VACUUM
650 * There probably, in the future, needs to be a separate callback to
651 * integrate with autovacuum's scheduling.
658 * Prepare to analyze block `blockno` of `scan`. The scan has been started
659 * with table_beginscan_analyze(). See also
660 * table_scan_analyze_next_block().
662 * The callback may acquire resources like locks that are held until
663 * table_scan_analyze_next_tuple() returns false. It e.g. can make sense
664 * to hold a lock until all tuples on a block have been analyzed by
665 * scan_analyze_next_tuple.
667 * The callback can return false if the block is not suitable for
668 * sampling, e.g. because it's a metapage that could never contain tuples.
670 * XXX: This obviously is primarily suited for block-based AMs. It's not
671 * clear what a good interface for non block based AMs would be, so there
678 * See table_scan_analyze_next_tuple().
680 * Not every AM might have a meaningful concept of dead rows, in which
681 * case it's OK to not increment *deadrows - but note that that may
682 * influence autovacuum scheduling (see comment for relation_vacuum
691 /* see table_index_build_range_scan for reference about parameters */
701 void *callback_state,
704 /* see table_index_validate_scan for reference about parameters */
712 /* ------------------------------------------------------------------------
713 * Miscellaneous functions.
714 * ------------------------------------------------------------------------
718 * See table_relation_size().
720 * Note that currently a few callers use the MAIN_FORKNUM size to figure
721 * out the range of potentially interesting blocks (brin, analyze). It's
722 * probable that we'll need to revise the interface for those at some
729 * This callback should return true if the relation requires a TOAST table
730 * and false if it does not. It may wish to examine the relation's tuple
731 * descriptor before making a decision, but if it uses some other method
732 * of storing large values (or if it does not support them) it can simply
738 * This callback should return the OID of the table AM that implements
739 * TOAST tables for this AM. If the relation_needs_toast_table callback
740 * always returns false, this callback is not required.
745 * This callback is invoked when detoasting a value stored in a toast
746 * table implemented by this AM. See table_relation_fetch_toast_slice()
756 /* ------------------------------------------------------------------------
757 * Planner related functions.
758 * ------------------------------------------------------------------------
762 * See table_relation_estimate_size().
764 * While block oriented, it shouldn't be too hard for an AM that doesn't
765 * internally use blocks to convert into a usable representation.
767 * This differs from the relation_size callback by returning size
768 * estimates (both relation size and tuple count) for planning purposes,
769 * rather than returning a currently correct estimate.
776 /* ------------------------------------------------------------------------
777 * Executor related functions.
778 * ------------------------------------------------------------------------
782 * Fetch the next tuple of a bitmap table scan into `slot` and return true
783 * if a visible tuple was found, false otherwise.
785 * `lossy_pages` is incremented if the bitmap is lossy for the selected
786 * page; otherwise, `exact_pages` is incremented. These are tracked for
787 * display in EXPLAIN ANALYZE output.
789 * Prefetching additional data from the bitmap is left to the table AM.
791 * This is an optional callback.
800 * Prepare to fetch tuples from the next block in a sample scan. Return
801 * false if the sample scan is finished, true otherwise. `scan` was
802 * started via table_beginscan_sampling().
804 * Typically this will first determine the target block by calling the
805 * TsmRoutine's NextSampleBlock() callback if not NULL, or alternatively
806 * perform a sequential scan over all blocks. The determined block is
807 * then typically read and pinned.
809 * As the TsmRoutine interface is block based, a block needs to be passed
810 * to NextSampleBlock(). If that's not appropriate for an AM, it
811 * internally needs to perform mapping between the internal and a block
812 * based representation.
814 * Note that it's not acceptable to hold deadlock prone resources such as
815 * lwlocks until scan_sample_next_tuple() has exhausted the tuples on the
816 * block - the tuple is likely to be returned to an upper query node, and
817 * the next call could be off a long while. Holding buffer pins and such
820 * Currently it is required to implement this interface, as there's no
821 * alternative way (contrary e.g. to bitmap scans) to implement sample
822 * scans. If infeasible to implement, the AM may raise an error.
828 * This callback, only called after scan_sample_next_block has returned
829 * true, should determine the next tuple to be returned from the selected
830 * block using the TsmRoutine's NextSampleTuple() callback.
832 * The callback needs to perform visibility checks, and only return
833 * visible tuples. That obviously can mean calling NextSampleTuple()
836 * The TsmRoutine interface assumes that there's a maximum offset on a
837 * given page, so if that doesn't apply to an AM, it needs to emulate that
838 * assumption somehow.
847/* ----------------------------------------------------------------------------
849 * ----------------------------------------------------------------------------
853 * Returns slot callbacks suitable for holding tuples of the appropriate type
854 * for the relation. Works for tables, views, foreign tables and partitioned
860 * Returns slot using the callbacks returned by table_slot_callbacks(), and
861 * registers it on *reglist.
866/* ----------------------------------------------------------------------------
867 * Table scan functions.
868 * ----------------------------------------------------------------------------
872 * Start a scan of `rel`. Returned tuples pass a visibility test of
873 * `snapshot`, and if nkeys != 0, the results are filtered by those scan keys.
886 * Like table_beginscan(), but for scanning catalog. It'll automatically use a
887 * snapshot appropriate for scanning catalog relations.
893 * Like table_beginscan(), but table_beginscan_strat() offers an extended API
894 * that lets the caller control whether a nondefault buffer access strategy
895 * can be used, and whether syncscan can be chosen (possibly resulting in the
896 * scan not starting from block zero). Both of these default to true with
897 * plain table_beginscan.
902 bool allow_strat,
bool allow_sync)
915 * table_beginscan_bm is an alternative entry point for setting up a
916 * TableScanDesc for a bitmap heap scan. Although that scan technology is
917 * really quite unlike a standard seqscan, there is just enough commonality to
918 * make it worth using the same data structure.
931 * table_beginscan_sampling is an alternative entry point for setting up a
932 * TableScanDesc for a TABLESAMPLE scan. As with bitmap scans, it's worth
933 * using the same data structure although the behavior is rather different.
934 * In addition to the options offered by table_beginscan_strat, this call
935 * also allows control of whether page-mode visibility checking is used.
940 bool allow_strat,
bool allow_sync,
956 * table_beginscan_tid is an alternative entry point for setting up a
957 * TableScanDesc for a Tid scan. As with bitmap scans, it's worth using
958 * the same data structure although the behavior is rather different.
969 * table_beginscan_analyze is an alternative entry point for setting up a
970 * TableScanDesc for an ANALYZE scan. As with bitmap scans, it's worth using
971 * the same data structure although the behavior is rather different.
991 * Restart a relation scan.
1000 * Restart a relation scan after changing params.
1002 * This call allows changing the buffer strategy, syncscan, and pagemode
1003 * options before starting a fresh scan. Note that although the actual use of
1004 * syncscan might change (effectively, enabling or disabling reporting), the
1005 * previously selected startblock will be kept.
1009 bool allow_strat,
bool allow_sync,
bool allow_pagemode)
1012 allow_strat, allow_sync,
1017 * Return next tuple from `scan`, store in slot.
1024 /* We don't expect actual scans using NoMovementScanDirection */
1029 * We don't expect direct calls to table_scan_getnextslot with valid
1030 * CheckXidAlive for catalog or regular tables. See detailed comments in
1031 * xact.c where these variables are declared.
1034 elog(
ERROR,
"unexpected table_scan_getnextslot call during logical decoding");
1039/* ----------------------------------------------------------------------------
1040 * TID Range scanning related functions.
1041 * ----------------------------------------------------------------------------
1045 * table_beginscan_tidrange is the entry point for setting up a TableScanDesc
1046 * for a TID range scan.
1058 /* Set the range of TIDs to scan */
1065 * table_rescan_tidrange resets the scan position and sets the minimum and
1066 * maximum TID range to scan for a TableScanDesc created by
1067 * table_beginscan_tidrange.
1073 /* Ensure table_beginscan_tidrange() was used. */
1081 * Fetch the next tuple from `sscan` for a TID range scan created by
1082 * table_beginscan_tidrange(). Stores the tuple in `slot` and returns true,
1083 * or returns false if no more tuples exist in the range.
1089 /* Ensure table_beginscan_tidrange() was used. */
1092 /* We don't expect actual scans using NoMovementScanDirection */
1102/* ----------------------------------------------------------------------------
1103 * Parallel table scan related functions.
1104 * ----------------------------------------------------------------------------
1108 * Estimate the size of shared memory needed for a parallel scan of this
1114 * Initialize ParallelTableScanDesc for a parallel scan of this
1115 * relation. `pscan` needs to be sized according to parallelscan_estimate()
1116 * for the same relation. Call this just once in the leader process; then,
1117 * individual workers attach via table_beginscan_parallel.
1124 * Begin a parallel scan. `pscan` needs to have been initialized with
1125 * table_parallelscan_initialize(), for the same relation. The initialization
1126 * does not need to have happened in this backend.
1128 * Caller must hold a suitable lock on the relation.
1134 * Restart a parallel scan. Call this in the leader process. Caller is
1135 * responsible for making sure that all workers have finished the scan
1145/* ----------------------------------------------------------------------------
1146 * Index scan related functions.
1147 * ----------------------------------------------------------------------------
1151 * Prepare to fetch tuples from the relation, as needed when fetching tuples
1152 * for an index scan.
1154 * Tuples for an index scan can then be fetched via table_index_fetch_tuple().
1163 * Reset index fetch. Typically this will release cross index fetch resources
1164 * held in IndexFetchTableData.
1173 * Release resources and deallocate index fetch.
1182 * Fetches, as part of an index scan, tuple at `tid` into `slot`, after doing
1183 * a visibility test according to `snapshot`. If a tuple was found and passed
1184 * the visibility test, returns true, false otherwise. Note that *tid may be
1185 * modified when we return true (see later remarks on multiple row versions
1186 * reachable via a single index entry).
1188 * *call_again needs to be false on the first call to table_index_fetch_tuple() for
1189 * a tid. If there potentially is another tuple matching the tid, *call_again
1190 * will be set to true, signaling that table_index_fetch_tuple() should be called
1191 * again for the same tid.
1193 * *all_dead, if all_dead is not NULL, will be set to true by
1194 * table_index_fetch_tuple() iff it is guaranteed that no backend needs to see
1195 * that tuple. Index AMs can use that to avoid returning that tid in future
1198 * The difference between this function and table_tuple_fetch_row_version()
1199 * is that this function returns the currently visible version of a row if
1200 * the AM supports storing multiple row versions reachable via a single index
1201 * entry (like heap's HOT). Whereas table_tuple_fetch_row_version() only
1202 * evaluates the tuple exactly at `tid`. Outside of index entry ->table tuple
1203 * lookups, table_tuple_fetch_row_version() is what's usually needed.
1210 bool *call_again,
bool *all_dead)
1213 * We don't expect direct calls to table_index_fetch_tuple with valid
1214 * CheckXidAlive for catalog or regular tables. See detailed comments in
1215 * xact.c where these variables are declared.
1218 elog(
ERROR,
"unexpected table_index_fetch_tuple call during logical decoding");
1226 * This is a convenience wrapper around table_index_fetch_tuple() which
1227 * returns whether there are table tuple items corresponding to an index
1228 * entry. This likely is only useful to verify if there's a conflict in a
1237/* ------------------------------------------------------------------------
1238 * Functions for non-modifying operations on individual tuples
1239 * ------------------------------------------------------------------------
1244 * Fetch tuple at `tid` into `slot`, after doing a visibility test according to
1245 * `snapshot`. If a tuple was found and passed the visibility test, returns
1246 * true, false otherwise.
1248 * See table_index_fetch_tuple's comment about what the difference between
1249 * these functions is. It is correct to use this function outside of index
1250 * entry->table tuple lookups.
1259 * We don't expect direct calls to table_tuple_fetch_row_version with
1260 * valid CheckXidAlive for catalog or regular tables. See detailed
1261 * comments in xact.c where these variables are declared.
1264 elog(
ERROR,
"unexpected table_tuple_fetch_row_version call during logical decoding");
1270 * Verify that `tid` is a potentially valid tuple identifier. That doesn't
1271 * mean that the pointed to row needs to exist or be visible, but that
1272 * attempting to fetch the row (e.g. with table_tuple_get_latest_tid() or
1273 * table_tuple_fetch_row_version()) should not error out if called with that
1276 * `scan` needs to have been started via table_beginscan().
1285 * Return the latest version of the tuple at `tid`, by updating `tid` to
1286 * point at the newest version.
1291 * Return true iff tuple in slot satisfies the snapshot.
1293 * This assumes the slot's tuple is valid, and of the appropriate type for the
1296 * Some AMs might modify the data underlying the tuple as a side-effect. If so
1297 * they ought to mark the relevant buffer dirty.
1307 * Determine which index tuples are safe to delete based on their table TID.
1309 * Determines which entries from index AM caller's TM_IndexDeleteOp state
1310 * point to vacuumable table tuples. Entries that are found by tableam to be
1311 * vacuumable are naturally safe for index AM to delete, and so get directly
1312 * marked as deletable. See comments above TM_IndexDelete and comments above
1313 * TM_IndexDeleteOp for full details.
1315 * Returns a snapshotConflictHorizon transaction ID that caller places in
1316 * its index deletion WAL record. This might be used during subsequent REDO
1317 * of the WAL record when in Hot Standby mode -- a recovery conflict for the
1318 * index deletion operation might be required on the standby.
1327/* ----------------------------------------------------------------------------
1328 * Functions for manipulations of physical tuples.
1329 * ----------------------------------------------------------------------------
1333 * Insert a tuple from a slot into table AM routine.
1335 * The options bitmask allows the caller to specify options that may change the
1336 * behaviour of the AM. The AM will ignore options that it does not support.
1338 * If the TABLE_INSERT_SKIP_FSM option is specified, AMs are free to not reuse
1339 * free space in the relation. This can save some cycles when we know the
1340 * relation is new and doesn't contain useful amounts of free space.
1341 * TABLE_INSERT_SKIP_FSM is commonly passed directly to
1342 * RelationGetBufferForTuple. See that method for more information.
1344 * TABLE_INSERT_FROZEN should only be specified for inserts into
1345 * relation storage created during the current subtransaction and when
1346 * there are no prior snapshots or pre-existing portals open.
1347 * This causes rows to be frozen, which is an MVCC violation and
1348 * requires explicit options chosen by user.
1350 * TABLE_INSERT_NO_LOGICAL force-disables the emitting of logical decoding
1351 * information for the tuple. This should solely be used during table rewrites
1352 * where RelationIsLogicallyLogged(relation) is not yet accurate for the new
1355 * Note that most of these options will be applied when inserting into the
1356 * heap's TOAST table, too, if the tuple requires any out-of-line data.
1358 * The BulkInsertState object (if any; bistate can be NULL for default
1359 * behavior) is also just passed through to RelationGetBufferForTuple. If
1360 * `bistate` is provided, table_finish_bulk_insert() needs to be called.
1362 * On return the slot's tts_tid and tts_tableOid are updated to reflect the
1363 * insertion. But note that any toasting of fields within the slot is NOT
1364 * reflected in the slots contents.
1375 * Perform a "speculative insertion". These can be backed out afterwards
1376 * without aborting the whole transaction. Other sessions can wait for the
1377 * speculative insertion to be confirmed, turning it into a regular tuple, or
1378 * aborted, as if it never existed. Speculatively inserted tuples behave as
1379 * "value locks" of short duration, used to implement INSERT .. ON CONFLICT.
1381 * A transaction having performed a speculative insertion has to either abort,
1382 * or finish the speculative insertion with
1383 * table_tuple_complete_speculative(succeeded = ...).
1392 bistate, specToken);
1396 * Complete "speculative insertion" started in the same transaction. If
1397 * succeeded is true, the tuple is fully inserted, if false, it's removed.
1401 uint32 specToken,
bool succeeded)
1408 * Insert multiple tuples into a table.
1410 * This is like table_tuple_insert(), but inserts multiple tuples in one
1411 * operation. That's often faster than calling table_tuple_insert() in a loop,
1412 * because e.g. the AM can reduce WAL logging and page locking overhead.
1414 * Except for taking `nslots` tuples as input, and an array of TupleTableSlots
1415 * in `slots`, the parameters for table_multi_insert() are the same as for
1416 * table_tuple_insert().
1418 * Note: this leaks memory into the current memory context. You can create a
1419 * temporary context before calling this, if that's a problem.
1432 * NB: do not call this directly unless prepared to deal with
1433 * concurrent-update conditions. Use simple_table_tuple_delete instead.
1436 * rel - table to be modified (caller must hold suitable lock)
1437 * tid - TID of tuple to be deleted
1438 * cid - delete command ID (used for visibility test, and stored into
1439 * cmax if successful)
1440 * crosscheck - if not InvalidSnapshot, also check tuple against this
1441 * wait - true if should wait for any conflicting update to commit/abort
1442 * changingPart - true iff the tuple is being moved to another partition
1443 * table due to an update of the partition key. Otherwise, false.
1445 * Output parameters:
1446 * tmfd - filled in failure cases (see below)
1448 * Normal, successful return value is TM_Ok, which means we did actually
1449 * delete it. Failure return codes are TM_SelfModified, TM_Updated, and
1450 * TM_BeingModified (the last only possible if wait == false).
1452 * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1453 * t_xmax, and, if possible, t_cmax. See comments for struct
1454 * TM_FailureData for additional info.
1462 snapshot, crosscheck,
1463 wait, tmfd, changingPart);
1469 * NB: do not call this directly unless you are prepared to deal with
1470 * concurrent-update conditions. Use simple_table_tuple_update instead.
1473 * rel - table to be modified (caller must hold suitable lock)
1474 * otid - TID of old tuple to be replaced
1475 * cid - update command ID (used for visibility test, and stored into
1476 * cmax/cmin if successful)
1477 * crosscheck - if not InvalidSnapshot, also check old tuple against this
1478 * wait - true if should wait for any conflicting update to commit/abort
1480 * Output parameters:
1481 * slot - newly constructed tuple data to store
1482 * tmfd - filled in failure cases (see below)
1483 * lockmode - filled with lock mode acquired on tuple
1484 * update_indexes - in success cases this is set to true if new index entries
1485 * are required for this tuple
1487 * Normal, successful return value is TM_Ok, which means we did actually
1488 * update it. Failure return codes are TM_SelfModified, TM_Updated, and
1489 * TM_BeingModified (the last only possible if wait == false).
1491 * On success, the slot's tts_tid and tts_tableOid are updated to match the new
1492 * stored tuple; in particular, slot->tts_tid is set to the TID where the
1493 * new tuple was inserted, and its HEAP_ONLY_TUPLE flag is set iff a HOT
1494 * update was done. However, any TOAST changes in the new tuple's
1495 * data are not reflected into *newtup.
1497 * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1498 * t_xmax, and, if possible, t_cmax. See comments for struct TM_FailureData
1499 * for additional info.
1508 cid, snapshot, crosscheck,
1510 lockmode, update_indexes);
1514 * Lock a tuple in the specified mode.
1517 * rel: relation containing tuple (caller must hold suitable lock)
1518 * tid: TID of tuple to lock (updated if an update chain was followed)
1519 * snapshot: snapshot to use for visibility determinations
1520 * cid: current command ID (used for visibility test, and stored into
1521 * tuple's cmax if lock is successful)
1522 * mode: lock mode desired
1523 * wait_policy: what to do if tuple lock is not available
1525 * If TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS, follow the update chain to
1526 * also lock descendant tuples if lock modes don't conflict.
1527 * If TUPLE_LOCK_FLAG_FIND_LAST_VERSION, follow the update chain and lock
1530 * Output parameters:
1531 * *slot: contains the target tuple
1532 * *tmfd: filled in failure cases (see below)
1534 * Function result may be:
1535 * TM_Ok: lock was successfully acquired
1536 * TM_Invisible: lock failed because tuple was never visible to us
1537 * TM_SelfModified: lock failed because tuple updated by self
1538 * TM_Updated: lock failed because tuple updated by other xact
1539 * TM_Deleted: lock failed because tuple deleted by other xact
1540 * TM_WouldBlock: lock couldn't be acquired and wait_policy is skip
1542 * In the failure cases other than TM_Invisible and TM_Deleted, the routine
1543 * fills *tmfd with the tuple's t_ctid, t_xmax, and, if possible, t_cmax.
1544 * Additionally, in both success and failure cases, tmfd->traversed is set if
1545 * an update chain was followed. See comments for struct TM_FailureData for
1555 cid,
mode, wait_policy,
1560 * Perform operations necessary to complete insertions made via
1561 * tuple_insert and multi_insert with a BulkInsertState specified.
1566 /* optional callback */
1572/* ------------------------------------------------------------------------
1573 * DDL related functionality.
1574 * ------------------------------------------------------------------------
1578 * Create storage for `rel` in `newrlocator`, with persistence set to
1581 * This is used both during relation creation and various DDL operations to
1582 * create new rel storage that can be filled from scratch. When creating
1583 * new storage for an existing relfilelocator, this should be called before the
1584 * relcache entry has been updated.
1586 * *freezeXid, *minmulti are set to the xid / multixact horizon for the table
1587 * that pg_class.{relfrozenxid, relminmxid} have to be set to.
1597 persistence, freezeXid,
1602 * Remove all table contents from `rel`, in a non-transactional manner.
1603 * Non-transactional meaning that there's no need to support rollbacks. This
1604 * commonly only is used to perform truncations for relation storage created in
1605 * the current transaction.
1614 * Copy data from `rel` into the new relfilelocator `newrlocator`. The new
1615 * relfilelocator may not have storage associated before this function is
1616 * called. This is only supposed to be used for low level operations like
1617 * changing a relation's tablespace.
1626 * Copy data from `OldTable` into `NewTable`, as part of a CLUSTER or VACUUM
1629 * Additional Input parameters:
1630 * - use_sort - if true, the table contents are sorted appropriate for
1631 * `OldIndex`; if false and OldIndex is not InvalidOid, the data is copied
1632 * in that index's order; if false and OldIndex is InvalidOid, no sorting is
1634 * - OldIndex - see use_sort
1635 * - OldestXmin - computed by vacuum_get_cutoffs(), even when
1636 * not needed for the relation's AM
1637 * - *xid_cutoff - ditto
1638 * - *multi_cutoff - ditto
1640 * Output parameters:
1641 * - *xid_cutoff - rel's new relfrozenxid value, may be invalid
1642 * - *multi_cutoff - rel's new relminmxid value, may be invalid
1643 * - *tups_vacuumed - stats, for logging, if appropriate for AM
1644 * - *tups_recently_dead - stats, for logging, if appropriate for AM
1654 double *tups_vacuumed,
1655 double *tups_recently_dead)
1658 use_sort, OldestXmin,
1659 xid_cutoff, multi_cutoff,
1660 num_tuples, tups_vacuumed,
1661 tups_recently_dead);
1665 * Perform VACUUM on the relation. The VACUUM can be triggered by a user or by
1666 * autovacuum. The specific actions performed by the AM will depend heavily on
1667 * the individual AM.
1669 * On entry a transaction needs to already been established, and the
1670 * table is locked with a ShareUpdateExclusive lock.
1672 * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through this
1673 * routine, even if (for ANALYZE) it is part of the same VACUUM command.
1683 * Prepare to analyze the next block in the read stream. The scan needs to
1684 * have been started with table_beginscan_analyze(). Note that this routine
1685 * might acquire resources like locks that are held until
1686 * table_scan_analyze_next_tuple() returns false.
1688 * Returns false if block is unsuitable for sampling, true otherwise.
1697 * Iterate over tuples in the block selected with
1698 * table_scan_analyze_next_block() (which needs to have returned true, and
1699 * this routine may not have returned false for the same block before). If a
1700 * tuple that's suitable for sampling is found, true is returned and a tuple
1701 * is stored in `slot`.
1703 * *liverows and *deadrows are incremented according to the encountered
1708 double *liverows,
double *deadrows,
1717 * table_index_build_scan - scan the table to find tuples to be indexed
1719 * This is called back from an access-method-specific index build procedure
1720 * after the AM has done whatever setup it needs. The parent table relation
1721 * is scanned to find tuples that should be entered into the index. Each
1722 * such tuple is passed to the AM's callback routine, which does the right
1723 * things to add it to the new index. After we return, the AM's index
1724 * build procedure does whatever cleanup it needs.
1726 * The total count of live tuples is returned. This is for updating pg_class
1727 * statistics. (It's annoying not to be able to do that here, but we want to
1728 * merge that update with others; see index_update_stats.) Note that the
1729 * index AM itself must keep track of the number of index tuples; we don't do
1730 * so here because the AM might reject some of the tuples for its own reasons,
1731 * such as being unable to store NULLs.
1733 * If 'progress', the PROGRESS_SCAN_BLOCKS_TOTAL counter is updated when
1734 * starting the scan, and PROGRESS_SCAN_BLOCKS_DONE is updated as we go along.
1736 * A side effect is to set indexInfo->ii_BrokenHotChain to true if we detect
1737 * any potentially broken HOT chains. Currently, we set this if there are any
1738 * RECENTLY_DEAD or DELETE_IN_PROGRESS entries in a HOT chain, without trying
1739 * very hard to detect whether they're really incompatible with the chain tip.
1740 * This only really makes sense for heap AM, it might need to be generalized
1741 * for other AMs later.
1750 void *callback_state,
1767 * As table_index_build_scan(), except that instead of scanning the complete
1768 * table, only the given number of blocks are scanned. Scan to end-of-rel can
1769 * be signaled by passing InvalidBlockNumber as numblocks. Note that
1770 * restricting the range to scan cannot be done when requesting syncscan.
1772 * When "anyvisible" mode is requested, all tuples visible to any transaction
1773 * are indexed and counted as live, including those inserted or deleted by
1774 * transactions that are still in progress.
1786 void *callback_state,
1803 * table_index_validate_scan - second table scan for concurrent index build
1805 * See validate_index() for an explanation.
1822/* ----------------------------------------------------------------------------
1823 * Miscellaneous functionality
1824 * ----------------------------------------------------------------------------
1828 * Return the current size of `rel` in bytes. If `forkNumber` is
1829 * InvalidForkNumber, return the relation's overall size, otherwise the size
1830 * for the indicated fork.
1832 * Note that the overall size might not be the equivalent of the sum of sizes
1833 * for the individual forks for some AMs, e.g. because the AMs storage does
1834 * not neatly map onto the builtin types of forks.
1843 * table_relation_needs_toast_table - does this relation need a toast table?
1852 * Return the OID of the AM that should be used to implement the TOAST table
1853 * for this relation.
1862 * Fetch all or part of a TOAST value from a TOAST table.
1864 * If this AM is never used to implement a TOAST table, then this callback
1865 * is not needed. But, if toasted values are ever stored in a table of this
1866 * type, then you will need this callback.
1868 * toastrel is the relation in which the toasted value is stored.
1870 * valueid identifies which toast value is to be fetched. For the heap,
1871 * this corresponds to the values stored in the chunk_id column.
1873 * attrsize is the total size of the toast value to be fetched.
1875 * sliceoffset is the offset within the toast value of the first byte that
1876 * should be fetched.
1878 * slicelength is the number of bytes from the toast value that should be
1881 * result is caller-allocated space into which the fetched bytes should be
1891 sliceoffset, slicelength,
1896/* ----------------------------------------------------------------------------
1897 * Planner related functionality
1898 * ----------------------------------------------------------------------------
1902 * Estimate the current size of the relation, as an AM specific workhorse for
1903 * estimate_rel_size(). Look there for an explanation of the parameters.
1915/* ----------------------------------------------------------------------------
1916 * Executor related functionality
1917 * ----------------------------------------------------------------------------
1921 * Fetch / check / return tuples as part of a bitmap table scan. `scan` needs
1922 * to have been started via table_beginscan_bm(). Fetch the next tuple of a
1923 * bitmap table scan into `slot` and return true if a visible tuple was found,
1926 * `recheck` is set by the table AM to indicate whether or not the tuple in
1927 * `slot` should be rechecked. Tuples from lossy pages will always need to be
1928 * rechecked, but some non-lossy pages' tuples may also require recheck.
1930 * `lossy_pages` is incremented if the block's representation in the bitmap is
1931 * lossy; otherwise, `exact_pages` is incremented.
1941 * We don't expect direct calls to table_scan_bitmap_next_tuple with valid
1942 * CheckXidAlive for catalog or regular tables. See detailed comments in
1943 * xact.c where these variables are declared.
1946 elog(
ERROR,
"unexpected table_scan_bitmap_next_tuple call during logical decoding");
1956 * Prepare to fetch tuples from the next block in a sample scan. Returns false
1957 * if the sample scan is finished, true otherwise. `scan` needs to have been
1958 * started via table_beginscan_sampling().
1960 * This will call the TsmRoutine's NextSampleBlock() callback if necessary
1961 * (i.e. NextSampleBlock is not NULL), or perform a sequential scan over the
1962 * underlying relation.
1969 * We don't expect direct calls to table_scan_sample_next_block with valid
1970 * CheckXidAlive for catalog or regular tables. See detailed comments in
1971 * xact.c where these variables are declared.
1974 elog(
ERROR,
"unexpected table_scan_sample_next_block call during logical decoding");
1979 * Fetch the next sample tuple into `slot` and return true if a visible tuple
1980 * was found, false otherwise. table_scan_sample_next_block() needs to
1981 * previously have selected a block (i.e. returned true), and no previous
1982 * table_scan_sample_next_tuple() for the same block may have returned false.
1984 * This will call the TsmRoutine's NextSampleTuple() callback.
1992 * We don't expect direct calls to table_scan_sample_next_tuple with valid
1993 * CheckXidAlive for catalog or regular tables. See detailed comments in
1994 * xact.c where these variables are declared.
1997 elog(
ERROR,
"unexpected table_scan_sample_next_tuple call during logical decoding");
2003/* ----------------------------------------------------------------------------
2004 * Functions to make modifications a bit simpler.
2005 * ----------------------------------------------------------------------------
2016/* ----------------------------------------------------------------------------
2017 * Helper functions to implement parallel scans for block oriented AMs.
2018 * ----------------------------------------------------------------------------
2034/* ----------------------------------------------------------------------------
2035 * Helper functions to implement relation sizing for block oriented AMs.
2036 * ----------------------------------------------------------------------------
2045 Size overhead_bytes_per_tuple,
2046 Size usable_bytes_per_page);
2048/* ----------------------------------------------------------------------------
2049 * Functions in tableamapi.c
2050 * ----------------------------------------------------------------------------
2055/* ----------------------------------------------------------------------------
2056 * Functions in heapam_handler.c
2057 * ----------------------------------------------------------------------------
2062#endif /* TABLEAM_H */
#define InvalidBlockNumber
static Datum values[MAXATTR]
TransactionId MultiXactId
Assert(PointerIsAligned(start, uint64))
static PgChecksumMode mode
#define RelationGetRelid(relation)
struct TableScanDescData * TableScanDesc
const struct TableAmRoutine * rd_tableam
Size(* parallelscan_initialize)(Relation rel, ParallelTableScanDesc pscan)
void(* relation_copy_data)(Relation rel, const RelFileLocator *newrlocator)
void(* index_fetch_reset)(struct IndexFetchTableData *data)
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
bool(* scan_sample_next_tuple)(TableScanDesc scan, SampleScanState *scanstate, TupleTableSlot *slot)
bool(* scan_sample_next_block)(TableScanDesc scan, SampleScanState *scanstate)
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
void(* relation_copy_for_cluster)(Relation OldTable, Relation NewTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, TupleTableSlot *slot, bool *recheck, uint64 *lossy_pages, uint64 *exact_pages)
bool(* scan_getnextslot_tidrange)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
bool(* relation_needs_toast_table)(Relation rel)
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
void(* scan_end)(TableScanDesc scan)
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
TM_Result(* tuple_lock)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, uint8 flags, TM_FailureData *tmfd)
void(* relation_nontransactional_truncate)(Relation rel)
TM_Result(* tuple_update)(Relation rel, ItemPointer otid, TupleTableSlot *slot, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
void(* relation_fetch_toast_slice)(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
Oid(* relation_toast_am)(Relation rel)
bool(* scan_analyze_next_block)(TableScanDesc scan, ReadStream *stream)
Size(* parallelscan_estimate)(Relation rel)
void(* relation_set_new_filelocator)(Relation rel, const RelFileLocator *newrlocator, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
void(* scan_rescan)(TableScanDesc scan, ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
void(* scan_set_tidrange)(TableScanDesc scan, ItemPointer mintid, ItemPointer maxtid)
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
void(* finish_bulk_insert)(Relation rel, int options)
bool(* scan_analyze_next_tuple)(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
TransactionId(* index_delete_tuples)(Relation rel, TM_IndexDeleteOp *delstate)
void(* index_fetch_end)(struct IndexFetchTableData *data)
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, BulkInsertStateData *bistate, uint32 specToken)
bool(* index_fetch_tuple)(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
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)
void(* relation_vacuum)(Relation rel, const VacuumParams params, BufferAccessStrategy bstrategy)
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, BulkInsertStateData *bistate)
void(* index_validate_scan)(Relation table_rel, Relation index_rel, IndexInfo *index_info, Snapshot snapshot, ValidateIndexState *state)
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, BulkInsertStateData *bistate)
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
static void table_relation_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
PGDLLIMPORT char * default_table_access_method
static void table_rescan_tidrange(TableScanDesc sscan, ItemPointer mintid, ItemPointer maxtid)
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)
static void table_endscan(TableScanDesc scan)
static void table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, BulkInsertStateData *bistate)
void simple_table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot, Snapshot snapshot, TU_UpdateIndexes *update_indexes)
static bool table_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
bool table_index_fetch_tuple_check(Relation rel, ItemPointer tid, Snapshot snapshot, bool *all_dead)
PGDLLIMPORT bool synchronize_seqscans
Size table_block_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan)
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc pscan)
struct TM_IndexDelete TM_IndexDelete
static void table_index_validate_scan(Relation table_rel, Relation index_rel, IndexInfo *index_info, Snapshot snapshot, ValidateIndexState *state)
static void table_relation_copy_for_cluster(Relation OldTable, Relation NewTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
static uint64 table_relation_size(Relation rel, ForkNumber forkNumber)
static bool table_scan_sample_next_block(TableScanDesc scan, SampleScanState *scanstate)
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, TupleTableSlot *slot, bool *recheck, uint64 *lossy_pages, uint64 *exact_pages)
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)
void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot)
static bool table_tuple_tid_valid(TableScanDesc scan, ItemPointer tid)
static IndexFetchTableData * table_index_fetch_begin(Relation rel)
static void table_rescan_set_params(TableScanDesc scan, ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
static TableScanDesc table_beginscan_sampling(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
static void table_tuple_insert_speculative(Relation rel, TupleTableSlot *slot, CommandId cid, int options, BulkInsertStateData *bistate, uint32 specToken)
void table_block_parallelscan_startblock_init(Relation rel, ParallelBlockTableScanWorker pbscanwork, ParallelBlockTableScanDesc pbscan)
static bool table_scan_analyze_next_block(TableScanDesc scan, ReadStream *stream)
static bool table_relation_needs_toast_table(Relation rel)
struct TM_IndexStatus TM_IndexStatus
static void table_tuple_complete_speculative(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
static TableScanDesc table_beginscan_tidrange(Relation rel, Snapshot snapshot, ItemPointer mintid, ItemPointer maxtid)
static TM_Result table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode, TU_UpdateIndexes *update_indexes)
static void table_index_fetch_end(struct IndexFetchTableData *scan)
static TableScanDesc table_beginscan_analyze(Relation rel)
const TableAmRoutine * GetTableAmRoutine(Oid amhandler)
static TM_Result table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
static void table_rescan(TableScanDesc scan, ScanKeyData *key)
static bool table_index_fetch_tuple(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, BulkInsertStateData *bistate)
const TableAmRoutine * GetHeapamTableAmRoutine(void)
void simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot)
static void table_relation_vacuum(Relation rel, const VacuumParams params, BufferAccessStrategy bstrategy)
struct TM_FailureData TM_FailureData
static void table_finish_bulk_insert(Relation rel, int options)
void table_block_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
void(* IndexBuildCallback)(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
uint64 table_block_relation_size(Relation rel, ForkNumber forkNumber)
static void table_relation_set_new_filelocator(Relation rel, const RelFileLocator *newrlocator, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
static bool table_scan_getnextslot_tidrange(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
static Oid table_relation_toast_am(Relation rel)
static bool table_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate, TupleTableSlot *slot)
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
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)
static void table_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key)
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, bool allow_strat, bool allow_sync)
struct TM_IndexDeleteOp TM_IndexDeleteOp
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
Size table_block_parallelscan_estimate(Relation rel)
static void table_relation_estimate_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
struct TableAmRoutine TableAmRoutine
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key)
static bool table_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
static TransactionId table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate)
static void table_relation_nontransactional_truncate(Relation rel)
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
static bool table_tuple_fetch_row_version(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
BlockNumber table_block_parallelscan_nextpage(Relation rel, ParallelBlockTableScanWorker pbscanwork, ParallelBlockTableScanDesc pbscan)
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)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
#define TransactionIdIsValid(xid)
TransactionId CheckXidAlive