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