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_ANALYZE = 1 << 3,
51 
52  /* several of SO_ALLOW_* may be specified */
53  /* allow or disallow use of access strategy */
54  SO_ALLOW_STRAT = 1 << 4,
55  /* report location to syncscan logic? */
56  SO_ALLOW_SYNC = 1 << 5,
57  /* verify visibility page-at-a-time? */
59 
60  /* unregister snapshot at scan end? */
62 } ScanOptions;
63 
64 /*
65  * Result codes for table_{update,delete,lock_tuple}, and for visibility
66  * routines inside table AMs.
67  */
68 typedef enum TM_Result
69 {
70  /*
71  * Signals that the action succeeded (i.e. update/delete performed, lock
72  * was acquired)
73  */
75 
76  /* The affected tuple wasn't visible to the relevant snapshot */
78 
79  /* The affected tuple was already modified by the calling backend */
81 
82  /*
83  * The affected tuple was updated by another transaction. This includes
84  * the case where tuple was moved to another partition.
85  */
87 
88  /* The affected tuple was deleted by another transaction */
90 
91  /*
92  * The affected tuple is currently being modified by another session. This
93  * will only be returned if table_(update/delete/lock_tuple) are
94  * instructed not to wait.
95  */
97 
98  /* lock couldn't be acquired, action skipped. Only used by lock_tuple */
100 } TM_Result;
101 
102 /*
103  * When table_tuple_update, table_tuple_delete, or table_tuple_lock fail
104  * because the target tuple is already outdated, they fill in this struct to
105  * provide information to the caller about what happened.
106  *
107  * ctid is the target's ctid link: it is the same as the target's TID if the
108  * target was deleted, or the location of the replacement tuple if the target
109  * was updated.
110  *
111  * xmax is the outdating transaction's XID. If the caller wants to visit the
112  * replacement tuple, it must check that this matches before believing the
113  * replacement is really a match.
114  *
115  * cmax is the outdating command's CID, but only when the failure code is
116  * TM_SelfModified (i.e., something in the current transaction outdated the
117  * tuple); otherwise cmax is zero. (We make this restriction because
118  * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
119  * transactions.)
120  */
121 typedef struct TM_FailureData
122 {
126  bool traversed;
128 
129 /* "options" flag bits for table_tuple_insert */
130 #define TABLE_INSERT_SKIP_WAL 0x0001
131 #define TABLE_INSERT_SKIP_FSM 0x0002
132 #define TABLE_INSERT_FROZEN 0x0004
133 #define TABLE_INSERT_NO_LOGICAL 0x0008
134 
135 /* flag bits for table_tuple_lock */
136 /* Follow tuples whose update is in progress if lock modes don't conflict */
137 #define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS (1 << 0)
138 /* Follow update chain and lock latest version of tuple */
139 #define TUPLE_LOCK_FLAG_FIND_LAST_VERSION (1 << 1)
140 
141 
142 /* Typedef for callback function for table_index_build_scan */
144  ItemPointer tid,
145  Datum *values,
146  bool *isnull,
147  bool tupleIsAlive,
148  void *state);
149 
150 /*
151  * API struct for a table AM. Note this must be allocated in a
152  * server-lifetime manner, typically as a static const struct, which then gets
153  * returned by FormData_pg_am.amhandler.
154  *
155  * In most cases it's not appropriate to call the callbacks directly, use the
156  * table_* wrapper functions instead.
157  *
158  * GetTableAmRoutine() asserts that required callbacks are filled in, remember
159  * to update when adding a callback.
160  */
161 typedef struct TableAmRoutine
162 {
163  /* this must be set to T_TableAmRoutine */
165 
166 
167  /* ------------------------------------------------------------------------
168  * Slot related callbacks.
169  * ------------------------------------------------------------------------
170  */
171 
172  /*
173  * Return slot implementation suitable for storing a tuple of this AM.
174  */
175  const TupleTableSlotOps *(*slot_callbacks) (Relation rel);
176 
177 
178  /* ------------------------------------------------------------------------
179  * Table scan callbacks.
180  * ------------------------------------------------------------------------
181  */
182 
183  /*
184  * Start a scan of `rel`. The callback has to return a TableScanDesc,
185  * which will typically be embedded in a larger, AM specific, struct.
186  *
187  * If nkeys != 0, the results need to be filtered by those scan keys.
188  *
189  * pscan, if not NULL, will have already been initialized with
190  * parallelscan_initialize(), and has to be for the same relation. Will
191  * only be set coming from table_beginscan_parallel().
192  *
193  * `flags` is a bitmask indicating the type of scan (ScanOptions's
194  * SO_TYPE_*, currently only one may be specified), options controlling
195  * the scan's behaviour (ScanOptions's SO_ALLOW_*, several may be
196  * specified, an AM may ignore unsupported ones) and whether the snapshot
197  * needs to be deallocated at scan_end (ScanOptions's SO_TEMP_SNAPSHOT).
198  */
199  TableScanDesc (*scan_begin) (Relation rel,
200  Snapshot snapshot,
201  int nkeys, struct ScanKeyData *key,
202  ParallelTableScanDesc pscan,
203  uint32 flags);
204 
205  /*
206  * Release resources and deallocate scan. If TableScanDesc.temp_snap,
207  * TableScanDesc.rs_snapshot needs to be unregistered.
208  */
209  void (*scan_end) (TableScanDesc scan);
210 
211  /*
212  * Restart relation scan. If set_params is set to true, allow_{strat,
213  * sync, pagemode} (see scan_begin) changes should be taken into account.
214  */
215  void (*scan_rescan) (TableScanDesc scan, struct ScanKeyData *key,
216  bool set_params, bool allow_strat,
217  bool allow_sync, bool allow_pagemode);
218 
219  /*
220  * Return next tuple from `scan`, store in slot.
221  */
222  bool (*scan_getnextslot) (TableScanDesc scan,
223  ScanDirection direction,
224  TupleTableSlot *slot);
225 
226 
227  /* ------------------------------------------------------------------------
228  * Parallel table scan related functions.
229  * ------------------------------------------------------------------------
230  */
231 
232  /*
233  * Estimate the size of shared memory needed for a parallel scan of this
234  * relation. The snapshot does not need to be accounted for.
235  */
236  Size (*parallelscan_estimate) (Relation rel);
237 
238  /*
239  * Initialize ParallelTableScanDesc for a parallel scan of this relation.
240  * `pscan` will be sized according to parallelscan_estimate() for the same
241  * relation.
242  */
243  Size (*parallelscan_initialize) (Relation rel,
244  ParallelTableScanDesc pscan);
245 
246  /*
247  * Reinitialize `pscan` for a new scan. `rel` will be the same relation as
248  * when `pscan` was initialized by parallelscan_initialize.
249  */
250  void (*parallelscan_reinitialize) (Relation rel,
251  ParallelTableScanDesc pscan);
252 
253 
254  /* ------------------------------------------------------------------------
255  * Index Scan Callbacks
256  * ------------------------------------------------------------------------
257  */
258 
259  /*
260  * Prepare to fetch tuples from the relation, as needed when fetching
261  * tuples for an index scan. The callback has to return an
262  * IndexFetchTableData, which the AM will typically embed in a larger
263  * structure with additional information.
264  *
265  * Tuples for an index scan can then be fetched via index_fetch_tuple.
266  */
267  struct IndexFetchTableData *(*index_fetch_begin) (Relation rel);
268 
269  /*
270  * Reset index fetch. Typically this will release cross index fetch
271  * resources held in IndexFetchTableData.
272  */
273  void (*index_fetch_reset) (struct IndexFetchTableData *data);
274 
275  /*
276  * Release resources and deallocate index fetch.
277  */
278  void (*index_fetch_end) (struct IndexFetchTableData *data);
279 
280  /*
281  * Fetch tuple at `tid` into `slot`, after doing a visibility test
282  * according to `snapshot`. If a tuple was found and passed the visibility
283  * test, return true, false otherwise.
284  *
285  * Note that AMs that do not necessarily update indexes when indexed
286  * columns do not change, need to return the current/correct version of
287  * the tuple that is visible to the snapshot, even if the tid points to an
288  * older version of the tuple.
289  *
290  * *call_again is false on the first call to index_fetch_tuple for a tid.
291  * If there potentially is another tuple matching the tid, *call_again
292  * needs be set to true by index_fetch_tuple, signalling to the caller
293  * that index_fetch_tuple should be called again for the same tid.
294  *
295  * *all_dead, if all_dead is not NULL, should be set to true by
296  * index_fetch_tuple iff it is guaranteed that no backend needs to see
297  * that tuple. Index AMs can use that to avoid returning that tid in
298  * future searches.
299  */
300  bool (*index_fetch_tuple) (struct IndexFetchTableData *scan,
301  ItemPointer tid,
302  Snapshot snapshot,
303  TupleTableSlot *slot,
304  bool *call_again, bool *all_dead);
305 
306 
307  /* ------------------------------------------------------------------------
308  * Callbacks for non-modifying operations on individual tuples
309  * ------------------------------------------------------------------------
310  */
311 
312  /*
313  * Fetch tuple at `tid` into `slot`, after doing a visibility test
314  * according to `snapshot`. If a tuple was found and passed the visibility
315  * test, returns true, false otherwise.
316  */
317  bool (*tuple_fetch_row_version) (Relation rel,
318  ItemPointer tid,
319  Snapshot snapshot,
320  TupleTableSlot *slot);
321 
322  /*
323  * Is tid valid for a scan of this relation.
324  */
325  bool (*tuple_tid_valid) (TableScanDesc scan,
326  ItemPointer tid);
327 
328  /*
329  * Return the latest version of the tuple at `tid`, by updating `tid` to
330  * point at the newest version.
331  */
332  void (*tuple_get_latest_tid) (TableScanDesc scan,
333  ItemPointer tid);
334 
335  /*
336  * Does the tuple in `slot` satisfy `snapshot`? The slot needs to be of
337  * the appropriate type for the AM.
338  */
339  bool (*tuple_satisfies_snapshot) (Relation rel,
340  TupleTableSlot *slot,
341  Snapshot snapshot);
342 
343  /* see table_compute_xid_horizon_for_tuples() */
344  TransactionId (*compute_xid_horizon_for_tuples) (Relation rel,
345  ItemPointerData *items,
346  int nitems);
347 
348 
349  /* ------------------------------------------------------------------------
350  * Manipulations of physical tuples.
351  * ------------------------------------------------------------------------
352  */
353 
354  /* see table_tuple_insert() for reference about parameters */
355  void (*tuple_insert) (Relation rel, TupleTableSlot *slot,
356  CommandId cid, int options,
357  struct BulkInsertStateData *bistate);
358 
359  /* see table_tuple_insert_speculative() for reference about parameters */
360  void (*tuple_insert_speculative) (Relation rel,
361  TupleTableSlot *slot,
362  CommandId cid,
363  int options,
364  struct BulkInsertStateData *bistate,
365  uint32 specToken);
366 
367  /* see table_tuple_complete_speculative() for reference about parameters */
368  void (*tuple_complete_speculative) (Relation rel,
369  TupleTableSlot *slot,
370  uint32 specToken,
371  bool succeeded);
372 
373  /* see table_multi_insert() for reference about parameters */
374  void (*multi_insert) (Relation rel, TupleTableSlot **slots, int nslots,
375  CommandId cid, int options, struct BulkInsertStateData *bistate);
376 
377  /* see table_tuple_delete() for reference about parameters */
378  TM_Result (*tuple_delete) (Relation rel,
379  ItemPointer tid,
380  CommandId cid,
381  Snapshot snapshot,
382  Snapshot crosscheck,
383  bool wait,
384  TM_FailureData *tmfd,
385  bool changingPart);
386 
387  /* see table_tuple_update() for reference about parameters */
388  TM_Result (*tuple_update) (Relation rel,
389  ItemPointer otid,
390  TupleTableSlot *slot,
391  CommandId cid,
392  Snapshot snapshot,
393  Snapshot crosscheck,
394  bool wait,
395  TM_FailureData *tmfd,
396  LockTupleMode *lockmode,
397  bool *update_indexes);
398 
399  /* see table_tuple_lock() for reference about parameters */
400  TM_Result (*tuple_lock) (Relation rel,
401  ItemPointer tid,
402  Snapshot snapshot,
403  TupleTableSlot *slot,
404  CommandId cid,
406  LockWaitPolicy wait_policy,
407  uint8 flags,
408  TM_FailureData *tmfd);
409 
410  /*
411  * Perform operations necessary to complete insertions made via
412  * tuple_insert and multi_insert with a BulkInsertState specified. This
413  * may for example be used to flush the relation, when the
414  * TABLE_INSERT_SKIP_WAL option was used.
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
486  * triggered by a user or by autovacuum. The specific actions
487  * performed by the AM will 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_analyze is an alternative entry point for setting up a
834  * TableScanDesc for an ANALYZE 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_ANALYZE;
841 
842  return rel->rd_tableam->scan_begin(rel, NULL, 0, NULL, NULL, flags);
843 }
844 
845 /*
846  * End relation scan.
847  */
848 static inline void
850 {
851  scan->rs_rd->rd_tableam->scan_end(scan);
852 }
853 
854 /*
855  * Restart a relation scan.
856  */
857 static inline void
859  struct ScanKeyData *key)
860 {
861  scan->rs_rd->rd_tableam->scan_rescan(scan, key, false, false, false, false);
862 }
863 
864 /*
865  * Restart a relation scan after changing params.
866  *
867  * This call allows changing the buffer strategy, syncscan, and pagemode
868  * options before starting a fresh scan. Note that although the actual use of
869  * syncscan might change (effectively, enabling or disabling reporting), the
870  * previously selected startblock will be kept.
871  */
872 static inline void
874  bool allow_strat, bool allow_sync, bool allow_pagemode)
875 {
876  scan->rs_rd->rd_tableam->scan_rescan(scan, key, true,
877  allow_strat, allow_sync,
878  allow_pagemode);
879 }
880 
881 /*
882  * Update snapshot used by the scan.
883  */
884 extern void table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot);
885 
886 /*
887  * Return next tuple from `scan`, store in slot.
888  */
889 static inline bool
891 {
892  slot->tts_tableOid = RelationGetRelid(sscan->rs_rd);
893  return sscan->rs_rd->rd_tableam->scan_getnextslot(sscan, direction, slot);
894 }
895 
896 
897 /* ----------------------------------------------------------------------------
898  * Parallel table scan related functions.
899  * ----------------------------------------------------------------------------
900  */
901 
902 /*
903  * Estimate the size of shared memory needed for a parallel scan of this
904  * relation.
905  */
906 extern Size table_parallelscan_estimate(Relation rel, Snapshot snapshot);
907 
908 /*
909  * Initialize ParallelTableScanDesc for a parallel scan of this
910  * relation. `pscan` needs to be sized according to parallelscan_estimate()
911  * for the same relation. Call this just once in the leader process; then,
912  * individual workers attach via table_beginscan_parallel.
913  */
915  ParallelTableScanDesc pscan,
916  Snapshot snapshot);
917 
918 /*
919  * Begin a parallel scan. `pscan` needs to have been initialized with
920  * table_parallelscan_initialize(), for the same relation. The initialization
921  * does not need to have happened in this backend.
922  *
923  * Caller must hold a suitable lock on the relation.
924  */
926  ParallelTableScanDesc pscan);
927 
928 /*
929  * Restart a parallel scan. Call this in the leader process. Caller is
930  * responsible for making sure that all workers have finished the scan
931  * beforehand.
932  */
933 static inline void
935 {
936  rel->rd_tableam->parallelscan_reinitialize(rel, pscan);
937 }
938 
939 
940 /* ----------------------------------------------------------------------------
941  * Index scan related functions.
942  * ----------------------------------------------------------------------------
943  */
944 
945 /*
946  * Prepare to fetch tuples from the relation, as needed when fetching tuples
947  * for an index scan.
948  *
949  * Tuples for an index scan can then be fetched via table_index_fetch_tuple().
950  */
951 static inline IndexFetchTableData *
953 {
954  return rel->rd_tableam->index_fetch_begin(rel);
955 }
956 
957 /*
958  * Reset index fetch. Typically this will release cross index fetch resources
959  * held in IndexFetchTableData.
960  */
961 static inline void
963 {
964  scan->rel->rd_tableam->index_fetch_reset(scan);
965 }
966 
967 /*
968  * Release resources and deallocate index fetch.
969  */
970 static inline void
972 {
973  scan->rel->rd_tableam->index_fetch_end(scan);
974 }
975 
976 /*
977  * Fetches, as part of an index scan, tuple at `tid` into `slot`, after doing
978  * a visibility test according to `snapshot`. If a tuple was found and passed
979  * the visibility test, returns true, false otherwise.
980  *
981  * *call_again needs to be false on the first call to table_index_fetch_tuple() for
982  * a tid. If there potentially is another tuple matching the tid, *call_again
983  * will be set to true, signalling that table_index_fetch_tuple() should be called
984  * again for the same tid.
985  *
986  * *all_dead, if all_dead is not NULL, will be set to true by
987  * table_index_fetch_tuple() iff it is guaranteed that no backend needs to see
988  * that tuple. Index AMs can use that to avoid returning that tid in future
989  * searches.
990  *
991  * The difference between this function and table_fetch_row_version is that
992  * this function returns the currently visible version of a row if the AM
993  * supports storing multiple row versions reachable via a single index entry
994  * (like heap's HOT). Whereas table_fetch_row_version only evaluates the
995  * tuple exactly at `tid`. Outside of index entry ->table tuple lookups,
996  * table_tuple_fetch_row_version is what's usually needed.
997  */
998 static inline bool
1000  ItemPointer tid,
1001  Snapshot snapshot,
1002  TupleTableSlot *slot,
1003  bool *call_again, bool *all_dead)
1004 {
1005 
1006  return scan->rel->rd_tableam->index_fetch_tuple(scan, tid, snapshot,
1007  slot, call_again,
1008  all_dead);
1009 }
1010 
1011 /*
1012  * This is a convenience wrapper around table_index_fetch_tuple() which
1013  * returns whether there are table tuple items corresponding to an index
1014  * entry. This likely is only useful to verify if there's a conflict in a
1015  * unique index.
1016  */
1017 extern bool table_index_fetch_tuple_check(Relation rel,
1018  ItemPointer tid,
1019  Snapshot snapshot,
1020  bool *all_dead);
1021 
1022 
1023 /* ------------------------------------------------------------------------
1024  * Functions for non-modifying operations on individual tuples
1025  * ------------------------------------------------------------------------
1026  */
1027 
1028 
1029 /*
1030  * Fetch tuple at `tid` into `slot`, after doing a visibility test according to
1031  * `snapshot`. If a tuple was found and passed the visibility test, returns
1032  * true, false otherwise.
1033  *
1034  * See table_index_fetch_tuple's comment about what the difference between
1035  * these functions is. It is correct to use this function outside of index
1036  * entry->table tuple lookups.
1037  */
1038 static inline bool
1040  ItemPointer tid,
1041  Snapshot snapshot,
1042  TupleTableSlot *slot)
1043 {
1044  return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot);
1045 }
1046 
1047 /*
1048  * Verify that `tid` is a potentially valid tuple identifier. That doesn't
1049  * mean that the pointed to row needs to exist or be visible, but that
1050  * attempting to fetch the row (e.g. with table_get_latest_tid() or
1051  * table_fetch_row_version()) should not error out if called with that tid.
1052  *
1053  * `scan` needs to have been started via table_beginscan().
1054  */
1055 static inline bool
1057 {
1058  return scan->rs_rd->rd_tableam->tuple_tid_valid(scan, tid);
1059 }
1060 
1061 /*
1062  * Return the latest version of the tuple at `tid`, by updating `tid` to
1063  * point at the newest version.
1064  */
1066 
1067 /*
1068  * Return true iff tuple in slot satisfies the snapshot.
1069  *
1070  * This assumes the slot's tuple is valid, and of the appropriate type for the
1071  * AM.
1072  *
1073  * Some AMs might modify the data underlying the tuple as a side-effect. If so
1074  * they ought to mark the relevant buffer dirty.
1075  */
1076 static inline bool
1078  Snapshot snapshot)
1079 {
1080  return rel->rd_tableam->tuple_satisfies_snapshot(rel, slot, snapshot);
1081 }
1082 
1083 /*
1084  * Compute the newest xid among the tuples pointed to by items. This is used
1085  * to compute what snapshots to conflict with when replaying WAL records for
1086  * page-level index vacuums.
1087  */
1088 static inline TransactionId
1090  ItemPointerData *items,
1091  int nitems)
1092 {
1093  return rel->rd_tableam->compute_xid_horizon_for_tuples(rel, items, nitems);
1094 }
1095 
1096 
1097 /* ----------------------------------------------------------------------------
1098  * Functions for manipulations of physical tuples.
1099  * ----------------------------------------------------------------------------
1100  */
1101 
1102 /*
1103  * Insert a tuple from a slot into table AM routine.
1104  *
1105  * The options bitmask allows the caller to specify options that may change the
1106  * behaviour of the AM. The AM will ignore options that it does not support.
1107  *
1108  * If the TABLE_INSERT_SKIP_WAL option is specified, the new tuple doesn't
1109  * need to be logged to WAL, even for a non-temp relation. It is the AMs
1110  * choice whether this optimization is supported.
1111  *
1112  * If the TABLE_INSERT_SKIP_FSM option is specified, AMs are free to not reuse
1113  * free space in the relation. This can save some cycles when we know the
1114  * relation is new and doesn't contain useful amounts of free space.
1115  * TABLE_INSERT_SKIP_FSM is commonly passed directly to
1116  * RelationGetBufferForTuple. See that method for more information.
1117  *
1118  * TABLE_INSERT_FROZEN should only be specified for inserts into
1119  * relfilenodes created during the current subtransaction and when
1120  * there are no prior snapshots or pre-existing portals open.
1121  * This causes rows to be frozen, which is an MVCC violation and
1122  * requires explicit options chosen by user.
1123  *
1124  * TABLE_INSERT_NO_LOGICAL force-disables the emitting of logical decoding
1125  * information for the tuple. This should solely be used during table rewrites
1126  * where RelationIsLogicallyLogged(relation) is not yet accurate for the new
1127  * relation.
1128  *
1129  * Note that most of these options will be applied when inserting into the
1130  * heap's TOAST table, too, if the tuple requires any out-of-line data.
1131  *
1132  * The BulkInsertState object (if any; bistate can be NULL for default
1133  * behavior) is also just passed through to RelationGetBufferForTuple. If
1134  * `bistate` is provided, table_finish_bulk_insert() needs to be called.
1135  *
1136  * On return the slot's tts_tid and tts_tableOid are updated to reflect the
1137  * insertion. But note that any toasting of fields within the slot is NOT
1138  * reflected in the slots contents.
1139  */
1140 static inline void
1142  int options, struct BulkInsertStateData *bistate)
1143 {
1144  rel->rd_tableam->tuple_insert(rel, slot, cid, options,
1145  bistate);
1146 }
1147 
1148 /*
1149  * Perform a "speculative insertion". These can be backed out afterwards
1150  * without aborting the whole transaction. Other sessions can wait for the
1151  * speculative insertion to be confirmed, turning it into a regular tuple, or
1152  * aborted, as if it never existed. Speculatively inserted tuples behave as
1153  * "value locks" of short duration, used to implement INSERT .. ON CONFLICT.
1154  *
1155  * A transaction having performed a speculative insertion has to either abort,
1156  * or finish the speculative insertion with
1157  * table_tuple_complete_speculative(succeeded = ...).
1158  */
1159 static inline void
1161  CommandId cid, int options,
1162  struct BulkInsertStateData *bistate,
1163  uint32 specToken)
1164 {
1165  rel->rd_tableam->tuple_insert_speculative(rel, slot, cid, options,
1166  bistate, specToken);
1167 }
1168 
1169 /*
1170  * Complete "speculative insertion" started in the same transaction. If
1171  * succeeded is true, the tuple is fully inserted, if false, it's removed.
1172  */
1173 static inline void
1175  uint32 specToken, bool succeeded)
1176 {
1177  rel->rd_tableam->tuple_complete_speculative(rel, slot, specToken,
1178  succeeded);
1179 }
1180 
1181 /*
1182  * Insert multiple tuples into a table.
1183  *
1184  * This is like table_insert(), but inserts multiple tuples in one
1185  * operation. That's often faster than calling table_insert() in a loop,
1186  * because e.g. the AM can reduce WAL logging and page locking overhead.
1187  *
1188  * Except for taking `nslots` tuples as input, as an array of TupleTableSlots
1189  * in `slots`, the parameters for table_multi_insert() are the same as for
1190  * table_tuple_insert().
1191  *
1192  * Note: this leaks memory into the current memory context. You can create a
1193  * temporary context before calling this, if that's a problem.
1194  */
1195 static inline void
1196 table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots,
1197  CommandId cid, int options, struct BulkInsertStateData *bistate)
1198 {
1199  rel->rd_tableam->multi_insert(rel, slots, nslots,
1200  cid, options, bistate);
1201 }
1202 
1203 /*
1204  * Delete a tuple.
1205  *
1206  * NB: do not call this directly unless prepared to deal with
1207  * concurrent-update conditions. Use simple_table_tuple_delete instead.
1208  *
1209  * Input parameters:
1210  * relation - table to be modified (caller must hold suitable lock)
1211  * tid - TID of tuple to be deleted
1212  * cid - delete command ID (used for visibility test, and stored into
1213  * cmax if successful)
1214  * crosscheck - if not InvalidSnapshot, also check tuple against this
1215  * wait - true if should wait for any conflicting update to commit/abort
1216  * Output parameters:
1217  * tmfd - filled in failure cases (see below)
1218  * changingPart - true iff the tuple is being moved to another partition
1219  * table due to an update of the partition key. Otherwise, false.
1220  *
1221  * Normal, successful return value is TM_Ok, which means we did actually
1222  * delete it. Failure return codes are TM_SelfModified, TM_Updated, and
1223  * TM_BeingModified (the last only possible if wait == false).
1224  *
1225  * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1226  * t_xmax, and, if possible, and, if possible, t_cmax. See comments for
1227  * struct TM_FailureData for additional info.
1228  */
1229 static inline TM_Result
1231  Snapshot snapshot, Snapshot crosscheck, bool wait,
1232  TM_FailureData *tmfd, bool changingPart)
1233 {
1234  return rel->rd_tableam->tuple_delete(rel, tid, cid,
1235  snapshot, crosscheck,
1236  wait, tmfd, changingPart);
1237 }
1238 
1239 /*
1240  * Update a tuple.
1241  *
1242  * NB: do not call this directly unless you are prepared to deal with
1243  * concurrent-update conditions. Use simple_table_tuple_update instead.
1244  *
1245  * Input parameters:
1246  * relation - table to be modified (caller must hold suitable lock)
1247  * otid - TID of old tuple to be replaced
1248  * slot - newly constructed tuple data to store
1249  * cid - update command ID (used for visibility test, and stored into
1250  * cmax/cmin if successful)
1251  * crosscheck - if not InvalidSnapshot, also check old tuple against this
1252  * wait - true if should wait for any conflicting update to commit/abort
1253  * Output parameters:
1254  * tmfd - filled in failure cases (see below)
1255  * lockmode - filled with lock mode acquired on tuple
1256  * update_indexes - in success cases this is set to true if new index entries
1257  * are required for this tuple
1258  *
1259  * Normal, successful return value is TM_Ok, which means we did actually
1260  * update it. Failure return codes are TM_SelfModified, TM_Updated, and
1261  * TM_BeingModified (the last only possible if wait == false).
1262  *
1263  * On success, the slot's tts_tid and tts_tableOid are updated to match the new
1264  * stored tuple; in particular, slot->tts_tid is set to the TID where the
1265  * new tuple was inserted, and its HEAP_ONLY_TUPLE flag is set iff a HOT
1266  * update was done. However, any TOAST changes in the new tuple's
1267  * data are not reflected into *newtup.
1268  *
1269  * In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
1270  * t_xmax, and, if possible, t_cmax. See comments for struct TM_FailureData
1271  * for additional info.
1272  */
1273 static inline TM_Result
1275  CommandId cid, Snapshot snapshot, Snapshot crosscheck,
1276  bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
1277  bool *update_indexes)
1278 {
1279  return rel->rd_tableam->tuple_update(rel, otid, slot,
1280  cid, snapshot, crosscheck,
1281  wait, tmfd,
1282  lockmode, update_indexes);
1283 }
1284 
1285 /*
1286  * Lock a tuple in the specified mode.
1287  *
1288  * Input parameters:
1289  * relation: relation containing tuple (caller must hold suitable lock)
1290  * tid: TID of tuple to lock
1291  * snapshot: snapshot to use for visibility determinations
1292  * cid: current command ID (used for visibility test, and stored into
1293  * tuple's cmax if lock is successful)
1294  * mode: lock mode desired
1295  * wait_policy: what to do if tuple lock is not available
1296  * flags:
1297  * If TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS, follow the update chain to
1298  * also lock descendant tuples if lock modes don't conflict.
1299  * If TUPLE_LOCK_FLAG_FIND_LAST_VERSION, follow the update chain and lock
1300  * latest version.
1301  *
1302  * Output parameters:
1303  * *slot: contains the target tuple
1304  * *tmfd: filled in failure cases (see below)
1305  *
1306  * Function result may be:
1307  * TM_Ok: lock was successfully acquired
1308  * TM_Invisible: lock failed because tuple was never visible to us
1309  * TM_SelfModified: lock failed because tuple updated by self
1310  * TM_Updated: lock failed because tuple updated by other xact
1311  * TM_Deleted: lock failed because tuple deleted by other xact
1312  * TM_WouldBlock: lock couldn't be acquired and wait_policy is skip
1313  *
1314  * In the failure cases other than TM_Invisible and TM_Deleted, the routine
1315  * fills *tmfd with the tuple's t_ctid, t_xmax, and, if possible, t_cmax. See
1316  * comments for struct TM_FailureData for additional info.
1317  */
1318 static inline TM_Result
1321  LockWaitPolicy wait_policy, uint8 flags,
1322  TM_FailureData *tmfd)
1323 {
1324  return rel->rd_tableam->tuple_lock(rel, tid, snapshot, slot,
1325  cid, mode, wait_policy,
1326  flags, tmfd);
1327 }
1328 
1329 /*
1330  * Perform operations necessary to complete insertions made via
1331  * tuple_insert and multi_insert with a BulkInsertState specified. This
1332  * e.g. may e.g. used to flush the relation when inserting with
1333  * TABLE_INSERT_SKIP_WAL specified.
1334  */
1335 static inline void
1337 {
1338  /* optional callback */
1339  if (rel->rd_tableam && rel->rd_tableam->finish_bulk_insert)
1340  rel->rd_tableam->finish_bulk_insert(rel, options);
1341 }
1342 
1343 
1344 /* ------------------------------------------------------------------------
1345  * DDL related functionality.
1346  * ------------------------------------------------------------------------
1347  */
1348 
1349 /*
1350  * Create storage for `rel` in `newrnode`, with persistence set to
1351  * `persistence`.
1352  *
1353  * This is used both during relation creation and various DDL operations to
1354  * create a new relfilenode that can be filled from scratch. When creating
1355  * new storage for an existing relfilenode, this should be called before the
1356  * relcache entry has been updated.
1357  *
1358  * *freezeXid, *minmulti are set to the xid / multixact horizon for the table
1359  * that pg_class.{relfrozenxid, relminmxid} have to be set to.
1360  */
1361 static inline void
1363  const RelFileNode *newrnode,
1364  char persistence,
1365  TransactionId *freezeXid,
1366  MultiXactId *minmulti)
1367 {
1368  rel->rd_tableam->relation_set_new_filenode(rel, newrnode, persistence,
1369  freezeXid, minmulti);
1370 }
1371 
1372 /*
1373  * Remove all table contents from `rel`, in a non-transactional manner.
1374  * Non-transactional meaning that there's no need to support rollbacks. This
1375  * commonly only is used to perform truncations for relfilenodes created in the
1376  * current transaction.
1377  */
1378 static inline void
1380 {
1382 }
1383 
1384 /*
1385  * Copy data from `rel` into the new relfilenode `newrnode`. The new
1386  * relfilenode may not have storage associated before this function is
1387  * called. This is only supposed to be used for low level operations like
1388  * changing a relation's tablespace.
1389  */
1390 static inline void
1392 {
1393  rel->rd_tableam->relation_copy_data(rel, newrnode);
1394 }
1395 
1396 /*
1397  * Copy data from `OldTable` into `NewTable`, as part of a CLUSTER or VACUUM
1398  * FULL.
1399  *
1400  * Additional Input parameters:
1401  * - use_sort - if true, the table contents are sorted appropriate for
1402  * `OldIndex`; if false and OldIndex is not InvalidOid, the data is copied
1403  * in that index's order; if false and OldIndex is InvalidOid, no sorting is
1404  * performed
1405  * - OldIndex - see use_sort
1406  * - OldestXmin - computed by vacuum_set_xid_limits(), even when
1407  * not needed for the relation's AM
1408  * - *xid_cutoff - ditto
1409  * - *multi_cutoff - ditto
1410  *
1411  * Output parameters:
1412  * - *xid_cutoff - rel's new relfrozenxid value, may be invalid
1413  * - *multi_cutoff - rel's new relminmxid value, may be invalid
1414  * - *tups_vacuumed - stats, for logging, if appropriate for AM
1415  * - *tups_recently_dead - stats, for logging, if appropriate for AM
1416  */
1417 static inline void
1419  Relation OldIndex,
1420  bool use_sort,
1422  TransactionId *xid_cutoff,
1423  MultiXactId *multi_cutoff,
1424  double *num_tuples,
1425  double *tups_vacuumed,
1426  double *tups_recently_dead)
1427 {
1428  OldTable->rd_tableam->relation_copy_for_cluster(OldTable, NewTable, OldIndex,
1429  use_sort, OldestXmin,
1430  xid_cutoff, multi_cutoff,
1431  num_tuples, tups_vacuumed,
1432  tups_recently_dead);
1433 }
1434 
1435 /*
1436  * Perform VACUUM on the relation. The VACUUM can be triggered by a user or by
1437  * autovacuum. The specific actions performed by the AM will depend heavily on
1438  * the individual AM.
1439  *
1440  * On entry a transaction needs to already been established, and the
1441  * table is locked with a ShareUpdateExclusive lock.
1442  *
1443  * Note that neither VACUUM FULL (and CLUSTER), nor ANALYZE go through this
1444  * routine, even if (for ANALYZE) it is part of the same VACUUM command.
1445  */
1446 static inline void
1448  BufferAccessStrategy bstrategy)
1449 {
1450  rel->rd_tableam->relation_vacuum(rel, params, bstrategy);
1451 }
1452 
1453 /*
1454  * Prepare to analyze block `blockno` of `scan`. The scan needs to have been
1455  * started with table_beginscan_analyze(). Note that this routine might
1456  * acquire resources like locks that are held until
1457  * table_scan_analyze_next_tuple() returns false.
1458  *
1459  * Returns false if block is unsuitable for sampling, true otherwise.
1460  */
1461 static inline bool
1463  BufferAccessStrategy bstrategy)
1464 {
1465  return scan->rs_rd->rd_tableam->scan_analyze_next_block(scan, blockno,
1466  bstrategy);
1467 }
1468 
1469 /*
1470  * Iterate over tuples in the block selected with
1471  * table_scan_analyze_next_block() (which needs to have returned true, and
1472  * this routine may not have returned false for the same block before). If a
1473  * tuple that's suitable for sampling is found, true is returned and a tuple
1474  * is stored in `slot`.
1475  *
1476  * *liverows and *deadrows are incremented according to the encountered
1477  * tuples.
1478  */
1479 static inline bool
1481  double *liverows, double *deadrows,
1482  TupleTableSlot *slot)
1483 {
1484  return scan->rs_rd->rd_tableam->scan_analyze_next_tuple(scan, OldestXmin,
1485  liverows, deadrows,
1486  slot);
1487 }
1488 
1489 /*
1490  * table_index_build_scan - scan the table to find tuples to be indexed
1491  *
1492  * This is called back from an access-method-specific index build procedure
1493  * after the AM has done whatever setup it needs. The parent table relation
1494  * is scanned to find tuples that should be entered into the index. Each
1495  * such tuple is passed to the AM's callback routine, which does the right
1496  * things to add it to the new index. After we return, the AM's index
1497  * build procedure does whatever cleanup it needs.
1498  *
1499  * The total count of live tuples is returned. This is for updating pg_class
1500  * statistics. (It's annoying not to be able to do that here, but we want to
1501  * merge that update with others; see index_update_stats.) Note that the
1502  * index AM itself must keep track of the number of index tuples; we don't do
1503  * so here because the AM might reject some of the tuples for its own reasons,
1504  * such as being unable to store NULLs.
1505  *
1506  * If 'progress', the PROGRESS_SCAN_BLOCKS_TOTAL counter is updated when
1507  * starting the scan, and PROGRESS_SCAN_BLOCKS_DONE is updated as we go along.
1508  *
1509  * A side effect is to set indexInfo->ii_BrokenHotChain to true if we detect
1510  * any potentially broken HOT chains. Currently, we set this if there are any
1511  * RECENTLY_DEAD or DELETE_IN_PROGRESS entries in a HOT chain, without trying
1512  * very hard to detect whether they're really incompatible with the chain tip.
1513  * This only really makes sense for heap AM, it might need to be generalized
1514  * for other AMs later.
1515  */
1516 static inline double
1518  Relation index_rel,
1519  struct IndexInfo *index_info,
1520  bool allow_sync,
1521  bool progress,
1523  void *callback_state,
1524  TableScanDesc scan)
1525 {
1526  return table_rel->rd_tableam->index_build_range_scan(table_rel,
1527  index_rel,
1528  index_info,
1529  allow_sync,
1530  false,
1531  progress,
1532  0,
1534  callback,
1535  callback_state,
1536  scan);
1537 }
1538 
1539 /*
1540  * As table_index_build_scan(), except that instead of scanning the complete
1541  * table, only the given number of blocks are scanned. Scan to end-of-rel can
1542  * be signalled by passing InvalidBlockNumber as numblocks. Note that
1543  * restricting the range to scan cannot be done when requesting syncscan.
1544  *
1545  * When "anyvisible" mode is requested, all tuples visible to any transaction
1546  * are indexed and counted as live, including those inserted or deleted by
1547  * transactions that are still in progress.
1548  */
1549 static inline double
1551  Relation index_rel,
1552  struct IndexInfo *index_info,
1553  bool allow_sync,
1554  bool anyvisible,
1555  bool progress,
1556  BlockNumber start_blockno,
1557  BlockNumber numblocks,
1559  void *callback_state,
1560  TableScanDesc scan)
1561 {
1562  return table_rel->rd_tableam->index_build_range_scan(table_rel,
1563  index_rel,
1564  index_info,
1565  allow_sync,
1566  anyvisible,
1567  progress,
1568  start_blockno,
1569  numblocks,
1570  callback,
1571  callback_state,
1572  scan);
1573 }
1574 
1575 /*
1576  * table_index_validate_scan - second table scan for concurrent index build
1577  *
1578  * See validate_index() for an explanation.
1579  */
1580 static inline void
1582  Relation index_rel,
1583  struct IndexInfo *index_info,
1584  Snapshot snapshot,
1585  struct ValidateIndexState *state)
1586 {
1587  table_rel->rd_tableam->index_validate_scan(table_rel,
1588  index_rel,
1589  index_info,
1590  snapshot,
1591  state);
1592 }
1593 
1594 
1595 /* ----------------------------------------------------------------------------
1596  * Miscellaneous functionality
1597  * ----------------------------------------------------------------------------
1598  */
1599 
1600 /*
1601  * Return the current size of `rel` in bytes. If `forkNumber` is
1602  * InvalidForkNumber, return the relation's overall size, otherwise the size
1603  * for the indicated fork.
1604  *
1605  * Note that the overall size might not be the equivalent of the sum of sizes
1606  * for the individual forks for some AMs, e.g. because the AMs storage does
1607  * not neatly map onto the builtin types of forks.
1608  */
1609 static inline uint64
1611 {
1612  return rel->rd_tableam->relation_size(rel, forkNumber);
1613 }
1614 
1615 /*
1616  * table_relation_needs_toast_table - does this relation need a toast table?
1617  */
1618 static inline bool
1620 {
1621  return rel->rd_tableam->relation_needs_toast_table(rel);
1622 }
1623 
1624 /*
1625  * Return the OID of the AM that should be used to implement the TOAST table
1626  * for this relation.
1627  */
1628 static inline Oid
1630 {
1631  return rel->rd_tableam->relation_toast_am(rel);
1632 }
1633 
1634 /*
1635  * Fetch all or part of a TOAST value from a TOAST table.
1636  *
1637  * If this AM is never used to implement a TOAST table, then this callback
1638  * is not needed. But, if toasted values are ever stored in a table of this
1639  * type, then you will need this callback.
1640  *
1641  * toastrel is the relation in which the toasted value is stored.
1642  *
1643  * valueid identifes which toast value is to be fetched. For the heap,
1644  * this corresponds to the values stored in the chunk_id column.
1645  *
1646  * attrsize is the total size of the toast value to be fetched.
1647  *
1648  * sliceoffset is the offset within the toast value of the first byte that
1649  * should be fetched.
1650  *
1651  * slicelength is the number of bytes from the toast value that should be
1652  * fetched.
1653  *
1654  * result is caller-allocated space into which the fetched bytes should be
1655  * stored.
1656  */
1657 static inline void
1659  int32 attrsize, int32 sliceoffset,
1660  int32 slicelength, struct varlena *result)
1661 {
1662  toastrel->rd_tableam->relation_fetch_toast_slice(toastrel, valueid,
1663  attrsize,
1664  sliceoffset, slicelength,
1665  result);
1666 }
1667 
1668 
1669 /* ----------------------------------------------------------------------------
1670  * Planner related functionality
1671  * ----------------------------------------------------------------------------
1672  */
1673 
1674 /*
1675  * Estimate the current size of the relation, as an AM specific workhorse for
1676  * estimate_rel_size(). Look there for an explanation of the parameters.
1677  */
1678 static inline void
1680  BlockNumber *pages, double *tuples,
1681  double *allvisfrac)
1682 {
1683  rel->rd_tableam->relation_estimate_size(rel, attr_widths, pages, tuples,
1684  allvisfrac);
1685 }
1686 
1687 
1688 /* ----------------------------------------------------------------------------
1689  * Executor related functionality
1690  * ----------------------------------------------------------------------------
1691  */
1692 
1693 /*
1694  * Prepare to fetch / check / return tuples from `tbmres->blockno` as part of
1695  * a bitmap table scan. `scan` needs to have been started via
1696  * table_beginscan_bm(). Returns false if there are no tuples to be found on
1697  * the page, true otherwise.
1698  *
1699  * Note, this is an optionally implemented function, therefore should only be
1700  * used after verifying the presence (at plan time or such).
1701  */
1702 static inline bool
1704  struct TBMIterateResult *tbmres)
1705 {
1706  return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan,
1707  tbmres);
1708 }
1709 
1710 /*
1711  * Fetch the next tuple of a bitmap table scan into `slot` and return true if
1712  * a visible tuple was found, false otherwise.
1713  * table_scan_bitmap_next_block() needs to previously have selected a
1714  * block (i.e. returned true), and no previous
1715  * table_scan_bitmap_next_tuple() for the same block may have
1716  * returned false.
1717  */
1718 static inline bool
1720  struct TBMIterateResult *tbmres,
1721  TupleTableSlot *slot)
1722 {
1723  return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
1724  tbmres,
1725  slot);
1726 }
1727 
1728 /*
1729  * Prepare to fetch tuples from the next block in a sample scan. Returns false
1730  * if the sample scan is finished, true otherwise. `scan` needs to have been
1731  * started via table_beginscan_sampling().
1732  *
1733  * This will call the TsmRoutine's NextSampleBlock() callback if necessary
1734  * (i.e. NextSampleBlock is not NULL), or perform a sequential scan over the
1735  * underlying relation.
1736  */
1737 static inline bool
1739  struct SampleScanState *scanstate)
1740 {
1741  return scan->rs_rd->rd_tableam->scan_sample_next_block(scan, scanstate);
1742 }
1743 
1744 /*
1745  * Fetch the next sample tuple into `slot` and return true if a visible tuple
1746  * was found, false otherwise. table_scan_sample_next_block() needs to
1747  * previously have selected a block (i.e. returned true), and no previous
1748  * table_scan_sample_next_tuple() for the same block may have returned false.
1749  *
1750  * This will call the TsmRoutine's NextSampleTuple() callback.
1751  */
1752 static inline bool
1754  struct SampleScanState *scanstate,
1755  TupleTableSlot *slot)
1756 {
1757  return scan->rs_rd->rd_tableam->scan_sample_next_tuple(scan, scanstate,
1758  slot);
1759 }
1760 
1761 
1762 /* ----------------------------------------------------------------------------
1763  * Functions to make modifications a bit simpler.
1764  * ----------------------------------------------------------------------------
1765  */
1766 
1767 extern void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot);
1768 extern void simple_table_tuple_delete(Relation rel, ItemPointer tid,
1769  Snapshot snapshot);
1770 extern void simple_table_tuple_update(Relation rel, ItemPointer otid,
1771  TupleTableSlot *slot, Snapshot snapshot,
1772  bool *update_indexes);
1773 
1774 
1775 /* ----------------------------------------------------------------------------
1776  * Helper functions to implement parallel scans for block oriented AMs.
1777  * ----------------------------------------------------------------------------
1778  */
1779 
1782  ParallelTableScanDesc pscan);
1784  ParallelTableScanDesc pscan);
1789 
1790 
1791 /* ----------------------------------------------------------------------------
1792  * Helper functions to implement relation sizing for block oriented AMs.
1793  * ----------------------------------------------------------------------------
1794  */
1795 
1796 extern uint64 table_block_relation_size(Relation rel, ForkNumber forkNumber);
1798  int32 *attr_widths,
1799  BlockNumber *pages,
1800  double *tuples,
1801  double *allvisfrac,
1802  Size overhead_bytes_per_tuple,
1803  Size usable_bytes_per_page);
1804 
1805 /* ----------------------------------------------------------------------------
1806  * Functions in tableamapi.c
1807  * ----------------------------------------------------------------------------
1808  */
1809 
1810 extern const TableAmRoutine *GetTableAmRoutine(Oid amhandler);
1811 extern const TableAmRoutine *GetHeapamTableAmRoutine(void);
1812 extern bool check_default_table_access_method(char **newval, void **extra,
1813  GucSource source);
1814 
1815 #endif /* TABLEAM_H */
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:222
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:528
ItemPointerData ctid
Definition: tableam.h:123
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:1719
static void table_relation_estimate_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:1679
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:164
static void table_relation_copy_data(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:1391
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:388
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:228
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
Definition: tableam.c:141
uint32 TransactionId
Definition: c.h:514
Size table_block_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.c:374
Size table_block_parallelscan_estimate(Relation rel)
Definition: tableam.c:368
struct TableAmRoutine TableAmRoutine
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:267
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:273
void table_block_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.c:392
void(* scan_end)(TableScanDesc scan)
Definition: tableam.h:209
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:1658
char * default_table_access_method
Definition: tableam.c:34
CommandId cmax
Definition: tableam.h:125
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:357
static void table_relation_vacuum(Relation rel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:1447
static IndexFetchTableData * table_index_fetch_begin(Relation rel)
Definition: tableam.h:952
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:1336
static bool table_scan_sample_next_block(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:1738
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:317
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:890
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:344
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:858
static void table_tuple_complete_speculative(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:1174
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:407
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:1141
uint64 table_block_relation_size(Relation rel, ForkNumber forkNumber)
Definition: tableam.c:508
signed int int32
Definition: c.h:347
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:360
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:215
static bool table_scan_sample_next_tuple(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:1753
static TransactionId table_compute_xid_horizon_for_tuples(Relation rel, ItemPointerData *items, int nitems)
Definition: tableam.h:1089
bool table_index_fetch_tuple_check(Relation rel, ItemPointer tid, Snapshot snapshot, bool *all_dead)
Definition: tableam.c:201
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:355
static void table_relation_nontransactional_truncate(Relation rel)
Definition: tableam.h:1379
static bool table_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:1462
TransactionId xmax
Definition: tableam.h:124
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:368
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:1517
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:1319
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:320
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:199
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:374
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:1550
static uint64 table_relation_size(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:1610
TableScanDesc table_beginscan_parallel(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.c:161
ScanDirection
Definition: sdir.h:22
static TransactionId OldestXmin
Definition: vacuumlazy.c:299
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
Definition: tableam.c:126
unsigned int uint32
Definition: c.h:359
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:1196
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:250
ForkNumber
Definition: relpath.h:40
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:934
static bool table_tuple_fetch_row_version(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:1039
static char ** options
int progress
Definition: pgbench.c:234
TM_Result
Definition: tableam.h:68
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:1160
static bool table_index_fetch_tuple(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:999
const struct TableAmRoutine * rd_tableam
Definition: rel.h:146
static void table_rescan_set_params(TableScanDesc scan, struct ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:873
BlockNumber table_block_parallelscan_nextpage(Relation rel, ParallelBlockTableScanDesc pbscan)
Definition: tableam.c:450
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:1230
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:582
static void table_index_fetch_reset(struct IndexFetchTableData *scan)
Definition: tableam.h:962
TransactionId MultiXactId
Definition: c.h:524
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition: tableam.h:278
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:400
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:1077
static bool table_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:1480
Definition: regguts.h:298
Definition: tableam.h:74
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:339
const TableAmRoutine * GetHeapamTableAmRoutine(void)
size_t Size
Definition: c.h:467
#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:548
void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot)
Definition: tableam.c:261
static void table_relation_set_new_filenode(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:1362
Relation rs_rd
Definition: relscan.h:34
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:849
void simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot)
Definition: tableam.c:275
static Datum values[MAXATTR]
Definition: bootstrap.c:167
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:325
static void table_index_validate_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:1581
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:1703
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:1056
Definition: c.h:556
static bool table_relation_needs_toast_table(Relation rel)
Definition: tableam.h:1619
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:1629
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:1274
bool traversed
Definition: tableam.h:126
static void table_index_fetch_end(struct IndexFetchTableData *scan)
Definition: tableam.h:971
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:300
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
Definition: tableam.h:378
#define RelationGetRelid(relation)
Definition: rel.h:428
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:1418
LockWaitPolicy
Definition: lockoptions.h:36
void(* IndexBuildCallback)(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
Definition: tableam.h:143
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:309
static TableScanDesc table_beginscan_analyze(Relation rel)
Definition: tableam.h:838
struct TableScanDescData * TableScanDesc
Definition: relscan.h:49