PostgreSQL Source Code  git master
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-2020, 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 "utils/guc.h"
23 #include "utils/rel.h"
24 #include "utils/snapshot.h"
25 
26 
27 #define DEFAULT_TABLE_ACCESS_METHOD "heap"
28 
29 /* GUCs */
30 extern char *default_table_access_method;
31 extern bool synchronize_seqscans;
32 
33 
34 struct BulkInsertStateData;
35 struct IndexInfo;
36 struct SampleScanState;
37 struct TBMIterateResult;
38 struct VacuumParams;
39 struct ValidateIndexState;
40 
41 /*
42  * Bitmask values for the flags argument to the scan_begin callback.
43  */
44 typedef enum ScanOptions
45 {
46  /* one of SO_TYPE_* may be specified */
47  SO_TYPE_SEQSCAN = 1 << 0,
50  SO_TYPE_TIDSCAN = 1 << 3,
51  SO_TYPE_ANALYZE = 1 << 4,
52 
53  /* several of SO_ALLOW_* may be specified */
54  /* allow or disallow use of access strategy */
55  SO_ALLOW_STRAT = 1 << 5,
56  /* report location to syncscan logic? */
57  SO_ALLOW_SYNC = 1 << 6,
58  /* verify visibility page-at-a-time? */
60 
61  /* unregister snapshot at scan end? */
63 } ScanOptions;
64 
65 /*
66  * Result codes for table_{update,delete,lock_tuple}, and for visibility
67  * routines inside table AMs.
68  */
69 typedef enum TM_Result
70 {
71  /*
72  * Signals that the action succeeded (i.e. update/delete performed, lock
73  * was acquired)
74  */
76 
77  /* The affected tuple wasn't visible to the relevant snapshot */
79 
80  /* The affected tuple was already modified by the calling backend */
82 
83  /*
84  * The affected tuple was updated by another transaction. This includes
85  * the case where tuple was moved to another partition.
86  */
88 
89  /* The affected tuple was deleted by another transaction */
91 
92  /*
93  * The affected tuple is currently being modified by another session. This
94  * will only be returned if table_(update/delete/lock_tuple) are
95  * instructed not to wait.
96  */
98 
99  /* lock couldn't be acquired, action skipped. Only used by lock_tuple */
101 } TM_Result;
102 
103 /*
104  * When table_tuple_update, table_tuple_delete, or table_tuple_lock fail
105  * because the target tuple is already outdated, they fill in this struct to
106  * provide information to the caller about what happened.
107  *
108  * ctid is the target's ctid link: it is the same as the target's TID if the
109  * target was deleted, or the location of the replacement tuple if the target
110  * was updated.
111  *
112  * xmax is the outdating transaction's XID. If the caller wants to visit the
113  * replacement tuple, it must check that this matches before believing the
114  * replacement is really a match.
115  *
116  * cmax is the outdating command's CID, but only when the failure code is
117  * TM_SelfModified (i.e., something in the current transaction outdated the
118  * tuple); otherwise cmax is zero. (We make this restriction because
119  * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
120  * transactions.)
121  */
122 typedef struct TM_FailureData
123 {
127  bool traversed;
129 
130 /* "options" flag bits for table_tuple_insert */
131 /* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
132 #define TABLE_INSERT_SKIP_FSM 0x0002
133 #define TABLE_INSERT_FROZEN 0x0004
134 #define TABLE_INSERT_NO_LOGICAL 0x0008
135 
136 /* flag bits for table_tuple_lock */
137 /* Follow tuples whose update is in progress if lock modes don't conflict */
138 #define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS (1 << 0)
139 /* Follow update chain and lock latest version of tuple */
140 #define TUPLE_LOCK_FLAG_FIND_LAST_VERSION (1 << 1)
141 
142 
143 /* Typedef for callback function for table_index_build_scan */
145  ItemPointer tid,
146  Datum *values,
147  bool *isnull,
148  bool tupleIsAlive,
149  void *state);
150 
151 /*
152  * API struct for a table AM. Note this must be allocated in a
153  * server-lifetime manner, typically as a static const struct, which then gets
154  * returned by FormData_pg_am.amhandler.
155  *
156  * In most cases it's not appropriate to call the callbacks directly, use the
157  * table_* wrapper functions instead.
158  *
159  * GetTableAmRoutine() asserts that required callbacks are filled in, remember
160  * to update when adding a callback.
161  */
162 typedef struct TableAmRoutine
163 {
164  /* this must be set to T_TableAmRoutine */
166 
167 
168  /* ------------------------------------------------------------------------
169  * Slot related callbacks.
170  * ------------------------------------------------------------------------
171  */
172 
173  /*
174  * Return slot implementation suitable for storing a tuple of this AM.
175  */
176  const TupleTableSlotOps *(*slot_callbacks) (Relation rel);
177 
178 
179  /* ------------------------------------------------------------------------
180  * Table scan callbacks.
181  * ------------------------------------------------------------------------
182  */
183 
184  /*
185  * Start a scan of `rel`. The callback has to return a TableScanDesc,
186  * which will typically be embedded in a larger, AM specific, struct.
187  *
188  * If nkeys != 0, the results need to be filtered by those scan keys.
189  *
190  * pscan, if not NULL, will have already been initialized with
191  * parallelscan_initialize(), and has to be for the same relation. Will
192  * only be set coming from table_beginscan_parallel().
193  *
194  * `flags` is a bitmask indicating the type of scan (ScanOptions's
195  * SO_TYPE_*, currently only one may be specified), options controlling
196  * the scan's behaviour (ScanOptions's SO_ALLOW_*, several may be
197  * specified, an AM may ignore unsupported ones) and whether the snapshot
198  * needs to be deallocated at scan_end (ScanOptions's SO_TEMP_SNAPSHOT).
199  */
200  TableScanDesc (*scan_begin) (Relation rel,
201  Snapshot snapshot,
202  int nkeys, struct ScanKeyData *key,
203  ParallelTableScanDesc pscan,
204  uint32 flags);
205 
206  /*
207  * Release resources and deallocate scan. If TableScanDesc.temp_snap,
208  * TableScanDesc.rs_snapshot needs to be unregistered.
209  */
210  void (*scan_end) (TableScanDesc scan);
211 
212  /*
213  * Restart relation scan. If set_params is set to true, allow_{strat,
214  * sync, pagemode} (see scan_begin) changes should be taken into account.
215  */
216  void (*scan_rescan) (TableScanDesc scan, struct ScanKeyData *key,
217  bool set_params, bool allow_strat,
218  bool allow_sync, bool allow_pagemode);
219 
220  /*
221  * Return next tuple from `scan`, store in slot.
222  */
223  bool (*scan_getnextslot) (TableScanDesc scan,
224  ScanDirection direction,
225  TupleTableSlot *slot);
226 
227 
228  /* ------------------------------------------------------------------------
229  * Parallel table scan related functions.
230  * ------------------------------------------------------------------------
231  */
232 
233  /*
234  * Estimate the size of shared memory needed for a parallel scan of this
235  * relation. The snapshot does not need to be accounted for.
236  */
237  Size (*parallelscan_estimate) (Relation rel);
238 
239  /*
240  * Initialize ParallelTableScanDesc for a parallel scan of this relation.
241  * `pscan` will be sized according to parallelscan_estimate() for the same
242  * relation.
243  */
244  Size (*parallelscan_initialize) (Relation rel,
245  ParallelTableScanDesc pscan);
246 
247  /*
248  * Reinitialize `pscan` for a new scan. `rel` will be the same relation as
249  * when `pscan` was initialized by parallelscan_initialize.
250  */
251  void (*parallelscan_reinitialize) (Relation rel,
252  ParallelTableScanDesc pscan);
253 
254 
255  /* ------------------------------------------------------------------------
256  * Index Scan Callbacks
257  * ------------------------------------------------------------------------
258  */
259 
260  /*
261  * Prepare to fetch tuples from the relation, as needed when fetching
262  * tuples for an index scan. The callback has to return an
263  * IndexFetchTableData, which the AM will typically embed in a larger
264  * structure with additional information.
265  *
266  * Tuples for an index scan can then be fetched via index_fetch_tuple.
267  */
268  struct IndexFetchTableData *(*index_fetch_begin) (Relation rel);
269 
270  /*
271  * Reset index fetch. Typically this will release cross index fetch
272  * resources held in IndexFetchTableData.
273  */
274  void (*index_fetch_reset) (struct IndexFetchTableData *data);
275 
276  /*
277  * Release resources and deallocate index fetch.
278  */
279  void (*index_fetch_end) (struct IndexFetchTableData *data);
280 
281  /*
282  * Fetch tuple at `tid` into `slot`, after doing a visibility test
283  * according to `snapshot`. If a tuple was found and passed the visibility
284  * test, return true, false otherwise.
285  *
286  * Note that AMs that do not necessarily update indexes when indexed
287  * columns do not change, need to return the current/correct version of
288  * the tuple that is visible to the snapshot, even if the tid points to an
289  * older version of the tuple.
290  *
291  * *call_again is false on the first call to index_fetch_tuple for a tid.
292  * If there potentially is another tuple matching the tid, *call_again
293  * needs to be set to true by index_fetch_tuple, signaling to the caller
294  * that index_fetch_tuple should be called again for the same tid.
295  *
296  * *all_dead, if all_dead is not NULL, should be set to true by
297  * index_fetch_tuple iff it is guaranteed that no backend needs to see
298  * that tuple. Index AMs can use that to avoid returning that tid in
299  * future searches.
300  */
301  bool (*index_fetch_tuple) (struct IndexFetchTableData *scan,
302  ItemPointer tid,
303  Snapshot snapshot,
304  TupleTableSlot *slot,
305  bool *call_again, bool *all_dead);
306 
307 
308  /* ------------------------------------------------------------------------
309  * Callbacks for non-modifying operations on individual tuples
310  * ------------------------------------------------------------------------
311  */
312 
313  /*
314  * Fetch tuple at `tid` into `slot`, after doing a visibility test
315  * according to `snapshot`. If a tuple was found and passed the visibility
316  * test, returns true, false otherwise.
317  */
318  bool (*tuple_fetch_row_version) (Relation rel,
319  ItemPointer tid,
320  Snapshot snapshot,
321  TupleTableSlot *slot);
322 
323  /*
324  * Is tid valid for a scan of this relation.
325  */
326  bool (*tuple_tid_valid) (TableScanDesc scan,
327  ItemPointer tid);
328 
329  /*
330  * Return the latest version of the tuple at `tid`, by updating `tid` to
331  * point at the newest version.
332  */
333  void (*tuple_get_latest_tid) (TableScanDesc scan,
334  ItemPointer tid);
335 
336  /*
337  * Does the tuple in `slot` satisfy `snapshot`? The slot needs to be of
338  * the appropriate type for the AM.
339  */
340  bool (*tuple_satisfies_snapshot) (Relation rel,
341  TupleTableSlot *slot,
342  Snapshot snapshot);
343 
344  /* see table_compute_xid_horizon_for_tuples() */
345  TransactionId (*compute_xid_horizon_for_tuples) (Relation rel,
346  ItemPointerData *items,
347  int nitems);
348 
349 
350  /* ------------------------------------------------------------------------
351  * Manipulations of physical tuples.
352  * ------------------------------------------------------------------------
353  */
354 
355  /* see table_tuple_insert() for reference about parameters */
356  void (*tuple_insert) (Relation rel, TupleTableSlot *slot,
357  CommandId cid, int options,
358  struct BulkInsertStateData *bistate);
359 
360  /* see table_tuple_insert_speculative() for reference about parameters */
361  void (*tuple_insert_speculative) (Relation rel,
362  TupleTableSlot *slot,
363  CommandId cid,
364  int options,
365  struct BulkInsertStateData *bistate,
366  uint32 specToken);
367 
368  /* see table_tuple_complete_speculative() for reference about parameters */
369  void (*tuple_complete_speculative) (Relation rel,
370  TupleTableSlot *slot,
371  uint32 specToken,
372  bool succeeded);
373 
374  /* see table_multi_insert() for reference about parameters */
375  void (*multi_insert) (Relation rel, TupleTableSlot **slots, int nslots,
376  CommandId cid, int options, struct BulkInsertStateData *bistate);
377 
378  /* see table_tuple_delete() for reference about parameters */
379  TM_Result (*tuple_delete) (Relation rel,
380  ItemPointer tid,
381  CommandId cid,
382  Snapshot snapshot,
383  Snapshot crosscheck,
384  bool wait,
385  TM_FailureData *tmfd,
386  bool changingPart);
387 
388  /* see table_tuple_update() for reference about parameters */
389  TM_Result (*tuple_update) (Relation rel,
390  ItemPointer otid,
391  TupleTableSlot *slot,
392  CommandId cid,
393  Snapshot snapshot,
394  Snapshot crosscheck,
395  bool wait,
396  TM_FailureData *tmfd,
397  LockTupleMode *lockmode,
398  bool *update_indexes);
399 
400  /* see table_tuple_lock() for reference about parameters */
401  TM_Result (*tuple_lock) (Relation rel,
402  ItemPointer tid,
403  Snapshot snapshot,
404  TupleTableSlot *slot,
405  CommandId cid,
407  LockWaitPolicy wait_policy,
408  uint8 flags,
409  TM_FailureData *tmfd);
410 
411  /*
412  * Perform operations necessary to complete insertions made via
413  * tuple_insert and multi_insert with a BulkInsertState specified. In-tree
414  * access methods ceased to use this.
415  *
416  * Typically callers of tuple_insert and multi_insert will just pass all
417  * the flags that apply to them, and each AM has to decide which of them
418  * make sense for it, and then only take actions in finish_bulk_insert for
419  * those flags, and ignore others.
420  *
421  * Optional callback.
422  */
423  void (*finish_bulk_insert) (Relation rel, int options);
424 
425 
426  /* ------------------------------------------------------------------------
427  * DDL related functionality.
428  * ------------------------------------------------------------------------
429  */
430 
431  /*
432  * This callback needs to create a new relation filenode for `rel`, with
433  * appropriate durability behaviour for `persistence`.
434  *
435  * Note that only the subset of the relcache filled by
436  * RelationBuildLocalRelation() can be relied upon and that the relation's
437  * catalog entries will either not yet exist (new relation), or will still
438  * reference the old relfilenode.
439  *
440  * As output *freezeXid, *minmulti must be set to the values appropriate
441  * for pg_class.{relfrozenxid, relminmxid}. For AMs that don't need those
442  * fields to be filled they can be set to InvalidTransactionId and
443  * InvalidMultiXactId, respectively.
444  *
445  * See also table_relation_set_new_filenode().
446  */
447  void (*relation_set_new_filenode) (Relation rel,
448  const RelFileNode *newrnode,
449  char persistence,
450  TransactionId *freezeXid,
451  MultiXactId *minmulti);
452 
453  /*
454  * This callback needs to remove all contents from `rel`'s current
455  * relfilenode. No provisions for transactional behaviour need to be made.
456  * Often this can be implemented by truncating the underlying storage to
457  * its minimal size.
458  *
459  * See also table_relation_nontransactional_truncate().
460  */
461  void (*relation_nontransactional_truncate) (Relation rel);
462 
463  /*
464  * See table_relation_copy_data().
465  *
466  * This can typically be implemented by directly copying the underlying
467  * storage, unless it contains references to the tablespace internally.
468  */
469  void (*relation_copy_data) (Relation rel,
470  const RelFileNode *newrnode);
471 
472  /* See table_relation_copy_for_cluster() */
473  void (*relation_copy_for_cluster) (Relation NewTable,
474  Relation OldTable,
475  Relation OldIndex,
476  bool use_sort,
478  TransactionId *xid_cutoff,
479  MultiXactId *multi_cutoff,
480  double *num_tuples,
481  double *tups_vacuumed,
482  double *tups_recently_dead);
483 
484  /*
485  * React to VACUUM command on the relation. The VACUUM can be triggered by
486  * a user or by autovacuum. The specific actions performed by the AM will
487  * depend heavily on the individual AM.
488  *
489  * On entry a transaction is already established, and the relation is
490  * locked with a ShareUpdateExclusive lock.
491  *
492  * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through
493  * this routine, even if (for ANALYZE) it is part of the same VACUUM
494  * command.
495  *
496  * There probably, in the future, needs to be a separate callback to
497  * integrate with autovacuum's scheduling.
498  */
499  void (*relation_vacuum) (Relation onerel,
500  struct VacuumParams *params,
501  BufferAccessStrategy bstrategy);
502 
503  /*
504  * Prepare to analyze block `blockno` of `scan`. The scan has been started
505  * with table_beginscan_analyze(). See also
506  * table_scan_analyze_next_block().
507  *
508  * The callback may acquire resources like locks that are held until
509  * table_scan_analyze_next_tuple() returns false. It e.g. can make sense
510  * to hold a lock until all tuples on a block have been analyzed by
511  * scan_analyze_next_tuple.
512  *
513  * The callback can return false if the block is not suitable for
514  * sampling, e.g. because it's a metapage that could never contain tuples.
515  *
516  * XXX: This obviously is primarily suited for block-based AMs. It's not
517  * clear what a good interface for non block based AMs would be, so there
518  * isn't one yet.
519  */
520  bool (*scan_analyze_next_block) (TableScanDesc scan,
521  BlockNumber blockno,
522  BufferAccessStrategy bstrategy);
523 
524  /*
525  * See table_scan_analyze_next_tuple().
526  *
527  * Not every AM might have a meaningful concept of dead rows, in which
528  * case it's OK to not increment *deadrows - but note that that may
529  * influence autovacuum scheduling (see comment for relation_vacuum
530  * callback).
531  */
532  bool (*scan_analyze_next_tuple) (TableScanDesc scan,
534  double *liverows,
535  double *deadrows,
536  TupleTableSlot *slot);
537 
538  /* see table_index_build_range_scan for reference about parameters */
539  double (*index_build_range_scan) (Relation table_rel,
540  Relation index_rel,
541  struct IndexInfo *index_info,
542  bool allow_sync,
543  bool anyvisible,
544  bool progress,
545  BlockNumber start_blockno,
546  BlockNumber numblocks,
548  void *callback_state,
549  TableScanDesc scan);
550 
551  /* see table_index_validate_scan for reference about parameters */
552  void (*index_validate_scan) (Relation table_rel,
553  Relation index_rel,
554  struct IndexInfo *index_info,
555  Snapshot snapshot,
556  struct ValidateIndexState *state);
557 
558 
559  /* ------------------------------------------------------------------------
560  * Miscellaneous functions.
561  * ------------------------------------------------------------------------
562  */
563 
564  /*
565  * See table_relation_size().
566  *
567  * Note that currently a few callers use the MAIN_FORKNUM size to figure
568  * out the range of potentially interesting blocks (brin, analyze). It's
569  * probable that we'll need to revise the interface for those at some
570  * point.
571  */
572  uint64 (*relation_size) (Relation rel, ForkNumber forkNumber);
573 
574 
575  /*
576  * This callback should return true if the relation requires a TOAST table
577  * and false if it does not. It may wish to examine the relation's tuple
578  * descriptor before making a decision, but if it uses some other method
579  * of storing large values (or if it does not support them) it can simply
580  * return false.
581  */
582  bool (*relation_needs_toast_table) (Relation rel);
583 
584  /*
585  * This callback should return the OID of the table AM that implements
586  * TOAST tables for this AM. If the relation_needs_toast_table callback
587  * always returns false, this callback is not required.
588  */
589  Oid (*relation_toast_am) (Relation rel);
590 
591  /*
592  * This callback is invoked when detoasting a value stored in a toast
593  * table implemented by this AM. See table_relation_fetch_toast_slice()
594  * for more details.
595  */
596  void (*relation_fetch_toast_slice) (Relation toastrel, Oid valueid,
597  int32 attrsize,
598  int32 sliceoffset,
599  int32 slicelength,
600  struct varlena *result);
601 
602 
603  /* ------------------------------------------------------------------------
604  * Planner related functions.
605  * ------------------------------------------------------------------------
606  */
607 
608  /*
609  * See table_relation_estimate_size().
610  *
611  * While block oriented, it shouldn't be too hard for an AM that doesn't
612  * internally use blocks to convert into a usable representation.
613  *
614  * This differs from the relation_size callback by returning size
615  * estimates (both relation size and tuple count) for planning purposes,
616  * rather than returning a currently correct estimate.
617  */
618  void (*relation_estimate_size) (Relation rel, int32 *attr_widths,
619  BlockNumber *pages, double *tuples,
620  double *allvisfrac);
621 
622 
623  /* ------------------------------------------------------------------------
624  * Executor related functions.
625  * ------------------------------------------------------------------------
626  */
627 
628  /*
629  * Prepare to fetch / check / return tuples from `tbmres->blockno` as part
630  * of a bitmap table scan. `scan` was started via table_beginscan_bm().
631  * Return false if there are no tuples to be found on the page, true
632  * otherwise.
633  *
634  * This will typically read and pin the target block, and do the necessary
635  * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
636  * make sense to perform tuple visibility checks at this time). For some
637  * AMs it will make more sense to do all the work referencing `tbmres`
638  * contents here, for others it might be better to defer more work to
639  * scan_bitmap_next_tuple.
640  *
641  * If `tbmres->blockno` is -1, this is a lossy scan and all visible tuples
642  * on the page have to be returned, otherwise the tuples at offsets in
643  * `tbmres->offsets` need to be returned.
644  *
645  * XXX: Currently this may only be implemented if the AM uses md.c as its
646  * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
647  * blockids directly to the underlying storage. nodeBitmapHeapscan.c
648  * performs prefetching directly using that interface. This probably
649  * needs to be rectified at a later point.
650  *
651  * XXX: Currently this may only be implemented if the AM uses the
652  * visibilitymap, as nodeBitmapHeapscan.c unconditionally accesses it to
653  * perform prefetching. This probably needs to be rectified at a later
654  * point.
655  *
656  * Optional callback, but either both scan_bitmap_next_block and
657  * scan_bitmap_next_tuple need to exist, or neither.
658  */
659  bool (*scan_bitmap_next_block) (TableScanDesc scan,
660  struct TBMIterateResult *tbmres);
661 
662  /*
663  * Fetch the next tuple of a bitmap table scan into `slot` and return true
664  * if a visible tuple was found, false otherwise.
665  *
666  * For some AMs it will make more sense to do all the work referencing
667  * `tbmres` contents in scan_bitmap_next_block, for others it might be
668  * better to defer more work to this callback.
669  *
670  * Optional callback, but either both scan_bitmap_next_block and
671  * scan_bitmap_next_tuple need to exist, or neither.
672  */
673  bool (*scan_bitmap_next_tuple) (TableScanDesc scan,
674  struct TBMIterateResult *tbmres,
675  TupleTableSlot *slot);
676 
677  /*
678  * Prepare to fetch tuples from the next block in a sample scan. Return
679  * false if the sample scan is finished, true otherwise. `scan` was
680  * started via table_beginscan_sampling().
681  *
682  * Typically this will first determine the target block by calling the
683  * TsmRoutine's NextSampleBlock() callback if not NULL, or alternatively
684  * perform a sequential scan over all blocks. The determined block is
685  * then typically read and pinned.
686  *
687  * As the TsmRoutine interface is block based, a block needs to be passed
688  * to NextSampleBlock(). If that's not appropriate for an AM, it
689  * internally needs to perform mapping between the internal and a block
690  * based representation.
691  *
692  * Note that it's not acceptable to hold deadlock prone resources such as
693  * lwlocks until scan_sample_next_tuple() has exhausted the tuples on the
694  * block - the tuple is likely to be returned to an upper query node, and
695  * the next call could be off a long while. Holding buffer pins and such
696  * is obviously OK.
697  *
698  * Currently it is required to implement this interface, as there's no
699  * alternative way (contrary e.g. to bitmap scans) to implement sample
700  * scans. If infeasible to implement, the AM may raise an error.
701  */
702  bool (*scan_sample_next_block) (TableScanDesc scan,
703  struct SampleScanState *scanstate);
704 
705  /*
706  * This callback, only called after scan_sample_next_block has returned
707  * true, should determine the next tuple to be returned from the selected
708  * block using the TsmRoutine's NextSampleTuple() callback.
709  *
710  * The callback needs to perform visibility checks, and only return
711  * visible tuples. That obviously can mean calling NextSampleTuple()
712  * multiple times.
713  *
714  * The TsmRoutine interface assumes that there's a maximum offset on a
715  * given page, so if that doesn't apply to an AM, it needs to emulate that
716  * assumption somehow.
717  */
718  bool (*scan_sample_next_tuple) (TableScanDesc scan,
719  struct SampleScanState *scanstate,
720  TupleTableSlot *slot);
721 
723 
724 
725 /* ----------------------------------------------------------------------------
726  * Slot functions.
727  * ----------------------------------------------------------------------------
728  */
729 
730 /*
731  * Returns slot callbacks suitable for holding tuples of the appropriate type
732  * for the relation. Works for tables, views, foreign tables and partitioned
733  * tables.
734  */
736 
737 /*
738  * Returns slot using the callbacks returned by table_slot_callbacks(), and
739  * registers it on *reglist.
740  */
741 extern TupleTableSlot *table_slot_create(Relation rel, List **reglist);
742 
743 
744 /* ----------------------------------------------------------------------------
745  * Table scan functions.
746  * ----------------------------------------------------------------------------
747  */
748 
749 /*
750  * Start a scan of `rel`. Returned tuples pass a visibility test of
751  * `snapshot`, and if nkeys != 0, the results are filtered by those scan keys.
752  */
753 static inline TableScanDesc
755  int nkeys, struct ScanKeyData *key)
756 {
757  uint32 flags = SO_TYPE_SEQSCAN |
759 
760  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
761 }
762 
763 /*
764  * Like table_beginscan(), but for scanning catalog. It'll automatically use a
765  * snapshot appropriate for scanning catalog relations.
766  */
767 extern TableScanDesc table_beginscan_catalog(Relation rel, int nkeys,
768  struct ScanKeyData *key);
769 
770 /*
771  * Like table_beginscan(), but table_beginscan_strat() offers an extended API
772  * that lets the caller control whether a nondefault buffer access strategy
773  * can be used, and whether syncscan can be chosen (possibly resulting in the
774  * scan not starting from block zero). Both of these default to true with
775  * plain table_beginscan.
776  */
777 static inline TableScanDesc
779  int nkeys, struct ScanKeyData *key,
780  bool allow_strat, bool allow_sync)
781 {
783 
784  if (allow_strat)
785  flags |= SO_ALLOW_STRAT;
786  if (allow_sync)
787  flags |= SO_ALLOW_SYNC;
788 
789  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
790 }
791 
792 /*
793  * table_beginscan_bm is an alternative entry point for setting up a
794  * TableScanDesc for a bitmap heap scan. Although that scan technology is
795  * really quite unlike a standard seqscan, there is just enough commonality to
796  * make it worth using the same data structure.
797  */
798 static inline TableScanDesc
800  int nkeys, struct ScanKeyData *key)
801 {
803 
804  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
805 }
806 
807 /*
808  * table_beginscan_sampling is an alternative entry point for setting up a
809  * TableScanDesc for a TABLESAMPLE scan. As with bitmap scans, it's worth
810  * using the same data structure although the behavior is rather different.
811  * In addition to the options offered by table_beginscan_strat, this call
812  * also allows control of whether page-mode visibility checking is used.
813  */
814 static inline TableScanDesc
816  int nkeys, struct ScanKeyData *key,
817  bool allow_strat, bool allow_sync,
818  bool allow_pagemode)
819 {
820  uint32 flags = SO_TYPE_SAMPLESCAN;
821 
822  if (allow_strat)
823  flags |= SO_ALLOW_STRAT;
824  if (allow_sync)
825  flags |= SO_ALLOW_SYNC;
826  if (allow_pagemode)
827  flags |= SO_ALLOW_PAGEMODE;
828 
829  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
830 }
831 
832 /*
833  * table_beginscan_tid is an alternative entry point for setting up a
834  * TableScanDesc for a Tid scan. As with bitmap scans, it's worth using
835  * the same data structure although the behavior is rather different.
836  */
837 static inline TableScanDesc
839 {
840  uint32 flags = SO_TYPE_TIDSCAN;
841 
842  return rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
843 }
844 
845 /*
846  * table_beginscan_analyze is an alternative entry point for setting up a
847  * TableScanDesc for an ANALYZE scan. As with bitmap scans, it's worth using
848  * the same data structure although the behavior is rather different.
849  */
850 static inline TableScanDesc
852 {
853  uint32 flags = SO_TYPE_ANALYZE;
854 
855  return rel->rd_tableam->scan_begin(rel, NULL, 0, NULL, NULL, flags);
856 }
857 
858 /*
859  * End relation scan.
860  */
861 static inline void
863 {
864  scan->rs_rd->rd_tableam->scan_end(scan);
865 }
866 
867 /*
868  * Restart a relation scan.
869  */
870 static inline void
872  struct ScanKeyData *key)
873 {
874  scan->rs_rd->rd_tableam->scan_rescan(scan, key, false, false, false, false);
875 }
876 
877 /*
878  * Restart a relation scan after changing params.
879  *
880  * This call allows changing the buffer strategy, syncscan, and pagemode
881  * options before starting a fresh scan. Note that although the actual use of
882  * syncscan might change (effectively, enabling or disabling reporting), the
883  * previously selected startblock will be kept.
884  */
885 static inline void
887  bool allow_strat, bool allow_sync, bool allow_pagemode)
888 {
889  scan->rs_rd->rd_tableam->scan_rescan(scan, key, true,
890  allow_strat, allow_sync,
891  allow_pagemode);
892 }
893 
894 /*
895  * Update snapshot used by the scan.
896  */
897 extern void table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot);
898 
899 /*
900  * Return next tuple from `scan`, store in slot.
901  */
902 static inline bool
904 {
905  slot->tts_tableOid = RelationGetRelid(sscan->rs_rd);
906  return sscan->rs_rd->rd_tableam->scan_getnextslot(sscan, direction, slot);
907 }
908 
909 
910 /* ----------------------------------------------------------------------------
911  * Parallel table scan related functions.
912  * ----------------------------------------------------------------------------
913  */
914 
915 /*
916  * Estimate the size of shared memory needed for a parallel scan of this
917  * relation.
918  */
919 extern Size table_parallelscan_estimate(Relation rel, Snapshot snapshot);
920 
921 /*
922  * Initialize ParallelTableScanDesc for a parallel scan of this
923  * relation. `pscan` needs to be sized according to parallelscan_estimate()
924  * for the same relation. Call this just once in the leader process; then,
925  * individual workers attach via table_beginscan_parallel.
926  */
928  ParallelTableScanDesc pscan,
929  Snapshot snapshot);
930 
931 /*
932  * Begin a parallel scan. `pscan` needs to have been initialized with
933  * table_parallelscan_initialize(), for the same relation. The initialization
934  * does not need to have happened in this backend.
935  *
936  * Caller must hold a suitable lock on the relation.
937  */
939  ParallelTableScanDesc pscan);
940 
941 /*
942  * Restart a parallel scan. Call this in the leader process. Caller is
943  * responsible for making sure that all workers have finished the scan
944  * beforehand.
945  */
946 static inline void
948 {
949  rel->rd_tableam->parallelscan_reinitialize(rel, pscan);
950 }
951 
952 
953 /* ----------------------------------------------------------------------------
954  * Index scan related functions.
955  * ----------------------------------------------------------------------------
956  */
957 
958 /*
959  * Prepare to fetch tuples from the relation, as needed when fetching tuples
960  * for an index scan.
961  *
962  * Tuples for an index scan can then be fetched via table_index_fetch_tuple().
963  */
964 static inline IndexFetchTableData *
966 {
967  return rel->rd_tableam->index_fetch_begin(rel);
968 }
969 
970 /*
971  * Reset index fetch. Typically this will release cross index fetch resources
972  * held in IndexFetchTableData.
973  */
974 static inline void
976 {
977  scan->rel->rd_tableam->index_fetch_reset(scan);
978 }
979 
980 /*
981  * Release resources and deallocate index fetch.
982  */
983 static inline void
985 {
986  scan->rel->rd_tableam->index_fetch_end(scan);
987 }
988 
989 /*
990  * Fetches, as part of an index scan, tuple at `tid` into `slot`, after doing
991  * a visibility test according to `snapshot`. If a tuple was found and passed
992  * the visibility test, returns true, false otherwise. Note that *tid may be
993  * modified when we return true (see later remarks on multiple row versions
994  * reachable via a single index entry).
995  *
996  * *call_again needs to be false on the first call to table_index_fetch_tuple() for
997  * a tid. If there potentially is another tuple matching the tid, *call_again
998  * will be set to true, signaling that table_index_fetch_tuple() should be called
999  * again for the same tid.
1000  *
1001  * *all_dead, if all_dead is not NULL, will be set to true by
1002  * table_index_fetch_tuple() iff it is guaranteed that no backend needs to see
1003  * that tuple. Index AMs can use that to avoid returning that tid in future
1004  * searches.
1005  *
1006  * The difference between this function and table_fetch_row_version is that
1007  * this function returns the currently visible version of a row if the AM
1008  * supports storing multiple row versions reachable via a single index entry
1009  * (like heap's HOT). Whereas table_fetch_row_version only evaluates the
1010  * tuple exactly at `tid`. Outside of index entry ->table tuple lookups,
1011  * table_tuple_fetch_row_version is what's usually needed.
1012  */
1013 static inline bool
1015  ItemPointer tid,
1016  Snapshot snapshot,
1017  TupleTableSlot *slot,
1018  bool *call_again, bool *all_dead)
1019 {
1020 
1021  return scan->rel->rd_tableam->index_fetch_tuple(scan, tid, snapshot,
1022  slot, call_again,
1023  all_dead);
1024 }
1025 
1026 /*
1027  * This is a convenience wrapper around table_index_fetch_tuple() which
1028  * returns whether there are table tuple items corresponding to an index
1029  * entry. This likely is only useful to verify if there's a conflict in a
1030  * unique index.
1031  */
1032 extern bool table_index_fetch_tuple_check(Relation rel,
1033  ItemPointer tid,
1034  Snapshot snapshot,
1035  bool *all_dead);
1036 
1037 
1038 /* ------------------------------------------------------------------------
1039  * Functions for non-modifying operations on individual tuples
1040  * ------------------------------------------------------------------------
1041  */
1042 
1043 
1044 /*
1045  * Fetch tuple at `tid` into `slot`, after doing a visibility test according to
1046  * `snapshot`. If a tuple was found and passed the visibility test, returns
1047  * true, false otherwise.
1048  *
1049  * See table_index_fetch_tuple's comment about what the difference between
1050  * these functions is. It is correct to use this function outside of index
1051  * entry->table tuple lookups.
1052  */
1053 static inline bool
1055  ItemPointer tid,
1056  Snapshot snapshot,
1057  TupleTableSlot *slot)
1058 {
1059  return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot);
1060 }
1061 
1062 /*
1063  * Verify that `tid` is a potentially valid tuple identifier. That doesn't
1064  * mean that the pointed to row needs to exist or be visible, but that
1065  * attempting to fetch the row (e.g. with table_get_latest_tid() or
1066  * table_fetch_row_version()) should not error out if called with that tid.
1067  *
1068  * `scan` needs to have been started via table_beginscan().
1069  */
1070 static inline bool
1072 {
1073  return scan->rs_rd->rd_tableam->tuple_tid_valid(scan, tid);
1074 }
1075 
1076 /*
1077  * Return the latest version of the tuple at `tid`, by updating `tid` to
1078  * point at the newest version.
1079  */
1081 
1082 /*
1083  * Return true iff tuple in slot satisfies the snapshot.
1084  *
1085  * This assumes the slot's tuple is valid, and of the appropriate type for the
1086  * AM.
1087  *
1088  * Some AMs might modify the data underlying the tuple as a side-effect. If so
1089  * they ought to mark the relevant buffer dirty.
1090  */
1091 static inline bool
1093  Snapshot snapshot)
1094 {
1095  return rel->rd_tableam->tuple_satisfies_snapshot(rel, slot, snapshot);
1096 }
1097 
1098 /*
1099  * Compute the newest xid among the tuples pointed to by items. This is used
1100  * to compute what snapshots to conflict with when replaying WAL records for
1101  * page-level index vacuums.
1102  */
1103 static inline TransactionId
1105  ItemPointerData *items,
1106  int nitems)
1107 {
1108  return rel->rd_tableam->compute_xid_horizon_for_tuples(rel, items, nitems);
1109 }
1110 
1111 
1112 /* ----------------------------------------------------------------------------
1113  * Functions for manipulations of physical tuples.
1114  * ----------------------------------------------------------------------------
1115  */
1116 
1117 /*
1118  * Insert a tuple from a slot into table AM routine.
1119  *
1120  * The options bitmask allows the caller to specify options that may change the
1121  * behaviour of the AM. The AM will ignore options that it does not support.
1122  *
1123  * If the TABLE_INSERT_SKIP_FSM option is specified, AMs are free to not reuse
1124  * free space in the relation. This can save some cycles when we know the
1125  * relation is new and doesn't contain useful amounts of free space.
1126  * TABLE_INSERT_SKIP_FSM is commonly passed directly to
1127  * RelationGetBufferForTuple. See that method for more information.
1128  *
1129  * TABLE_INSERT_FROZEN should only be specified for inserts into
1130  * relfilenodes created during the current subtransaction and when
1131  * there are no prior snapshots or pre-existing portals open.
1132  * This causes rows to be frozen, which is an MVCC violation and
1133  * requires explicit options chosen by user.
1134  *
1135  * TABLE_INSERT_NO_LOGICAL force-disables the emitting of logical decoding
1136  * information for the tuple. This should solely be used during table rewrites
1137  * where RelationIsLogicallyLogged(relation) is not yet accurate for the new
1138  * relation.
1139  *
1140  * Note that most of these options will be applied when inserting into the
1141  * heap's TOAST table, too, if the tuple requires any out-of-line data.
1142  *
1143  * The BulkInsertState object (if any; bistate can be NULL for default
1144  * behavior) is also just passed through to RelationGetBufferForTuple. If
1145  * `bistate` is provided, table_finish_bulk_insert() needs to be called.
1146  *
1147  * On return the slot's tts_tid and tts_tableOid are updated to reflect the
1148  * insertion. But note that any toasting of fields within the slot is NOT
1149  * reflected in the slots contents.
1150  */
1151 static inline void
1153  int options, struct BulkInsertStateData *bistate)
1154 {
1155  rel->rd_tableam->tuple_insert(rel, slot, cid, options,
1156  bistate);
1157 }
1158 
1159 /*
1160  * Perform a "speculative insertion". These can be backed out afterwards
1161  * without aborting the whole transaction. Other sessions can wait for the
1162  * speculative insertion to be confirmed, turning it into a regular tuple, or
1163  * aborted, as if it never existed. Speculatively inserted tuples behave as
1164  * "value locks" of short duration, used to implement INSERT .. ON CONFLICT.
1165  *
1166  * A transaction having performed a speculative insertion has to either abort,
1167  * or finish the speculative insertion with
1168  * table_tuple_complete_speculative(succeeded = ...).
1169  */
1170 static inline void
1172  CommandId cid, int options,
1173  struct BulkInsertStateData *bistate,
1174  uint32 specToken)
1175 {
1176  rel->rd_tableam->tuple_insert_speculative(rel, slot, cid, options,
1177  bistate, specToken);
1178 }
1179 
1180 /*
1181  * Complete "speculative insertion" started in the same transaction. If
1182  * succeeded is true, the tuple is fully inserted, if false, it's removed.
1183  */
1184 static inline void
1186  uint32 specToken, bool succeeded)
1187 {
1188  rel->rd_tableam->tuple_complete_speculative(rel, slot, specToken,
1189  succeeded);
1190 }
1191 
1192 /*
1193  * Insert multiple tuples into a table.
1194  *
1195  * This is like table_insert(), but inserts multiple tuples in one
1196  * operation. That's often faster than calling table_insert() in a loop,
1197  * because e.g. the AM can reduce WAL logging and page locking overhead.
1198  *
1199  * Except for taking `nslots` tuples as input, and an array of TupleTableSlots
1200  * in `slots`, the parameters for table_multi_insert() are the same as for
1201  * table_tuple_insert().
1202  *
1203  * Note: this leaks memory into the current memory context. You can create a
1204  * temporary context before calling this, if that's a problem.
1205  */
1206 static inline void
1207 table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots,
1208  CommandId cid, int options, struct BulkInsertStateData *bistate)
1209 {
1210  rel->rd_tableam->multi_insert(rel, slots, nslots,
1211  cid, options, bistate);
1212 }
1213 
1214 /*
1215  * Delete a tuple.
1216  *
1217  * NB: do not call this directly unless prepared to deal with
1218  * concurrent-update conditions. Use simple_table_tuple_delete instead.
1219  *
1220  * Input parameters:
1221  * relation - table to be modified (caller must hold suitable lock)
1222  * tid - TID of tuple to be deleted
1223  * cid - delete command ID (used for visibility test, and stored into
1224  * cmax if successful)
1225  * crosscheck - if not InvalidSnapshot, also check tuple against this
1226  * wait - true if should wait for any conflicting update to commit/abort
1227  * Output parameters:
1228  * tmfd - filled in failure cases (see below)
1229  * changingPart - true iff the tuple is being moved to another partition
1230  * table due to an update of the partition key. Otherwise, false.
1231  *
1232  * Normal, successful return value is TM_Ok, which means we did actually
1233  * delete it. Failure return codes are TM_SelfModified, TM_Updated, and
1234  * TM_BeingModified (the last only possible if wait == false).
1235  *
1236  * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1237  * t_xmax, and, if possible, and, if possible, t_cmax. See comments for
1238  * struct TM_FailureData for additional info.
1239  */
1240 static inline TM_Result
1242  Snapshot snapshot, Snapshot crosscheck, bool wait,
1243  TM_FailureData *tmfd, bool changingPart)
1244 {
1245  return rel->rd_tableam->tuple_delete(rel, tid, cid,
1246  snapshot, crosscheck,
1247  wait, tmfd, changingPart);
1248 }
1249 
1250 /*
1251  * Update a tuple.
1252  *
1253  * NB: do not call this directly unless you are prepared to deal with
1254  * concurrent-update conditions. Use simple_table_tuple_update instead.
1255  *
1256  * Input parameters:
1257  * relation - table to be modified (caller must hold suitable lock)
1258  * otid - TID of old tuple to be replaced
1259  * slot - newly constructed tuple data to store
1260  * cid - update command ID (used for visibility test, and stored into
1261  * cmax/cmin if successful)
1262  * crosscheck - if not InvalidSnapshot, also check old tuple against this
1263  * wait - true if should wait for any conflicting update to commit/abort
1264  * Output parameters:
1265  * tmfd - filled in failure cases (see below)
1266  * lockmode - filled with lock mode acquired on tuple
1267  * update_indexes - in success cases this is set to true if new index entries
1268  * are required for this tuple
1269  *
1270  * Normal, successful return value is TM_Ok, which means we did actually
1271  * update it. Failure return codes are TM_SelfModified, TM_Updated, and
1272  * TM_BeingModified (the last only possible if wait == false).
1273  *
1274  * On success, the slot's tts_tid and tts_tableOid are updated to match the new
1275  * stored tuple; in particular, slot->tts_tid is set to the TID where the
1276  * new tuple was inserted, and its HEAP_ONLY_TUPLE flag is set iff a HOT
1277  * update was done. However, any TOAST changes in the new tuple's
1278  * data are not reflected into *newtup.
1279  *
1280  * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1281  * t_xmax, and, if possible, t_cmax. See comments for struct TM_FailureData
1282  * for additional info.
1283  */
1284 static inline TM_Result
1286  CommandId cid, Snapshot snapshot, Snapshot crosscheck,
1287  bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
1288  bool *update_indexes)
1289 {
1290  return rel->rd_tableam->tuple_update(rel, otid, slot,
1291  cid, snapshot, crosscheck,
1292  wait, tmfd,
1293  lockmode, update_indexes);
1294 }
1295 
1296 /*
1297  * Lock a tuple in the specified mode.
1298  *
1299  * Input parameters:
1300  * relation: relation containing tuple (caller must hold suitable lock)
1301  * tid: TID of tuple to lock
1302  * snapshot: snapshot to use for visibility determinations
1303  * cid: current command ID (used for visibility test, and stored into
1304  * tuple's cmax if lock is successful)
1305  * mode: lock mode desired
1306  * wait_policy: what to do if tuple lock is not available
1307  * flags:
1308  * If TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS, follow the update chain to
1309  * also lock descendant tuples if lock modes don't conflict.
1310  * If TUPLE_LOCK_FLAG_FIND_LAST_VERSION, follow the update chain and lock
1311  * latest version.
1312  *
1313  * Output parameters:
1314  * *slot: contains the target tuple
1315  * *tmfd: filled in failure cases (see below)
1316  *
1317  * Function result may be:
1318  * TM_Ok: lock was successfully acquired
1319  * TM_Invisible: lock failed because tuple was never visible to us
1320  * TM_SelfModified: lock failed because tuple updated by self
1321  * TM_Updated: lock failed because tuple updated by other xact
1322  * TM_Deleted: lock failed because tuple deleted by other xact
1323  * TM_WouldBlock: lock couldn't be acquired and wait_policy is skip
1324  *
1325  * In the failure cases other than TM_Invisible and TM_Deleted, the routine
1326  * fills *tmfd with the tuple's t_ctid, t_xmax, and, if possible, t_cmax. See
1327  * comments for struct TM_FailureData for additional info.
1328  */
1329 static inline TM_Result
1332  LockWaitPolicy wait_policy, uint8 flags,
1333  TM_FailureData *tmfd)
1334 {
1335  return rel->rd_tableam->tuple_lock(rel, tid, snapshot, slot,
1336  cid, mode, wait_policy,
1337  flags, tmfd);
1338 }
1339 
1340 /*
1341  * Perform operations necessary to complete insertions made via
1342  * tuple_insert and multi_insert with a BulkInsertState specified.
1343  */
1344 static inline void
1346 {
1347  /* optional callback */
1348  if (rel->rd_tableam && rel->rd_tableam->finish_bulk_insert)
1349  rel->rd_tableam->finish_bulk_insert(rel, options);
1350 }
1351 
1352 
1353 /* ------------------------------------------------------------------------
1354  * DDL related functionality.
1355  * ------------------------------------------------------------------------
1356  */
1357 
1358 /*
1359  * Create storage for `rel` in `newrnode`, with persistence set to
1360  * `persistence`.
1361  *
1362  * This is used both during relation creation and various DDL operations to
1363  * create a new relfilenode that can be filled from scratch. When creating
1364  * new storage for an existing relfilenode, this should be called before the
1365  * relcache entry has been updated.
1366  *
1367  * *freezeXid, *minmulti are set to the xid / multixact horizon for the table
1368  * that pg_class.{relfrozenxid, relminmxid} have to be set to.
1369  */
1370 static inline void
1372  const RelFileNode *newrnode,
1373  char persistence,
1374  TransactionId *freezeXid,
1375  MultiXactId *minmulti)
1376 {
1377  rel->rd_tableam->relation_set_new_filenode(rel, newrnode, persistence,
1378  freezeXid, minmulti);
1379 }
1380 
1381 /*
1382  * Remove all table contents from `rel`, in a non-transactional manner.
1383  * Non-transactional meaning that there's no need to support rollbacks. This
1384  * commonly only is used to perform truncations for relfilenodes created in the
1385  * current transaction.
1386  */
1387 static inline void
1389 {
1391 }
1392 
1393 /*
1394  * Copy data from `rel` into the new relfilenode `newrnode`. The new
1395  * relfilenode may not have storage associated before this function is
1396  * called. This is only supposed to be used for low level operations like
1397  * changing a relation's tablespace.
1398  */
1399 static inline void
1401 {
1402  rel->rd_tableam->relation_copy_data(rel, newrnode);
1403 }
1404 
1405 /*
1406  * Copy data from `OldTable` into `NewTable`, as part of a CLUSTER or VACUUM
1407  * FULL.
1408  *
1409  * Additional Input parameters:
1410  * - use_sort - if true, the table contents are sorted appropriate for
1411  * `OldIndex`; if false and OldIndex is not InvalidOid, the data is copied
1412  * in that index's order; if false and OldIndex is InvalidOid, no sorting is
1413  * performed
1414  * - OldIndex - see use_sort
1415  * - OldestXmin - computed by vacuum_set_xid_limits(), even when
1416  * not needed for the relation's AM
1417  * - *xid_cutoff - ditto
1418  * - *multi_cutoff - ditto
1419  *
1420  * Output parameters:
1421  * - *xid_cutoff - rel's new relfrozenxid value, may be invalid
1422  * - *multi_cutoff - rel's new relminmxid value, may be invalid
1423  * - *tups_vacuumed - stats, for logging, if appropriate for AM
1424  * - *tups_recently_dead - stats, for logging, if appropriate for AM
1425  */
1426 static inline void
1428  Relation OldIndex,
1429  bool use_sort,
1431  TransactionId *xid_cutoff,
1432  MultiXactId *multi_cutoff,
1433  double *num_tuples,
1434  double *tups_vacuumed,
1435  double *tups_recently_dead)
1436 {
1437  OldTable->rd_tableam->relation_copy_for_cluster(OldTable, NewTable, OldIndex,
1438  use_sort, OldestXmin,
1439  xid_cutoff, multi_cutoff,
1440  num_tuples, tups_vacuumed,
1441  tups_recently_dead);
1442 }
1443 
1444 /*
1445  * Perform VACUUM on the relation. The VACUUM can be triggered by a user or by
1446  * autovacuum. The specific actions performed by the AM will depend heavily on
1447  * the individual AM.
1448  *
1449  * On entry a transaction needs to already been established, and the
1450  * table is locked with a ShareUpdateExclusive lock.
1451  *
1452  * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through this
1453  * routine, even if (for ANALYZE) it is part of the same VACUUM command.
1454  */
1455 static inline void
1457  BufferAccessStrategy bstrategy)
1458 {
1459  rel->rd_tableam->relation_vacuum(rel, params, bstrategy);
1460 }
1461 
1462 /*
1463  * Prepare to analyze block `blockno` of `scan`. The scan needs to have been
1464  * started with table_beginscan_analyze(). Note that this routine might
1465  * acquire resources like locks that are held until
1466  * table_scan_analyze_next_tuple() returns false.
1467  *
1468  * Returns false if block is unsuitable for sampling, true otherwise.
1469  */
1470 static inline bool
1472  BufferAccessStrategy bstrategy)
1473 {
1474  return scan->rs_rd->rd_tableam->scan_analyze_next_block(scan, blockno,
1475  bstrategy);
1476 }
1477 
1478 /*
1479  * Iterate over tuples in the block selected with
1480  * table_scan_analyze_next_block() (which needs to have returned true, and
1481  * this routine may not have returned false for the same block before). If a
1482  * tuple that's suitable for sampling is found, true is returned and a tuple
1483  * is stored in `slot`.
1484  *
1485  * *liverows and *deadrows are incremented according to the encountered
1486  * tuples.
1487  */
1488 static inline bool
1490  double *liverows, double *deadrows,
1491  TupleTableSlot *slot)
1492 {
1493  return scan->rs_rd->rd_tableam->scan_analyze_next_tuple(scan, OldestXmin,
1494  liverows, deadrows,
1495  slot);
1496 }
1497 
1498 /*
1499  * table_index_build_scan - scan the table to find tuples to be indexed
1500  *
1501  * This is called back from an access-method-specific index build procedure
1502  * after the AM has done whatever setup it needs. The parent table relation
1503  * is scanned to find tuples that should be entered into the index. Each
1504  * such tuple is passed to the AM's callback routine, which does the right
1505  * things to add it to the new index. After we return, the AM's index
1506  * build procedure does whatever cleanup it needs.
1507  *
1508  * The total count of live tuples is returned. This is for updating pg_class
1509  * statistics. (It's annoying not to be able to do that here, but we want to
1510  * merge that update with others; see index_update_stats.) Note that the
1511  * index AM itself must keep track of the number of index tuples; we don't do
1512  * so here because the AM might reject some of the tuples for its own reasons,
1513  * such as being unable to store NULLs.
1514  *
1515  * If 'progress', the PROGRESS_SCAN_BLOCKS_TOTAL counter is updated when
1516  * starting the scan, and PROGRESS_SCAN_BLOCKS_DONE is updated as we go along.
1517  *
1518  * A side effect is to set indexInfo->ii_BrokenHotChain to true if we detect
1519  * any potentially broken HOT chains. Currently, we set this if there are any
1520  * RECENTLY_DEAD or DELETE_IN_PROGRESS entries in a HOT chain, without trying
1521  * very hard to detect whether they're really incompatible with the chain tip.
1522  * This only really makes sense for heap AM, it might need to be generalized
1523  * for other AMs later.
1524  */
1525 static inline double
1527  Relation index_rel,
1528  struct IndexInfo *index_info,
1529  bool allow_sync,
1530  bool progress,
1532  void *callback_state,
1533  TableScanDesc scan)
1534 {
1535  return table_rel->rd_tableam->index_build_range_scan(table_rel,
1536  index_rel,
1537  index_info,
1538  allow_sync,
1539  false,
1540  progress,
1541  0,
1543  callback,
1544  callback_state,
1545  scan);
1546 }
1547 
1548 /*
1549  * As table_index_build_scan(), except that instead of scanning the complete
1550  * table, only the given number of blocks are scanned. Scan to end-of-rel can
1551  * be signaled by passing InvalidBlockNumber as numblocks. Note that
1552  * restricting the range to scan cannot be done when requesting syncscan.
1553  *
1554  * When "anyvisible" mode is requested, all tuples visible to any transaction
1555  * are indexed and counted as live, including those inserted or deleted by
1556  * transactions that are still in progress.
1557  */
1558 static inline double
1560  Relation index_rel,
1561  struct IndexInfo *index_info,
1562  bool allow_sync,
1563  bool anyvisible,
1564  bool progress,
1565  BlockNumber start_blockno,
1566  BlockNumber numblocks,
1568  void *callback_state,
1569  TableScanDesc scan)
1570 {
1571  return table_rel->rd_tableam->index_build_range_scan(table_rel,
1572  index_rel,
1573  index_info,
1574  allow_sync,
1575  anyvisible,
1576  progress,
1577  start_blockno,
1578  numblocks,
1579  callback,
1580  callback_state,
1581  scan);
1582 }
1583 
1584 /*
1585  * table_index_validate_scan - second table scan for concurrent index build
1586  *
1587  * See validate_index() for an explanation.
1588  */
1589 static inline void
1591  Relation index_rel,
1592  struct IndexInfo *index_info,
1593  Snapshot snapshot,
1594  struct ValidateIndexState *state)
1595 {
1596  table_rel->rd_tableam->index_validate_scan(table_rel,
1597  index_rel,
1598  index_info,
1599  snapshot,
1600  state);
1601 }
1602 
1603 
1604 /* ----------------------------------------------------------------------------
1605  * Miscellaneous functionality
1606  * ----------------------------------------------------------------------------
1607  */
1608 
1609 /*
1610  * Return the current size of `rel` in bytes. If `forkNumber` is
1611  * InvalidForkNumber, return the relation's overall size, otherwise the size
1612  * for the indicated fork.
1613  *
1614  * Note that the overall size might not be the equivalent of the sum of sizes
1615  * for the individual forks for some AMs, e.g. because the AMs storage does
1616  * not neatly map onto the builtin types of forks.
1617  */
1618 static inline uint64
1620 {
1621  return rel->rd_tableam->relation_size(rel, forkNumber);
1622 }
1623 
1624 /*
1625  * table_relation_needs_toast_table - does this relation need a toast table?
1626  */
1627 static inline bool
1629 {
1630  return rel->rd_tableam->relation_needs_toast_table(rel);
1631 }
1632 
1633 /*
1634  * Return the OID of the AM that should be used to implement the TOAST table
1635  * for this relation.
1636  */
1637 static inline Oid
1639 {
1640  return rel->rd_tableam->relation_toast_am(rel);
1641 }
1642 
1643 /*
1644  * Fetch all or part of a TOAST value from a TOAST table.
1645  *
1646  * If this AM is never used to implement a TOAST table, then this callback
1647  * is not needed. But, if toasted values are ever stored in a table of this
1648  * type, then you will need this callback.
1649  *
1650  * toastrel is the relation in which the toasted value is stored.
1651  *
1652  * valueid identifes which toast value is to be fetched. For the heap,
1653  * this corresponds to the values stored in the chunk_id column.
1654  *
1655  * attrsize is the total size of the toast value to be fetched.
1656  *
1657  * sliceoffset is the offset within the toast value of the first byte that
1658  * should be fetched.
1659  *
1660  * slicelength is the number of bytes from the toast value that should be
1661  * fetched.
1662  *
1663  * result is caller-allocated space into which the fetched bytes should be
1664  * stored.
1665  */
1666 static inline void
1668  int32 attrsize, int32 sliceoffset,
1669  int32 slicelength, struct varlena *result)
1670 {
1671  toastrel->rd_tableam->relation_fetch_toast_slice(toastrel, valueid,
1672  attrsize,
1673  sliceoffset, slicelength,
1674  result);
1675 }
1676 
1677 
1678 /* ----------------------------------------------------------------------------
1679  * Planner related functionality
1680  * ----------------------------------------------------------------------------
1681  */
1682 
1683 /*
1684  * Estimate the current size of the relation, as an AM specific workhorse for
1685  * estimate_rel_size(). Look there for an explanation of the parameters.
1686  */
1687 static inline void
1689  BlockNumber *pages, double *tuples,
1690  double *allvisfrac)
1691 {
1692  rel->rd_tableam->relation_estimate_size(rel, attr_widths, pages, tuples,
1693  allvisfrac);
1694 }
1695 
1696 
1697 /* ----------------------------------------------------------------------------
1698  * Executor related functionality
1699  * ----------------------------------------------------------------------------
1700  */
1701 
1702 /*
1703  * Prepare to fetch / check / return tuples from `tbmres->blockno` as part of
1704  * a bitmap table scan. `scan` needs to have been started via
1705  * table_beginscan_bm(). Returns false if there are no tuples to be found on
1706  * the page, true otherwise.
1707  *
1708  * Note, this is an optionally implemented function, therefore should only be
1709  * used after verifying the presence (at plan time or such).
1710  */
1711 static inline bool
1713  struct TBMIterateResult *tbmres)
1714 {
1715  return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan,
1716  tbmres);
1717 }
1718 
1719 /*
1720  * Fetch the next tuple of a bitmap table scan into `slot` and return true if
1721  * a visible tuple was found, false otherwise.
1722  * table_scan_bitmap_next_block() needs to previously have selected a
1723  * block (i.e. returned true), and no previous
1724  * table_scan_bitmap_next_tuple() for the same block may have
1725  * returned false.
1726  */
1727 static inline bool
1729  struct TBMIterateResult *tbmres,
1730  TupleTableSlot *slot)
1731 {
1732  return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
1733  tbmres,
1734  slot);
1735 }
1736 
1737 /*
1738  * Prepare to fetch tuples from the next block in a sample scan. Returns false
1739  * if the sample scan is finished, true otherwise. `scan` needs to have been
1740  * started via table_beginscan_sampling().
1741  *
1742  * This will call the TsmRoutine's NextSampleBlock() callback if necessary
1743  * (i.e. NextSampleBlock is not NULL), or perform a sequential scan over the
1744  * underlying relation.
1745  */
1746 static inline bool
1748  struct SampleScanState *scanstate)
1749 {
1750  return scan->rs_rd->rd_tableam->scan_sample_next_block(scan, scanstate);
1751 }
1752 
1753 /*
1754  * Fetch the next sample tuple into `slot` and return true if a visible tuple
1755  * was found, false otherwise. table_scan_sample_next_block() needs to
1756  * previously have selected a block (i.e. returned true), and no previous
1757  * table_scan_sample_next_tuple() for the same block may have returned false.
1758  *
1759  * This will call the TsmRoutine's NextSampleTuple() callback.
1760  */
1761 static inline bool
1763  struct SampleScanState *scanstate,
1764  TupleTableSlot *slot)
1765 {
1766  return scan->rs_rd->rd_tableam->scan_sample_next_tuple(scan, scanstate,
1767  slot);
1768 }
1769 
1770 
1771 /* ----------------------------------------------------------------------------
1772  * Functions to make modifications a bit simpler.
1773  * ----------------------------------------------------------------------------
1774  */
1775 
1776 extern void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot);
1777 extern void simple_table_tuple_delete(Relation rel, ItemPointer tid,
1778  Snapshot snapshot);
1779 extern void simple_table_tuple_update(Relation rel, ItemPointer otid,
1780  TupleTableSlot *slot, Snapshot snapshot,
1781  bool *update_indexes);
1782 
1783 
1784 /* ----------------------------------------------------------------------------
1785  * Helper functions to implement parallel scans for block oriented AMs.
1786  * ----------------------------------------------------------------------------
1787  */
1788 
1791  ParallelTableScanDesc pscan);
1793  ParallelTableScanDesc pscan);
1798 
1799 
1800 /* ----------------------------------------------------------------------------
1801  * Helper functions to implement relation sizing for block oriented AMs.
1802  * ----------------------------------------------------------------------------
1803  */
1804 
1805 extern uint64 table_block_relation_size(Relation rel, ForkNumber forkNumber);
1807  int32 *attr_widths,
1808  BlockNumber *pages,
1809  double *tuples,
1810  double *allvisfrac,
1811  Size overhead_bytes_per_tuple,
1812  Size usable_bytes_per_page);
1813 
1814 /* ----------------------------------------------------------------------------
1815  * Functions in tableamapi.c
1816  * ----------------------------------------------------------------------------
1817  */
1818 
1819 extern const TableAmRoutine *GetTableAmRoutine(Oid amhandler);
1820 extern const TableAmRoutine *GetHeapamTableAmRoutine(void);
1821 extern bool check_default_table_access_method(char **newval, void **extra,
1822  GucSource source);
1823 
1824 #endif /* TABLEAM_H */
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:223
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:618
Oid tts_tableOid
Definition: tuptable.h:131
uint32 CommandId
Definition: c.h:527
ItemPointerData ctid
Definition: tableam.h:124
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:1728
static void table_relation_estimate_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:1688
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid(* relation_toast_am)(Relation rel)
Definition: tableam.h:589
LockTupleMode
Definition: lockoptions.h:49
ScanOptions
Definition: tableam.h:44
NodeTag type
Definition: tableam.h:165
static void table_relation_copy_data(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:1400
TM_Result(* tuple_update)(Relation rel, ItemPointer otid, TupleTableSlot *slot, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode, bool *update_indexes)
Definition: tableam.h:389
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:232
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
Definition: tableam.c:141
uint32 TransactionId
Definition: c.h:513
Size table_block_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.c:378
Size table_block_parallelscan_estimate(Relation rel)
Definition: tableam.c:372
struct TableAmRoutine TableAmRoutine
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:268
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:274
void table_block_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.c:396
void(* scan_end)(TableScanDesc scan)
Definition: tableam.h:210
bool(* scan_sample_next_block)(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:702
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:572
static void table_relation_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
Definition: tableam.h:1667
char * default_table_access_method
Definition: tableam.c:34
CommandId cmax
Definition: tableam.h:126
double(* index_build_range_scan)(Relation table_rel, Relation index_rel, struct 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:539
unsigned char uint8
Definition: c.h:365
static void table_relation_vacuum(Relation rel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:1456
static IndexFetchTableData * table_index_fetch_begin(Relation rel)
Definition: tableam.h:965
void(* index_validate_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:552
static void table_finish_bulk_insert(Relation rel, int options)
Definition: tableam.h:1345
static bool table_scan_sample_next_block(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:1747
uint32 BlockNumber
Definition: block.h:31
static TableScanDesc table_beginscan_sampling(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:815
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:318
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:903
void(* relation_nontransactional_truncate)(Relation rel)
Definition: tableam.h:461
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
TransactionId(* compute_xid_horizon_for_tuples)(Relation rel, ItemPointerData *items, int nitems)
Definition: tableam.h:345
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:871
static void table_tuple_complete_speculative(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:1185
bool(* scan_analyze_next_block)(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:520
void table_block_parallelscan_startblock_init(Relation rel, ParallelBlockTableScanDesc pbscan)
Definition: tableam.c:411
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
Definition: tableam.h:778
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:1152
uint64 table_block_relation_size(Relation rel, ForkNumber forkNumber)
Definition: tableam.c:512
signed int int32
Definition: c.h:355
void table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot)
Definition: tableam.c:110
GucSource
Definition: guc.h:105
bool synchronize_seqscans
Definition: tableam.c:35
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:361
Definition: type.h:89
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:216
static bool table_scan_sample_next_tuple(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:1762
static TransactionId table_compute_xid_horizon_for_tuples(Relation rel, ItemPointerData *items, int nitems)
Definition: tableam.h:1104
bool table_index_fetch_tuple_check(Relation rel, ItemPointer tid, Snapshot snapshot, bool *all_dead)
Definition: tableam.c:205
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:356
static void table_relation_nontransactional_truncate(Relation rel)
Definition: tableam.h:1388
static bool table_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:1471
TransactionId xmax
Definition: tableam.h:125
void(* finish_bulk_insert)(Relation rel, int options)
Definition: tableam.h:423
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:754
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:369
static double table_index_build_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, bool allow_sync, bool progress, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
Definition: tableam.h:1526
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:1330
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:659
void(* relation_set_new_filenode)(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:447
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
void simple_table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot, Snapshot snapshot, bool *update_indexes)
Definition: tableam.c:324
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:200
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:375
void(* relation_copy_for_cluster)(Relation NewTable, Relation OldTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
Definition: tableam.h:473
bool(* scan_analyze_next_tuple)(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:532
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:673
static double table_index_build_range_scan(Relation table_rel, Relation index_rel, struct 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:1559
static uint64 table_relation_size(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:1619
TableScanDesc table_beginscan_parallel(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.c:161
ScanDirection
Definition: sdir.h:22
static TransactionId OldestXmin
Definition: vacuumlazy.c:332
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
Definition: tableam.c:126
unsigned int uint32
Definition: c.h:367
void(* relation_copy_data)(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:469
static void table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:1207
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:251
ForkNumber
Definition: relpath.h:40
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:947
static bool table_tuple_fetch_row_version(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:1054
static char ** options
int progress
Definition: pgbench.c:234
TM_Result
Definition: tableam.h:69
uintptr_t Datum
Definition: postgres.h:367
static void table_tuple_insert_speculative(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:1171
static bool table_index_fetch_tuple(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:1014
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
static void table_rescan_set_params(TableScanDesc scan, struct ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:886
BlockNumber table_block_parallelscan_nextpage(Relation rel, ParallelBlockTableScanDesc pbscan)
Definition: tableam.c:454
static TM_Result table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
Definition: tableam.h:1241
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:582
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition: tableam.h:975
TransactionId MultiXactId
Definition: c.h:523
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition: tableam.h:279
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:401
TupleTableSlot * table_slot_create(Relation rel, List **reglist)
Definition: tableam.c:77
static bool table_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:1092
static bool table_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:1489
Definition: regguts.h:298
Definition: tableam.h:75
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:340
const TableAmRoutine * GetHeapamTableAmRoutine(void)
size_t Size
Definition: c.h:466
#define InvalidBlockNumber
Definition: block.h:33
struct TM_FailureData TM_FailureData
#define newval
bool(* scan_sample_next_tuple)(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:718
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:552
void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot)
Definition: tableam.c:265
static void table_relation_set_new_filenode(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:1371
Relation rs_rd
Definition: relscan.h:34
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:862
void simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot)
Definition: tableam.c:279
static Datum values[MAXATTR]
Definition: bootstrap.c:167
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
Definition: tableam.h:838
TableScanDesc table_beginscan_catalog(Relation rel, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:98
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:326
static void table_index_validate_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:1590
bool check_default_table_access_method(char **newval, void **extra, GucSource source)
Definition: tableamapi.c:111
const TupleTableSlotOps * table_slot_callbacks(Relation rel)
Definition: tableam.c:44
static bool table_scan_bitmap_next_block(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:1712
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:799
static bool table_tuple_tid_valid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:1071
Definition: c.h:555
static bool table_relation_needs_toast_table(Relation rel)
Definition: tableam.h:1628
void(* relation_vacuum)(Relation onerel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:499
static Oid table_relation_toast_am(Relation rel)
Definition: tableam.h:1638
Relation rel
Definition: relscan.h:91
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, bool *update_indexes)
Definition: tableam.h:1285
bool traversed
Definition: tableam.h:127
static void table_index_fetch_end(struct IndexFetchTableData *scan)
Definition: tableam.h:984
Definition: pg_list.h:50
const TableAmRoutine * GetTableAmRoutine(Oid amhandler)
Definition: tableamapi.c:34
bool(* index_fetch_tuple)(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:301
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
Definition: tableam.h:379
#define RelationGetRelid(relation)
Definition: rel.h:456
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)
Definition: tableam.h:1427
LockWaitPolicy
Definition: lockoptions.h:36
void(* IndexBuildCallback)(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
Definition: tableam.h:144
void(* relation_fetch_toast_slice)(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
Definition: tableam.h:596
unsigned char bool
Definition: c.h:317
static TableScanDesc table_beginscan_analyze(Relation rel)
Definition: tableam.h:851
struct TableScanDescData * TableScanDesc
Definition: relscan.h:49