PostgreSQL Source Code  git master
tableam.h File Reference
#include "access/relscan.h"
#include "access/sdir.h"
#include "access/xact.h"
#include "utils/guc.h"
#include "utils/rel.h"
#include "utils/snapshot.h"
Include dependency graph for tableam.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TM_FailureData
 
struct  TableAmRoutine
 

Macros

#define DEFAULT_TABLE_ACCESS_METHOD   "heap"
 
#define TABLE_INSERT_SKIP_FSM   0x0002
 
#define TABLE_INSERT_FROZEN   0x0004
 
#define TABLE_INSERT_NO_LOGICAL   0x0008
 
#define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS   (1 << 0)
 
#define TUPLE_LOCK_FLAG_FIND_LAST_VERSION   (1 << 1)
 

Typedefs

typedef enum ScanOptions ScanOptions
 
typedef enum TM_Result TM_Result
 
typedef struct TM_FailureData TM_FailureData
 
typedef void(* IndexBuildCallback) (Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
 
typedef struct TableAmRoutine TableAmRoutine
 

Enumerations

enum  ScanOptions {
  SO_TYPE_SEQSCAN = 1 << 0, SO_TYPE_BITMAPSCAN = 1 << 1, SO_TYPE_SAMPLESCAN = 1 << 2, SO_TYPE_TIDSCAN = 1 << 3,
  SO_TYPE_ANALYZE = 1 << 4, SO_ALLOW_STRAT = 1 << 5, SO_ALLOW_SYNC = 1 << 6, SO_ALLOW_PAGEMODE = 1 << 7,
  SO_TEMP_SNAPSHOT = 1 << 8
}
 
enum  TM_Result {
  TM_Ok, TM_Invisible, TM_SelfModified, TM_Updated,
  TM_Deleted, TM_BeingModified, TM_WouldBlock
}
 

Functions

const TupleTableSlotOpstable_slot_callbacks (Relation rel)
 
TupleTableSlottable_slot_create (Relation rel, List **reglist)
 
static TableScanDesc table_beginscan (Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
 
TableScanDesc table_beginscan_catalog (Relation rel, int nkeys, struct ScanKeyData *key)
 
static TableScanDesc table_beginscan_strat (Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
 
static TableScanDesc table_beginscan_bm (Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
 
static TableScanDesc table_beginscan_sampling (Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
 
static TableScanDesc table_beginscan_tid (Relation rel, Snapshot snapshot)
 
static TableScanDesc table_beginscan_analyze (Relation rel)
 
static void table_endscan (TableScanDesc scan)
 
static void table_rescan (TableScanDesc scan, struct ScanKeyData *key)
 
static void table_rescan_set_params (TableScanDesc scan, struct ScanKeyData *key, bool allow_strat, bool allow_sync, bool allow_pagemode)
 
void table_scan_update_snapshot (TableScanDesc scan, Snapshot snapshot)
 
static bool table_scan_getnextslot (TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
 
Size table_parallelscan_estimate (Relation rel, Snapshot snapshot)
 
void table_parallelscan_initialize (Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
 
TableScanDesc table_beginscan_parallel (Relation rel, ParallelTableScanDesc pscan)
 
static void table_parallelscan_reinitialize (Relation rel, ParallelTableScanDesc pscan)
 
static IndexFetchTableDatatable_index_fetch_begin (Relation rel)
 
static void table_index_fetch_reset (struct IndexFetchTableData *scan)
 
static void table_index_fetch_end (struct IndexFetchTableData *scan)
 
static bool table_index_fetch_tuple (struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
 
bool table_index_fetch_tuple_check (Relation rel, ItemPointer tid, Snapshot snapshot, bool *all_dead)
 
static bool table_tuple_fetch_row_version (Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
 
static bool table_tuple_tid_valid (TableScanDesc scan, ItemPointer tid)
 
void table_tuple_get_latest_tid (TableScanDesc scan, ItemPointer tid)
 
static bool table_tuple_satisfies_snapshot (Relation rel, TupleTableSlot *slot, Snapshot snapshot)
 
static TransactionId table_compute_xid_horizon_for_tuples (Relation rel, ItemPointerData *items, int nitems)
 
static void table_tuple_insert (Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
 
static void table_tuple_insert_speculative (Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
 
static void table_tuple_complete_speculative (Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
 
static void table_multi_insert (Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
 
static TM_Result table_tuple_delete (Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
 
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)
 
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)
 
static void table_finish_bulk_insert (Relation rel, int options)
 
static void table_relation_set_new_filenode (Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
 
static void table_relation_nontransactional_truncate (Relation rel)
 
static void table_relation_copy_data (Relation rel, const RelFileNode *newrnode)
 
static void table_relation_copy_for_cluster (Relation OldTable, Relation NewTable, Relation OldIndex, bool use_sort, TransactionId OldestXmin, TransactionId *xid_cutoff, MultiXactId *multi_cutoff, double *num_tuples, double *tups_vacuumed, double *tups_recently_dead)
 
static void table_relation_vacuum (Relation rel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
 
static bool table_scan_analyze_next_block (TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
 
static bool table_scan_analyze_next_tuple (TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
 
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)
 
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)
 
static void table_index_validate_scan (Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
 
static uint64 table_relation_size (Relation rel, ForkNumber forkNumber)
 
static bool table_relation_needs_toast_table (Relation rel)
 
static Oid table_relation_toast_am (Relation rel)
 
static void table_relation_fetch_toast_slice (Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
 
static void table_relation_estimate_size (Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
 
static bool table_scan_bitmap_next_block (TableScanDesc scan, struct TBMIterateResult *tbmres)
 
static bool table_scan_bitmap_next_tuple (TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
 
static bool table_scan_sample_next_block (TableScanDesc scan, struct SampleScanState *scanstate)
 
static bool table_scan_sample_next_tuple (TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
 
void simple_table_tuple_insert (Relation rel, TupleTableSlot *slot)
 
void simple_table_tuple_delete (Relation rel, ItemPointer tid, Snapshot snapshot)
 
void simple_table_tuple_update (Relation rel, ItemPointer otid, TupleTableSlot *slot, Snapshot snapshot, bool *update_indexes)
 
Size table_block_parallelscan_estimate (Relation rel)
 
Size table_block_parallelscan_initialize (Relation rel, ParallelTableScanDesc pscan)
 
void table_block_parallelscan_reinitialize (Relation rel, ParallelTableScanDesc pscan)
 
BlockNumber table_block_parallelscan_nextpage (Relation rel, ParallelBlockTableScanWorker pbscanwork, ParallelBlockTableScanDesc pbscan)
 
void table_block_parallelscan_startblock_init (Relation rel, ParallelBlockTableScanWorker pbscanwork, ParallelBlockTableScanDesc pbscan)
 
uint64 table_block_relation_size (Relation rel, ForkNumber forkNumber)
 
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)
 
const TableAmRoutineGetTableAmRoutine (Oid amhandler)
 
const TableAmRoutineGetHeapamTableAmRoutine (void)
 
bool check_default_table_access_method (char **newval, void **extra, GucSource source)
 

Variables

char * default_table_access_method
 
bool synchronize_seqscans
 

Macro Definition Documentation

◆ DEFAULT_TABLE_ACCESS_METHOD

#define DEFAULT_TABLE_ACCESS_METHOD   "heap"

Definition at line 28 of file tableam.h.

◆ TABLE_INSERT_FROZEN

#define TABLE_INSERT_FROZEN   0x0004

Definition at line 134 of file tableam.h.

Referenced by CopyFrom(), and transientrel_startup().

◆ TABLE_INSERT_NO_LOGICAL

#define TABLE_INSERT_NO_LOGICAL   0x0008

Definition at line 135 of file tableam.h.

◆ TABLE_INSERT_SKIP_FSM

#define TABLE_INSERT_SKIP_FSM   0x0002

Definition at line 133 of file tableam.h.

Referenced by ATRewriteTable(), CopyFrom(), intorel_startup(), and transientrel_startup().

◆ TUPLE_LOCK_FLAG_FIND_LAST_VERSION

#define TUPLE_LOCK_FLAG_FIND_LAST_VERSION   (1 << 1)

◆ TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS

#define TUPLE_LOCK_FLAG_LOCK_UPDATE_IN_PROGRESS   (1 << 0)

Definition at line 139 of file tableam.h.

Referenced by ExecLockRows(), and heapam_tuple_lock().

Typedef Documentation

◆ IndexBuildCallback

typedef void(* IndexBuildCallback) (Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)

Definition at line 145 of file tableam.h.

◆ ScanOptions

typedef enum ScanOptions ScanOptions

◆ TableAmRoutine

◆ TM_FailureData

◆ TM_Result

typedef enum TM_Result TM_Result

Enumeration Type Documentation

◆ ScanOptions

Enumerator
SO_TYPE_SEQSCAN 
SO_TYPE_BITMAPSCAN 
SO_TYPE_SAMPLESCAN 
SO_TYPE_TIDSCAN 
SO_TYPE_ANALYZE 
SO_ALLOW_STRAT 
SO_ALLOW_SYNC 
SO_ALLOW_PAGEMODE 
SO_TEMP_SNAPSHOT 

Definition at line 45 of file tableam.h.

46 {
47  /* one of SO_TYPE_* may be specified */
48  SO_TYPE_SEQSCAN = 1 << 0,
49  SO_TYPE_BITMAPSCAN = 1 << 1,
50  SO_TYPE_SAMPLESCAN = 1 << 2,
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? */
60  SO_ALLOW_PAGEMODE = 1 << 7,
61 
62  /* unregister snapshot at scan end? */
63  SO_TEMP_SNAPSHOT = 1 << 8
64 } ScanOptions;
ScanOptions
Definition: tableam.h:45

◆ TM_Result

enum TM_Result
Enumerator
TM_Ok 
TM_Invisible 
TM_SelfModified 
TM_Updated 
TM_Deleted 
TM_BeingModified 
TM_WouldBlock 

Definition at line 70 of file tableam.h.

71 {
72  /*
73  * Signals that the action succeeded (i.e. update/delete performed, lock
74  * was acquired)
75  */
76  TM_Ok,
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  */
88  TM_Updated,
89 
90  /* The affected tuple was deleted by another transaction */
91  TM_Deleted,
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;
TM_Result
Definition: tableam.h:70
Definition: tableam.h:76

Function Documentation

◆ check_default_table_access_method()

bool check_default_table_access_method ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 111 of file tableamapi.c.

References ereport, errcode(), errmsg(), get_table_am_oid(), GUC_check_errdetail, InvalidOid, IsTransactionState(), MyDatabaseId, NAMEDATALEN, NOTICE, OidIsValid, and PGC_S_TEST.

Referenced by table_scan_sample_next_tuple().

112 {
113  if (**newval == '\0')
114  {
115  GUC_check_errdetail("%s cannot be empty.",
116  "default_table_access_method");
117  return false;
118  }
119 
120  if (strlen(*newval) >= NAMEDATALEN)
121  {
122  GUC_check_errdetail("%s is too long (maximum %d characters).",
123  "default_table_access_method", NAMEDATALEN - 1);
124  return false;
125  }
126 
127  /*
128  * If we aren't inside a transaction, or not connected to a database, we
129  * cannot do the catalog access necessary to verify the method. Must
130  * accept the value on faith.
131  */
133  {
134  if (!OidIsValid(get_table_am_oid(*newval, true)))
135  {
136  /*
137  * When source == PGC_S_TEST, don't throw a hard error for a
138  * nonexistent table access method, only a NOTICE. See comments in
139  * guc.h.
140  */
141  if (source == PGC_S_TEST)
142  {
143  ereport(NOTICE,
144  (errcode(ERRCODE_UNDEFINED_OBJECT),
145  errmsg("table access method \"%s\" does not exist",
146  *newval)));
147  }
148  else
149  {
150  GUC_check_errdetail("Table access method \"%s\" does not exist.",
151  *newval);
152  return false;
153  }
154  }
155  }
156 
157  return true;
158 }
#define GUC_check_errdetail
Definition: guc.h:415
int errcode(int sqlerrcode)
Definition: elog.c:610
#define OidIsValid(objectId)
Definition: c.h:651
#define NAMEDATALEN
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define NOTICE
Definition: elog.h:37
Oid get_table_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:173
#define newval
bool IsTransactionState(void)
Definition: xact.c:371
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ GetHeapamTableAmRoutine()

const TableAmRoutine* GetHeapamTableAmRoutine ( void  )

Definition at line 2567 of file heapam_handler.c.

References heapam_methods.

Referenced by formrdesc(), heap_getnext(), and table_scan_sample_next_tuple().

2568 {
2569  return &heapam_methods;
2570 }
static const TableAmRoutine heapam_methods

◆ GetTableAmRoutine()

const TableAmRoutine* GetTableAmRoutine ( Oid  amhandler)

Definition at line 34 of file tableamapi.c.

References Assert, TableAmRoutine::compute_xid_horizon_for_tuples, DatumGetPointer, elog, ERROR, TableAmRoutine::index_build_range_scan, TableAmRoutine::index_fetch_begin, TableAmRoutine::index_fetch_end, TableAmRoutine::index_fetch_reset, TableAmRoutine::index_fetch_tuple, TableAmRoutine::index_validate_scan, IsA, TableAmRoutine::multi_insert, OidFunctionCall0, TableAmRoutine::parallelscan_estimate, TableAmRoutine::parallelscan_initialize, TableAmRoutine::parallelscan_reinitialize, TableAmRoutine::relation_copy_data, TableAmRoutine::relation_copy_for_cluster, TableAmRoutine::relation_estimate_size, TableAmRoutine::relation_needs_toast_table, TableAmRoutine::relation_nontransactional_truncate, TableAmRoutine::relation_set_new_filenode, TableAmRoutine::relation_size, TableAmRoutine::relation_vacuum, TableAmRoutine::scan_analyze_next_block, TableAmRoutine::scan_analyze_next_tuple, TableAmRoutine::scan_begin, TableAmRoutine::scan_bitmap_next_block, TableAmRoutine::scan_bitmap_next_tuple, TableAmRoutine::scan_end, TableAmRoutine::scan_getnextslot, TableAmRoutine::scan_rescan, TableAmRoutine::scan_sample_next_block, TableAmRoutine::scan_sample_next_tuple, TableAmRoutine::tuple_complete_speculative, TableAmRoutine::tuple_delete, TableAmRoutine::tuple_fetch_row_version, TableAmRoutine::tuple_get_latest_tid, TableAmRoutine::tuple_insert, TableAmRoutine::tuple_insert_speculative, TableAmRoutine::tuple_lock, TableAmRoutine::tuple_satisfies_snapshot, TableAmRoutine::tuple_tid_valid, and TableAmRoutine::tuple_update.

Referenced by InitTableAmRoutine(), and table_scan_sample_next_tuple().

35 {
36  Datum datum;
37  const TableAmRoutine *routine;
38 
39  datum = OidFunctionCall0(amhandler);
40  routine = (TableAmRoutine *) DatumGetPointer(datum);
41 
42  if (routine == NULL || !IsA(routine, TableAmRoutine))
43  elog(ERROR, "table access method handler %u did not return a TableAmRoutine struct",
44  amhandler);
45 
46  /*
47  * Assert that all required callbacks are present. That makes it a bit
48  * easier to keep AMs up to date, e.g. when forward porting them to a new
49  * major version.
50  */
51  Assert(routine->scan_begin != NULL);
52  Assert(routine->scan_end != NULL);
53  Assert(routine->scan_rescan != NULL);
54  Assert(routine->scan_getnextslot != NULL);
55 
56  Assert(routine->parallelscan_estimate != NULL);
57  Assert(routine->parallelscan_initialize != NULL);
58  Assert(routine->parallelscan_reinitialize != NULL);
59 
60  Assert(routine->index_fetch_begin != NULL);
61  Assert(routine->index_fetch_reset != NULL);
62  Assert(routine->index_fetch_end != NULL);
63  Assert(routine->index_fetch_tuple != NULL);
64 
65  Assert(routine->tuple_fetch_row_version != NULL);
66  Assert(routine->tuple_tid_valid != NULL);
67  Assert(routine->tuple_get_latest_tid != NULL);
68  Assert(routine->tuple_satisfies_snapshot != NULL);
69  Assert(routine->compute_xid_horizon_for_tuples != NULL);
70 
71  Assert(routine->tuple_insert != NULL);
72 
73  /*
74  * Could be made optional, but would require throwing error during
75  * parse-analysis.
76  */
77  Assert(routine->tuple_insert_speculative != NULL);
78  Assert(routine->tuple_complete_speculative != NULL);
79 
80  Assert(routine->multi_insert != NULL);
81  Assert(routine->tuple_delete != NULL);
82  Assert(routine->tuple_update != NULL);
83  Assert(routine->tuple_lock != NULL);
84 
85  Assert(routine->relation_set_new_filenode != NULL);
87  Assert(routine->relation_copy_data != NULL);
88  Assert(routine->relation_copy_for_cluster != NULL);
89  Assert(routine->relation_vacuum != NULL);
90  Assert(routine->scan_analyze_next_block != NULL);
91  Assert(routine->scan_analyze_next_tuple != NULL);
92  Assert(routine->index_build_range_scan != NULL);
93  Assert(routine->index_validate_scan != NULL);
94 
95  Assert(routine->relation_size != NULL);
96  Assert(routine->relation_needs_toast_table != NULL);
97 
98  Assert(routine->relation_estimate_size != NULL);
99 
100  /* optional, but one callback implies presence of the other */
101  Assert((routine->scan_bitmap_next_block == NULL) ==
102  (routine->scan_bitmap_next_tuple == NULL));
103  Assert(routine->scan_sample_next_block != NULL);
104  Assert(routine->scan_sample_next_tuple != NULL);
105 
106  return routine;
107 }
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
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
Size(* parallelscan_estimate)(Relation rel)
Definition: tableam.h:238
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
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:269
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:275
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
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
void(* index_validate_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:553
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:319
void(* relation_nontransactional_truncate)(Relation rel)
Definition: tableam.h:462
TransactionId(* compute_xid_horizon_for_tuples)(Relation rel, ItemPointerData *items, int nitems)
Definition: tableam.h:346
bool(* scan_analyze_next_block)(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:521
Size(* parallelscan_initialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:245
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:362
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:217
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:357
#define ERROR
Definition: elog.h:43
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:370
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
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
void(* relation_copy_data)(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:470
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:252
uintptr_t Datum
Definition: postgres.h:367
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:583
#define OidFunctionCall0(functionId)
Definition: fmgr.h:660
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
#define Assert(condition)
Definition: c.h:745
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:334
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:341
bool(* scan_sample_next_tuple)(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:719
#define DatumGetPointer(X)
Definition: postgres.h:549
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:327
#define elog(elevel,...)
Definition: elog.h:214
void(* relation_vacuum)(Relation onerel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:500
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

◆ simple_table_tuple_delete()

void simple_table_tuple_delete ( Relation  rel,
ItemPointer  tid,
Snapshot  snapshot 
)

Definition at line 301 of file tableam.c.

References elog, ERROR, GetCurrentCommandId(), InvalidSnapshot, table_tuple_delete(), TM_Deleted, TM_Ok, TM_SelfModified, and TM_Updated.

Referenced by ExecSimpleRelationDelete(), and table_scan_sample_next_tuple().

302 {
303  TM_Result result;
304  TM_FailureData tmfd;
305 
306  result = table_tuple_delete(rel, tid,
307  GetCurrentCommandId(true),
308  snapshot, InvalidSnapshot,
309  true /* wait for commit */ ,
310  &tmfd, false /* changingPart */ );
311 
312  switch (result)
313  {
314  case TM_SelfModified:
315  /* Tuple was already updated in current command? */
316  elog(ERROR, "tuple already updated by self");
317  break;
318 
319  case TM_Ok:
320  /* done successfully */
321  break;
322 
323  case TM_Updated:
324  elog(ERROR, "tuple concurrently updated");
325  break;
326 
327  case TM_Deleted:
328  elog(ERROR, "tuple concurrently deleted");
329  break;
330 
331  default:
332  elog(ERROR, "unrecognized table_tuple_delete status: %u", result);
333  break;
334  }
335 }
#define ERROR
Definition: elog.h:43
#define InvalidSnapshot
Definition: snapshot.h:123
TM_Result
Definition: tableam.h:70
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
Definition: tableam.h:76
#define elog(elevel,...)
Definition: elog.h:214
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:761

◆ simple_table_tuple_insert()

void simple_table_tuple_insert ( Relation  rel,
TupleTableSlot slot 
)

Definition at line 287 of file tableam.c.

References GetCurrentCommandId(), and table_tuple_insert().

Referenced by ExecSimpleRelationInsert(), and table_scan_sample_next_tuple().

288 {
289  table_tuple_insert(rel, slot, GetCurrentCommandId(true), 0, NULL);
290 }
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:1178
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:761

◆ simple_table_tuple_update()

void simple_table_tuple_update ( Relation  rel,
ItemPointer  otid,
TupleTableSlot slot,
Snapshot  snapshot,
bool update_indexes 
)

Definition at line 346 of file tableam.c.

References elog, ERROR, GetCurrentCommandId(), InvalidSnapshot, table_tuple_update(), TM_Deleted, TM_Ok, TM_SelfModified, and TM_Updated.

Referenced by ExecSimpleRelationUpdate(), and table_scan_sample_next_tuple().

350 {
351  TM_Result result;
352  TM_FailureData tmfd;
353  LockTupleMode lockmode;
354 
355  result = table_tuple_update(rel, otid, slot,
356  GetCurrentCommandId(true),
357  snapshot, InvalidSnapshot,
358  true /* wait for commit */ ,
359  &tmfd, &lockmode, update_indexes);
360 
361  switch (result)
362  {
363  case TM_SelfModified:
364  /* Tuple was already updated in current command? */
365  elog(ERROR, "tuple already updated by self");
366  break;
367 
368  case TM_Ok:
369  /* done successfully */
370  break;
371 
372  case TM_Updated:
373  elog(ERROR, "tuple concurrently updated");
374  break;
375 
376  case TM_Deleted:
377  elog(ERROR, "tuple concurrently deleted");
378  break;
379 
380  default:
381  elog(ERROR, "unrecognized table_tuple_update status: %u", result);
382  break;
383  }
384 
385 }
LockTupleMode
Definition: lockoptions.h:49
#define ERROR
Definition: elog.h:43
#define InvalidSnapshot
Definition: snapshot.h:123
TM_Result
Definition: tableam.h:70
Definition: tableam.h:76
#define elog(elevel,...)
Definition: elog.h:214
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:761
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

◆ table_beginscan()

static TableScanDesc table_beginscan ( Relation  rel,
Snapshot  snapshot,
int  nkeys,
struct ScanKeyData key 
)
inlinestatic

Definition at line 755 of file tableam.h.

References sort-test::key, RelationData::rd_tableam, TableAmRoutine::scan_begin, SO_ALLOW_PAGEMODE, SO_ALLOW_STRAT, SO_ALLOW_SYNC, SO_TYPE_SEQSCAN, and table_beginscan_catalog().

Referenced by AlterDomainNotNull(), ATRewriteTable(), check_default_partition_contents(), CopyTo(), DefineQueryRewrite(), heapam_relation_copy_for_cluster(), pgrowlocks(), pgstat_collect_oids(), RelationFindReplTupleSeq(), SeqNext(), validateDomainConstraint(), and validateForeignKeyConstraint().

757 {
758  uint32 flags = SO_TYPE_SEQSCAN |
760 
761  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
762 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:201
unsigned int uint32
Definition: c.h:374
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_beginscan_analyze()

static TableScanDesc table_beginscan_analyze ( Relation  rel)
inlinestatic

Definition at line 852 of file tableam.h.

References RelationData::rd_tableam, TableAmRoutine::scan_begin, and SO_TYPE_ANALYZE.

Referenced by acquire_sample_rows().

853 {
854  uint32 flags = SO_TYPE_ANALYZE;
855 
856  return rel->rd_tableam->scan_begin(rel, NULL, 0, NULL, NULL, flags);
857 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:201
unsigned int uint32
Definition: c.h:374
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_beginscan_bm()

static TableScanDesc table_beginscan_bm ( Relation  rel,
Snapshot  snapshot,
int  nkeys,
struct ScanKeyData key 
)
inlinestatic

Definition at line 800 of file tableam.h.

References RelationData::rd_tableam, TableAmRoutine::scan_begin, SO_ALLOW_PAGEMODE, and SO_TYPE_BITMAPSCAN.

Referenced by ExecInitBitmapHeapScan().

802 {
804 
805  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
806 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:201
unsigned int uint32
Definition: c.h:374
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_beginscan_catalog()

TableScanDesc table_beginscan_catalog ( Relation  rel,
int  nkeys,
struct ScanKeyData key 
)

Definition at line 112 of file tableam.c.

References GetCatalogSnapshot(), RelationData::rd_tableam, RegisterSnapshot(), RelationGetRelid, TableAmRoutine::scan_begin, SO_ALLOW_PAGEMODE, SO_ALLOW_STRAT, SO_ALLOW_SYNC, SO_TEMP_SNAPSHOT, and SO_TYPE_SEQSCAN.

Referenced by AlterTableMoveAll(), AlterTableSpaceOptions(), check_db_file_conflict(), createdb(), do_autovacuum(), DropSetting(), DropTableSpace(), find_typed_table_dependencies(), get_all_vacuum_rels(), get_database_list(), get_subscription_list(), get_tables_to_cluster(), get_tablespace_name(), get_tablespace_oid(), GetAllTablesPublicationRelations(), getRelationsInNamespace(), index_update_stats(), objectsInSchemaToOids(), populate_typ_array(), ReindexMultipleTables(), remove_dbtablespaces(), RemoveSubscriptionRel(), RenameTableSpace(), table_beginscan(), ThereIsAtLeastOneRole(), and vac_truncate_clog().

113 {
114  uint32 flags = SO_TYPE_SEQSCAN |
116  Oid relid = RelationGetRelid(relation);
117  Snapshot snapshot = RegisterSnapshot(GetCatalogSnapshot(relid));
118 
119  return relation->rd_tableam->scan_begin(relation, snapshot, nkeys, key,
120  NULL, flags);
121 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:386
unsigned int Oid
Definition: postgres_ext.h:31
unsigned int uint32
Definition: c.h:374
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ table_beginscan_parallel()

TableScanDesc table_beginscan_parallel ( Relation  rel,
ParallelTableScanDesc  pscan 
)

Definition at line 175 of file tableam.c.

References Assert, ParallelTableScanDescData::phs_relid, ParallelTableScanDescData::phs_snapshot_any, ParallelTableScanDescData::phs_snapshot_off, RelationData::rd_tableam, RegisterSnapshot(), RelationGetRelid, RestoreSnapshot(), TableAmRoutine::scan_begin, SnapshotAny, SO_ALLOW_PAGEMODE, SO_ALLOW_STRAT, SO_ALLOW_SYNC, SO_TEMP_SNAPSHOT, and SO_TYPE_SEQSCAN.

Referenced by _bt_parallel_scan_and_sort(), ExecSeqScanInitializeDSM(), ExecSeqScanInitializeWorker(), and table_scan_getnextslot().

176 {
177  Snapshot snapshot;
178  uint32 flags = SO_TYPE_SEQSCAN |
180 
181  Assert(RelationGetRelid(relation) == parallel_scan->phs_relid);
182 
183  if (!parallel_scan->phs_snapshot_any)
184  {
185  /* Snapshot was serialized -- restore it */
186  snapshot = RestoreSnapshot((char *) parallel_scan +
187  parallel_scan->phs_snapshot_off);
188  RegisterSnapshot(snapshot);
189  flags |= SO_TEMP_SNAPSHOT;
190  }
191  else
192  {
193  /* SnapshotAny passed by caller (not serialized) */
194  snapshot = SnapshotAny;
195  }
196 
197  return relation->rd_tableam->scan_begin(relation, snapshot, 0, NULL,
198  parallel_scan, flags);
199 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2157
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
unsigned int uint32
Definition: c.h:374
#define Assert(condition)
Definition: c.h:745
#define SnapshotAny
Definition: snapmgr.h:68
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ table_beginscan_sampling()

static TableScanDesc table_beginscan_sampling ( Relation  rel,
Snapshot  snapshot,
int  nkeys,
struct ScanKeyData key,
bool  allow_strat,
bool  allow_sync,
bool  allow_pagemode 
)
inlinestatic

Definition at line 816 of file tableam.h.

References RelationData::rd_tableam, TableAmRoutine::scan_begin, SO_ALLOW_PAGEMODE, SO_ALLOW_STRAT, SO_ALLOW_SYNC, and SO_TYPE_SAMPLESCAN.

Referenced by tablesample_init().

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 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:201
unsigned int uint32
Definition: c.h:374
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_beginscan_strat()

static TableScanDesc table_beginscan_strat ( Relation  rel,
Snapshot  snapshot,
int  nkeys,
struct ScanKeyData key,
bool  allow_strat,
bool  allow_sync 
)
inlinestatic

Definition at line 779 of file tableam.h.

References RelationData::rd_tableam, TableAmRoutine::scan_begin, SO_ALLOW_PAGEMODE, SO_ALLOW_STRAT, SO_ALLOW_SYNC, and SO_TYPE_SEQSCAN.

Referenced by bt_check_every_level(), heapam_index_build_range_scan(), heapam_index_validate_scan(), IndexCheckExclusion(), pgstat_heap(), and systable_beginscan().

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 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:201
unsigned int uint32
Definition: c.h:374
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_beginscan_tid()

static TableScanDesc table_beginscan_tid ( Relation  rel,
Snapshot  snapshot 
)
inlinestatic

Definition at line 839 of file tableam.h.

References RelationData::rd_tableam, TableAmRoutine::scan_begin, and SO_TYPE_TIDSCAN.

Referenced by currtid_byrelname(), currtid_byreloid(), and TidListEval().

840 {
841  uint32 flags = SO_TYPE_TIDSCAN;
842 
843  return rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
844 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:201
unsigned int uint32
Definition: c.h:374
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_block_parallelscan_estimate()

Size table_block_parallelscan_estimate ( Relation  rel)

Definition at line 394 of file tableam.c.

Referenced by SampleHeapTupleVisible(), and table_scan_sample_next_tuple().

395 {
396  return sizeof(ParallelBlockTableScanDescData);
397 }
struct ParallelBlockTableScanDescData ParallelBlockTableScanDescData

◆ table_block_parallelscan_initialize()

Size table_block_parallelscan_initialize ( Relation  rel,
ParallelTableScanDesc  pscan 
)

Definition at line 400 of file tableam.c.

References ParallelBlockTableScanDescData::base, InvalidBlockNumber, NBuffers, pg_atomic_init_u64(), ParallelBlockTableScanDescData::phs_mutex, ParallelBlockTableScanDescData::phs_nallocated, ParallelBlockTableScanDescData::phs_nblocks, ParallelTableScanDescData::phs_relid, ParallelBlockTableScanDescData::phs_startblock, ParallelTableScanDescData::phs_syncscan, RelationGetNumberOfBlocks, RelationGetRelid, RelationUsesLocalBuffers, SpinLockInit, and synchronize_seqscans.

Referenced by SampleHeapTupleVisible(), and table_scan_sample_next_tuple().

401 {
403 
404  bpscan->base.phs_relid = RelationGetRelid(rel);
405  bpscan->phs_nblocks = RelationGetNumberOfBlocks(rel);
406  /* compare phs_syncscan initialization to similar logic in initscan */
408  !RelationUsesLocalBuffers(rel) &&
409  bpscan->phs_nblocks > NBuffers / 4;
410  SpinLockInit(&bpscan->phs_mutex);
412  pg_atomic_init_u64(&bpscan->phs_nallocated, 0);
413 
414  return sizeof(ParallelBlockTableScanDescData);
415 }
pg_atomic_uint64 phs_nallocated
Definition: relscan.h:79
bool synchronize_seqscans
Definition: tableam.c:49
ParallelTableScanDescData base
Definition: relscan.h:74
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition: relscan.h:82
struct ParallelBlockTableScanDescData ParallelBlockTableScanDescData
#define SpinLockInit(lock)
Definition: spin.h:60
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:415
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:211
#define InvalidBlockNumber
Definition: block.h:33
#define RelationUsesLocalBuffers(relation)
Definition: rel.h:572
int NBuffers
Definition: globals.c:132
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ table_block_parallelscan_nextpage()

BlockNumber table_block_parallelscan_nextpage ( Relation  rel,
ParallelBlockTableScanWorker  pbscanwork,
ParallelBlockTableScanDesc  pbscan 
)

Definition at line 503 of file tableam.c.

References ParallelBlockTableScanDescData::base, InvalidBlockNumber, PARALLEL_SEQSCAN_RAMPDOWN_CHUNKS, pg_atomic_fetch_add_u64(), ParallelBlockTableScanDescData::phs_nallocated, ParallelBlockTableScanDescData::phs_nblocks, ParallelBlockTableScanDescData::phs_startblock, ParallelTableScanDescData::phs_syncscan, ParallelBlockTableScanWorkerData::phsw_chunk_remaining, ParallelBlockTableScanWorkerData::phsw_chunk_size, ParallelBlockTableScanWorkerData::phsw_nallocated, and ss_report_location().

Referenced by heapgettup(), heapgettup_pagemode(), and table_scan_sample_next_tuple().

506 {
507  BlockNumber page;
508  uint64 nallocated;
509 
510  /*
511  * The logic below allocates block numbers out to parallel workers in a
512  * way that each worker will receive a set of consecutive block numbers to
513  * scan. Earlier versions of this would allocate the next highest block
514  * number to the next worker to call this function. This would generally
515  * result in workers never receiving consecutive block numbers. Some
516  * operating systems would not detect the sequential I/O pattern due to
517  * each backend being a different process which could result in poor
518  * performance due to inefficient or no readahead. To work around this
519  * issue, we now allocate a range of block numbers for each worker and
520  * when they come back for another block, we give them the next one in
521  * that range until the range is complete. When the worker completes the
522  * range of blocks we then allocate another range for it and return the
523  * first block number from that range.
524  *
525  * Here we name these ranges of blocks "chunks". The initial size of
526  * these chunks is determined in table_block_parallelscan_startblock_init
527  * based on the size of the relation. Towards the end of the scan, we
528  * start making reductions in the size of the chunks in order to attempt
529  * to divide the remaining work over all the workers as evenly as
530  * possible.
531  *
532  * Here pbscanwork is local worker memory. phsw_chunk_remaining tracks
533  * the number of blocks remaining in the chunk. When that reaches 0 then
534  * we must allocate a new chunk for the worker.
535  *
536  * phs_nallocated tracks how many blocks have been allocated to workers
537  * already. When phs_nallocated >= rs_nblocks, all blocks have been
538  * allocated.
539  *
540  * Because we use an atomic fetch-and-add to fetch the current value, the
541  * phs_nallocated counter will exceed rs_nblocks, because workers will
542  * still increment the value, when they try to allocate the next block but
543  * all blocks have been allocated already. The counter must be 64 bits
544  * wide because of that, to avoid wrapping around when rs_nblocks is close
545  * to 2^32.
546  *
547  * The actual block to return is calculated by adding the counter to the
548  * starting block number, modulo nblocks.
549  */
550 
551  /*
552  * First check if we have any remaining blocks in a previous chunk for
553  * this worker. We must consume all of the blocks from that before we
554  * allocate a new chunk to the worker.
555  */
556  if (pbscanwork->phsw_chunk_remaining > 0)
557  {
558  /*
559  * Give them the next block in the range and update the remaining
560  * number of blocks.
561  */
562  nallocated = ++pbscanwork->phsw_nallocated;
563  pbscanwork->phsw_chunk_remaining--;
564  }
565  else
566  {
567  /*
568  * When we've only got PARALLEL_SEQSCAN_RAMPDOWN_CHUNKS chunks
569  * remaining in the scan, we half the chunk size. Since we reduce the
570  * chunk size here, we'll hit this again after doing
571  * PARALLEL_SEQSCAN_RAMPDOWN_CHUNKS at the new size. After a few
572  * iterations of this, we'll end up doing the last few blocks with the
573  * chunk size set to 1.
574  */
575  if (pbscanwork->phsw_chunk_size > 1 &&
576  pbscanwork->phsw_nallocated > pbscan->phs_nblocks -
578  pbscanwork->phsw_chunk_size >>= 1;
579 
580  nallocated = pbscanwork->phsw_nallocated =
582  pbscanwork->phsw_chunk_size);
583 
584  /*
585  * Set the remaining number of blocks in this chunk so that subsequent
586  * calls from this worker continue on with this chunk until it's done.
587  */
588  pbscanwork->phsw_chunk_remaining = pbscanwork->phsw_chunk_size - 1;
589  }
590 
591  if (nallocated >= pbscan->phs_nblocks)
592  page = InvalidBlockNumber; /* all blocks have been allocated */
593  else
594  page = (nallocated + pbscan->phs_startblock) % pbscan->phs_nblocks;
595 
596  /*
597  * Report scan location. Normally, we report the current page number.
598  * When we reach the end of the scan, though, we report the starting page,
599  * not the ending page, just so the starting positions for later scans
600  * doesn't slew backwards. We only report the position at the end of the
601  * scan once, though: subsequent callers will report nothing.
602  */
603  if (pbscan->base.phs_syncscan)
604  {
605  if (page != InvalidBlockNumber)
606  ss_report_location(rel, page);
607  else if (nallocated == pbscan->phs_nblocks)
608  ss_report_location(rel, pbscan->phs_startblock);
609  }
610 
611  return page;
612 }
pg_atomic_uint64 phs_nallocated
Definition: relscan.h:79
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:467
ParallelTableScanDescData base
Definition: relscan.h:74
uint32 BlockNumber
Definition: block.h:31
#define PARALLEL_SEQSCAN_RAMPDOWN_CHUNKS
Definition: tableam.c:43
#define InvalidBlockNumber
Definition: block.h:33
void ss_report_location(Relation rel, BlockNumber location)
Definition: syncscan.c:288

◆ table_block_parallelscan_reinitialize()

void table_block_parallelscan_reinitialize ( Relation  rel,
ParallelTableScanDesc  pscan 
)

Definition at line 418 of file tableam.c.

References pg_atomic_write_u64(), and ParallelBlockTableScanDescData::phs_nallocated.

Referenced by SampleHeapTupleVisible(), and table_scan_sample_next_tuple().

419 {
421 
422  pg_atomic_write_u64(&bpscan->phs_nallocated, 0);
423 }
pg_atomic_uint64 phs_nallocated
Definition: relscan.h:79
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition: relscan.h:82
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:438

◆ table_block_parallelscan_startblock_init()

void table_block_parallelscan_startblock_init ( Relation  rel,
ParallelBlockTableScanWorker  pbscanwork,
ParallelBlockTableScanDesc  pbscan 
)

Definition at line 433 of file tableam.c.

References ParallelBlockTableScanDescData::base, InvalidBlockNumber, Max, MaxBlockNumber, Min, PARALLEL_SEQSCAN_MAX_CHUNK_SIZE, PARALLEL_SEQSCAN_NCHUNKS, pg_nextpower2_32(), ParallelBlockTableScanDescData::phs_mutex, ParallelBlockTableScanDescData::phs_nblocks, ParallelBlockTableScanDescData::phs_startblock, ParallelTableScanDescData::phs_syncscan, ParallelBlockTableScanWorkerData::phsw_chunk_size, SpinLockAcquire, SpinLockRelease, ss_get_location(), and StaticAssertStmt.

Referenced by heapgettup(), heapgettup_pagemode(), and table_scan_sample_next_tuple().

436 {
437  BlockNumber sync_startpage = InvalidBlockNumber;
438 
439  /* Reset the state we use for controlling allocation size. */
440  memset(pbscanwork, 0, sizeof(*pbscanwork));
441 
442  StaticAssertStmt(MaxBlockNumber <= 0xFFFFFFFE,
443  "pg_nextpower2_32 may be too small for non-standard BlockNumber width");
444 
445  /*
446  * We determine the chunk size based on the size of the relation. First we
447  * split the relation into PARALLEL_SEQSCAN_NCHUNKS chunks but we then
448  * take the next highest power of 2 number of the chunk size. This means
449  * we split the relation into somewhere between PARALLEL_SEQSCAN_NCHUNKS
450  * and PARALLEL_SEQSCAN_NCHUNKS / 2 chunks.
451  */
452  pbscanwork->phsw_chunk_size = pg_nextpower2_32(Max(pbscan->phs_nblocks /
454 
455  /*
456  * Ensure we don't go over the maximum chunk size with larger tables. This
457  * means we may get much more than PARALLEL_SEQSCAN_NCHUNKS for larger
458  * tables. Too large a chunk size has been shown to be detrimental to
459  * synchronous scan performance.
460  */
461  pbscanwork->phsw_chunk_size = Min(pbscanwork->phsw_chunk_size,
463 
464 retry:
465  /* Grab the spinlock. */
466  SpinLockAcquire(&pbscan->phs_mutex);
467 
468  /*
469  * If the scan's startblock has not yet been initialized, we must do so
470  * now. If this is not a synchronized scan, we just start at block 0, but
471  * if it is a synchronized scan, we must get the starting position from
472  * the synchronized scan machinery. We can't hold the spinlock while
473  * doing that, though, so release the spinlock, get the information we
474  * need, and retry. If nobody else has initialized the scan in the
475  * meantime, we'll fill in the value we fetched on the second time
476  * through.
477  */
478  if (pbscan->phs_startblock == InvalidBlockNumber)
479  {
480  if (!pbscan->base.phs_syncscan)
481  pbscan->phs_startblock = 0;
482  else if (sync_startpage != InvalidBlockNumber)
483  pbscan->phs_startblock = sync_startpage;
484  else
485  {
486  SpinLockRelease(&pbscan->phs_mutex);
487  sync_startpage = ss_get_location(rel, pbscan->phs_nblocks);
488  goto retry;
489  }
490  }
491  SpinLockRelease(&pbscan->phs_mutex);
492 }
ParallelTableScanDescData base
Definition: relscan.h:74
#define PARALLEL_SEQSCAN_MAX_CHUNK_SIZE
Definition: tableam.c:45
#define Min(x, y)
Definition: c.h:927
uint32 BlockNumber
Definition: block.h:31
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:859
#define SpinLockAcquire(lock)
Definition: spin.h:62
#define MaxBlockNumber
Definition: block.h:35
static uint32 pg_nextpower2_32(uint32 num)
Definition: pg_bitutils.h:146
BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks)
Definition: syncscan.c:253
#define SpinLockRelease(lock)
Definition: spin.h:64
#define PARALLEL_SEQSCAN_NCHUNKS
Definition: tableam.c:41
#define Max(x, y)
Definition: c.h:921
#define InvalidBlockNumber
Definition: block.h:33

◆ table_block_relation_estimate_size()

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 at line 668 of file tableam.c.

References get_rel_data_width(), RelationData::rd_rel, and RelationGetNumberOfBlocks.

Referenced by heapam_estimate_rel_size(), and table_scan_sample_next_tuple().

673 {
674  BlockNumber curpages;
675  BlockNumber relpages;
676  double reltuples;
677  BlockNumber relallvisible;
678  double density;
679 
680  /* it should have storage, so we can call the smgr */
681  curpages = RelationGetNumberOfBlocks(rel);
682 
683  /* coerce values in pg_class to more desirable types */
684  relpages = (BlockNumber) rel->rd_rel->relpages;
685  reltuples = (double) rel->rd_rel->reltuples;
686  relallvisible = (BlockNumber) rel->rd_rel->relallvisible;
687 
688  /*
689  * HACK: if the relation has never yet been vacuumed, use a minimum size
690  * estimate of 10 pages. The idea here is to avoid assuming a
691  * newly-created table is really small, even if it currently is, because
692  * that may not be true once some data gets loaded into it. Once a vacuum
693  * or analyze cycle has been done on it, it's more reasonable to believe
694  * the size is somewhat stable.
695  *
696  * (Note that this is only an issue if the plan gets cached and used again
697  * after the table has been filled. What we're trying to avoid is using a
698  * nestloop-type plan on a table that has grown substantially since the
699  * plan was made. Normally, autovacuum/autoanalyze will occur once enough
700  * inserts have happened and cause cached-plan invalidation; but that
701  * doesn't happen instantaneously, and it won't happen at all for cases
702  * such as temporary tables.)
703  *
704  * We test "never vacuumed" by seeing whether reltuples < 0.
705  *
706  * If the table has inheritance children, we don't apply this heuristic.
707  * Totally empty parent tables are quite common, so we should be willing
708  * to believe that they are empty.
709  */
710  if (curpages < 10 &&
711  reltuples < 0 &&
712  !rel->rd_rel->relhassubclass)
713  curpages = 10;
714 
715  /* report estimated # pages */
716  *pages = curpages;
717  /* quick exit if rel is clearly empty */
718  if (curpages == 0)
719  {
720  *tuples = 0;
721  *allvisfrac = 0;
722  return;
723  }
724 
725  /* estimate number of tuples from previous tuple density */
726  if (reltuples >= 0 && relpages > 0)
727  density = reltuples / (double) relpages;
728  else
729  {
730  /*
731  * When we have no data because the relation was never yet vacuumed,
732  * estimate tuple width from attribute datatypes. We assume here that
733  * the pages are completely full, which is OK for tables but is
734  * probably an overestimate for indexes. Fortunately
735  * get_relation_info() can clamp the overestimate to the parent
736  * table's size.
737  *
738  * Note: this code intentionally disregards alignment considerations,
739  * because (a) that would be gilding the lily considering how crude
740  * the estimate is, (b) it creates platform dependencies in the
741  * default plans which are kind of a headache for regression testing,
742  * and (c) different table AMs might use different padding schemes.
743  */
744  int32 tuple_width;
745 
746  tuple_width = get_rel_data_width(rel, attr_widths);
747  tuple_width += overhead_bytes_per_tuple;
748  /* note: integer division is intentional here */
749  density = usable_bytes_per_page / tuple_width;
750  }
751  *tuples = rint(density * (double) curpages);
752 
753  /*
754  * We use relallvisible as-is, rather than scaling it up like we do for
755  * the pages and tuples counts, on the theory that any pages added since
756  * the last VACUUM are most likely not marked all-visible. But costsize.c
757  * wants it converted to a fraction.
758  */
759  if (relallvisible == 0 || curpages <= 0)
760  *allvisfrac = 0;
761  else if ((double) relallvisible >= curpages)
762  *allvisfrac = 1;
763  else
764  *allvisfrac = (double) relallvisible / curpages;
765 }
uint32 BlockNumber
Definition: block.h:31
Form_pg_class rd_rel
Definition: rel.h:109
signed int int32
Definition: c.h:362
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:211
int32 get_rel_data_width(Relation rel, int32 *attr_widths)
Definition: plancat.c:1087

◆ table_block_relation_size()

uint64 table_block_relation_size ( Relation  rel,
ForkNumber  forkNumber 
)

Definition at line 628 of file tableam.c.

References i, InvalidForkNumber, MAX_FORKNUM, RelationData::rd_smgr, RelationOpenSmgr, and smgrnblocks().

Referenced by SampleHeapTupleVisible(), and table_scan_sample_next_tuple().

629 {
630  uint64 nblocks = 0;
631 
632  /* Open it at the smgr level if not already done */
633  RelationOpenSmgr(rel);
634 
635  /* InvalidForkNumber indicates returning the size for all forks */
636  if (forkNumber == InvalidForkNumber)
637  {
638  for (int i = 0; i < MAX_FORKNUM; i++)
639  nblocks += smgrnblocks(rel->rd_smgr, i);
640  }
641  else
642  nblocks = smgrnblocks(rel->rd_smgr, forkNumber);
643 
644  return nblocks * BLCKSZ;
645 }
struct SMgrRelationData * rd_smgr
Definition: rel.h:57
#define RelationOpenSmgr(relation)
Definition: rel.h:513
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:549
#define MAX_FORKNUM
Definition: relpath.h:55
int i

◆ table_compute_xid_horizon_for_tuples()

static TransactionId table_compute_xid_horizon_for_tuples ( Relation  rel,
ItemPointerData items,
int  nitems 
)
inlinestatic

Definition at line 1130 of file tableam.h.

References TableAmRoutine::compute_xid_horizon_for_tuples, and RelationData::rd_tableam.

Referenced by _bt_xid_horizon(), and index_compute_xid_horizon_for_tuples().

1133 {
1134  return rel->rd_tableam->compute_xid_horizon_for_tuples(rel, items, nitems);
1135 }
TransactionId(* compute_xid_horizon_for_tuples)(Relation rel, ItemPointerData *items, int nitems)
Definition: tableam.h:346
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_endscan()

static void table_endscan ( TableScanDesc  scan)
inlinestatic

Definition at line 863 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, and TableAmRoutine::scan_end.

Referenced by acquire_sample_rows(), AlterDomainNotNull(), AlterTableMoveAll(), AlterTableSpaceOptions(), ATRewriteTable(), check_db_file_conflict(), check_default_partition_contents(), CopyTo(), createdb(), currtid_byrelname(), currtid_byreloid(), DefineQueryRewrite(), do_autovacuum(), DropSetting(), DropTableSpace(), ExecEndBitmapHeapScan(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndTidScan(), find_typed_table_dependencies(), get_all_vacuum_rels(), get_database_list(), get_subscription_list(), get_tables_to_cluster(), get_tablespace_name(), get_tablespace_oid(), GetAllTablesPublicationRelations(), getRelationsInNamespace(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), index_update_stats(), IndexCheckExclusion(), objectsInSchemaToOids(), pgrowlocks(), pgstat_collect_oids(), pgstat_heap(), populate_typ_array(), ReindexMultipleTables(), RelationFindReplTupleSeq(), remove_dbtablespaces(), RemoveSubscriptionRel(), RenameTableSpace(), systable_endscan(), ThereIsAtLeastOneRole(), vac_truncate_clog(), validateDomainConstraint(), and validateForeignKeyConstraint().

864 {
865  scan->rs_rd->rd_tableam->scan_end(scan);
866 }
void(* scan_end)(TableScanDesc scan)
Definition: tableam.h:211
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34

◆ table_finish_bulk_insert()

static void table_finish_bulk_insert ( Relation  rel,
int  options 
)
inlinestatic

Definition at line 1371 of file tableam.h.

References TableAmRoutine::finish_bulk_insert, and RelationData::rd_tableam.

Referenced by ATRewriteTable(), CopyMultiInsertBufferCleanup(), intorel_shutdown(), and transientrel_shutdown().

1372 {
1373  /* optional callback */
1374  if (rel->rd_tableam && rel->rd_tableam->finish_bulk_insert)
1376 }
void(* finish_bulk_insert)(Relation rel, int options)
Definition: tableam.h:424
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_index_build_range_scan()

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 
)
inlinestatic

Definition at line 1585 of file tableam.h.

References TableAmRoutine::index_build_range_scan, and RelationData::rd_tableam.

Referenced by summarize_range().

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 }
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
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
int progress
Definition: pgbench.c:235
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_index_build_scan()

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 
)
inlinestatic

Definition at line 1552 of file tableam.h.

References TableAmRoutine::index_build_range_scan, InvalidBlockNumber, and RelationData::rd_tableam.

Referenced by _bt_parallel_scan_and_sort(), _bt_spools_heapscan(), blbuild(), brinbuild(), bt_check_every_level(), ginbuild(), gistbuild(), hashbuild(), and spgbuild().

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 }
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
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
int progress
Definition: pgbench.c:235
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define InvalidBlockNumber
Definition: block.h:33

◆ table_index_fetch_begin()

static IndexFetchTableData* table_index_fetch_begin ( Relation  rel)
inlinestatic

Definition at line 975 of file tableam.h.

References TableAmRoutine::index_fetch_begin, and RelationData::rd_tableam.

Referenced by index_beginscan(), index_beginscan_parallel(), table_index_fetch_tuple_check(), and unique_key_recheck().

976 {
977  return rel->rd_tableam->index_fetch_begin(rel);
978 }
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:269
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_index_fetch_end()

static void table_index_fetch_end ( struct IndexFetchTableData scan)
inlinestatic

Definition at line 994 of file tableam.h.

References TableAmRoutine::index_fetch_end, RelationData::rd_tableam, and IndexFetchTableData::rel.

Referenced by index_endscan(), table_index_fetch_tuple_check(), and unique_key_recheck().

995 {
996  scan->rel->rd_tableam->index_fetch_end(scan);
997 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition: tableam.h:280

◆ table_index_fetch_reset()

static void table_index_fetch_reset ( struct IndexFetchTableData scan)
inlinestatic

Definition at line 985 of file tableam.h.

References TableAmRoutine::index_fetch_reset, RelationData::rd_tableam, and IndexFetchTableData::rel.

Referenced by index_getnext_tid(), index_parallelrescan(), index_rescan(), and index_restrpos().

986 {
987  scan->rel->rd_tableam->index_fetch_reset(scan);
988 }
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:275
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_index_fetch_tuple()

static bool table_index_fetch_tuple ( struct IndexFetchTableData scan,
ItemPointer  tid,
Snapshot  snapshot,
TupleTableSlot slot,
bool call_again,
bool all_dead 
)
inlinestatic

Definition at line 1024 of file tableam.h.

References bsysscan, CheckXidAlive, elog, ERROR, TableAmRoutine::index_fetch_tuple, RelationData::rd_tableam, IndexFetchTableData::rel, table_index_fetch_tuple_check(), TransactionIdIsValid, and unlikely.

Referenced by index_fetch_heap(), table_index_fetch_tuple_check(), and unique_key_recheck().

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 }
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41
bool(* index_fetch_tuple)(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:302

◆ table_index_fetch_tuple_check()

bool table_index_fetch_tuple_check ( Relation  rel,
ItemPointer  tid,
Snapshot  snapshot,
bool all_dead 
)

Definition at line 219 of file tableam.c.

References ExecDropSingleTupleTableSlot(), table_index_fetch_begin(), table_index_fetch_end(), table_index_fetch_tuple(), and table_slot_create().

Referenced by _bt_check_unique(), and table_index_fetch_tuple().

223 {
224  IndexFetchTableData *scan;
225  TupleTableSlot *slot;
226  bool call_again = false;
227  bool found;
228 
229  slot = table_slot_create(rel, NULL);
230  scan = table_index_fetch_begin(rel);
231  found = table_index_fetch_tuple(scan, tid, snapshot, slot, &call_again,
232  all_dead);
233  table_index_fetch_end(scan);
235 
236  return found;
237 }
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
Definition: tableam.c:91
static IndexFetchTableData * table_index_fetch_begin(Relation rel)
Definition: tableam.h:975
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1224
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
static void table_index_fetch_end(struct IndexFetchTableData *scan)
Definition: tableam.h:994

◆ table_index_validate_scan()

static void table_index_validate_scan ( Relation  table_rel,
Relation  index_rel,
struct IndexInfo index_info,
Snapshot  snapshot,
struct ValidateIndexState state 
)
inlinestatic

Definition at line 1616 of file tableam.h.

References TableAmRoutine::index_validate_scan, and RelationData::rd_tableam.

Referenced by validate_index().

1621 {
1622  table_rel->rd_tableam->index_validate_scan(table_rel,
1623  index_rel,
1624  index_info,
1625  snapshot,
1626  state);
1627 }
void(* index_validate_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:553
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_multi_insert()

static void table_multi_insert ( Relation  rel,
TupleTableSlot **  slots,
int  nslots,
CommandId  cid,
int  options,
struct BulkInsertStateData bistate 
)
inlinestatic

Definition at line 1233 of file tableam.h.

References TableAmRoutine::multi_insert, and RelationData::rd_tableam.

Referenced by CopyMultiInsertBufferFlush().

1235 {
1236  rel->rd_tableam->multi_insert(rel, slots, nslots,
1237  cid, options, bistate);
1238 }
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:376
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_parallelscan_estimate()

Size table_parallelscan_estimate ( Relation  rel,
Snapshot  snapshot 
)

Definition at line 140 of file tableam.c.

References add_size(), Assert, EstimateSnapshotSpace(), IsMVCCSnapshot, TableAmRoutine::parallelscan_estimate, RelationData::rd_tableam, and SnapshotAny.

Referenced by _bt_parallel_estimate_shared(), ExecSeqScanEstimate(), and table_scan_getnextslot().

141 {
142  Size sz = 0;
143 
144  if (IsMVCCSnapshot(snapshot))
145  sz = add_size(sz, EstimateSnapshotSpace(snapshot));
146  else
147  Assert(snapshot == SnapshotAny);
148 
149  sz = add_size(sz, rel->rd_tableam->parallelscan_estimate(rel));
150 
151  return sz;
152 }
Size(* parallelscan_estimate)(Relation rel)
Definition: tableam.h:238
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2074
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:97
#define Assert(condition)
Definition: c.h:745
size_t Size
Definition: c.h:473
#define SnapshotAny
Definition: snapmgr.h:68

◆ table_parallelscan_initialize()

void table_parallelscan_initialize ( Relation  rel,
ParallelTableScanDesc  pscan,
Snapshot  snapshot 
)

Definition at line 155 of file tableam.c.

References Assert, IsMVCCSnapshot, TableAmRoutine::parallelscan_initialize, ParallelTableScanDescData::phs_snapshot_any, ParallelTableScanDescData::phs_snapshot_off, RelationData::rd_tableam, SerializeSnapshot(), and SnapshotAny.

Referenced by _bt_begin_parallel(), ExecSeqScanInitializeDSM(), and table_scan_getnextslot().

157 {
158  Size snapshot_off = rel->rd_tableam->parallelscan_initialize(rel, pscan);
159 
160  pscan->phs_snapshot_off = snapshot_off;
161 
162  if (IsMVCCSnapshot(snapshot))
163  {
164  SerializeSnapshot(snapshot, (char *) pscan + pscan->phs_snapshot_off);
165  pscan->phs_snapshot_any = false;
166  }
167  else
168  {
169  Assert(snapshot == SnapshotAny);
170  pscan->phs_snapshot_any = true;
171  }
172 }
Size(* parallelscan_initialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:245
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2098
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:97
#define Assert(condition)
Definition: c.h:745
size_t Size
Definition: c.h:473
#define SnapshotAny
Definition: snapmgr.h:68

◆ table_parallelscan_reinitialize()

static void table_parallelscan_reinitialize ( Relation  rel,
ParallelTableScanDesc  pscan 
)
inlinestatic

Definition at line 957 of file tableam.h.

References TableAmRoutine::parallelscan_reinitialize, and RelationData::rd_tableam.

Referenced by ExecSeqScanReInitializeDSM().

958 {
959  rel->rd_tableam->parallelscan_reinitialize(rel, pscan);
960 }
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:252
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_copy_data()

static void table_relation_copy_data ( Relation  rel,
const RelFileNode newrnode 
)
inlinestatic

Definition at line 1426 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_copy_data.

Referenced by ATExecSetTableSpace().

1427 {
1428  rel->rd_tableam->relation_copy_data(rel, newrnode);
1429 }
void(* relation_copy_data)(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:470
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_copy_for_cluster()

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 
)
inlinestatic

Definition at line 1453 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_copy_for_cluster.

Referenced by copy_table_data().

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 }
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
static TransactionId OldestXmin
Definition: vacuumlazy.c:335
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_estimate_size()

static void table_relation_estimate_size ( Relation  rel,
int32 attr_widths,
BlockNumber pages,
double *  tuples,
double *  allvisfrac 
)
inlinestatic

Definition at line 1714 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_estimate_size.

Referenced by estimate_rel_size().

1717 {
1718  rel->rd_tableam->relation_estimate_size(rel, attr_widths, pages, tuples,
1719  allvisfrac);
1720 }
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:619
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_fetch_toast_slice()

static void table_relation_fetch_toast_slice ( Relation  toastrel,
Oid  valueid,
int32  attrsize,
int32  sliceoffset,
int32  slicelength,
struct varlena result 
)
inlinestatic

Definition at line 1693 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_fetch_toast_slice.

Referenced by toast_fetch_datum(), and toast_fetch_datum_slice().

1696 {
1697  toastrel->rd_tableam->relation_fetch_toast_slice(toastrel, valueid,
1698  attrsize,
1699  sliceoffset, slicelength,
1700  result);
1701 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
void(* relation_fetch_toast_slice)(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
Definition: tableam.h:597

◆ table_relation_needs_toast_table()

static bool table_relation_needs_toast_table ( Relation  rel)
inlinestatic

Definition at line 1654 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_needs_toast_table.

Referenced by needs_toast_table().

1655 {
1656  return rel->rd_tableam->relation_needs_toast_table(rel);
1657 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:583

◆ table_relation_nontransactional_truncate()

static void table_relation_nontransactional_truncate ( Relation  rel)
inlinestatic

Definition at line 1414 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_nontransactional_truncate.

Referenced by heap_truncate_one_rel().

1415 {
1417 }
void(* relation_nontransactional_truncate)(Relation rel)
Definition: tableam.h:462
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_set_new_filenode()

static void table_relation_set_new_filenode ( Relation  rel,
const RelFileNode newrnode,
char  persistence,
TransactionId freezeXid,
MultiXactId minmulti 
)
inlinestatic

Definition at line 1397 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_set_new_filenode.

Referenced by heap_create(), and RelationSetNewRelfilenode().

1402 {
1403  rel->rd_tableam->relation_set_new_filenode(rel, newrnode, persistence,
1404  freezeXid, minmulti);
1405 }
void(* relation_set_new_filenode)(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:448
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_size()

static uint64 table_relation_size ( Relation  rel,
ForkNumber  forkNumber 
)
inlinestatic

Definition at line 1645 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_size.

Referenced by RelationGetNumberOfBlocksInFork().

1646 {
1647  return rel->rd_tableam->relation_size(rel, forkNumber);
1648 }
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:573
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_toast_am()

static Oid table_relation_toast_am ( Relation  rel)
inlinestatic

Definition at line 1664 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_toast_am.

Referenced by create_toast_table().

1665 {
1666  return rel->rd_tableam->relation_toast_am(rel);
1667 }
Oid(* relation_toast_am)(Relation rel)
Definition: tableam.h:590
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_relation_vacuum()

static void table_relation_vacuum ( Relation  rel,
struct VacuumParams params,
BufferAccessStrategy  bstrategy 
)
inlinestatic

Definition at line 1482 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::relation_vacuum.

Referenced by vacuum_rel().

1484 {
1485  rel->rd_tableam->relation_vacuum(rel, params, bstrategy);
1486 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
void(* relation_vacuum)(Relation onerel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:500

◆ table_rescan()

static void table_rescan ( TableScanDesc  scan,
struct ScanKeyData key 
)
inlinestatic

Definition at line 872 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, and TableAmRoutine::scan_rescan.

Referenced by ExecReScanBitmapHeapScan(), ExecReScanSeqScan(), ExecReScanTidScan(), and RelationFindReplTupleSeq().

874 {
875  scan->rs_rd->rd_tableam->scan_rescan(scan, key, false, false, false, false);
876 }
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:217
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34

◆ table_rescan_set_params()

static void table_rescan_set_params ( TableScanDesc  scan,
struct ScanKeyData key,
bool  allow_strat,
bool  allow_sync,
bool  allow_pagemode 
)
inlinestatic

Definition at line 887 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, TableAmRoutine::scan_rescan, and table_scan_update_snapshot().

Referenced by tablesample_init().

889 {
890  scan->rs_rd->rd_tableam->scan_rescan(scan, key, true,
891  allow_strat, allow_sync,
892  allow_pagemode);
893 }
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:217
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34

◆ table_scan_analyze_next_block()

static bool table_scan_analyze_next_block ( TableScanDesc  scan,
BlockNumber  blockno,
BufferAccessStrategy  bstrategy 
)
inlinestatic

Definition at line 1497 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, and TableAmRoutine::scan_analyze_next_block.

Referenced by acquire_sample_rows().

1499 {
1500  return scan->rs_rd->rd_tableam->scan_analyze_next_block(scan, blockno,
1501  bstrategy);
1502 }
bool(* scan_analyze_next_block)(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:521
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34

◆ table_scan_analyze_next_tuple()

static bool table_scan_analyze_next_tuple ( TableScanDesc  scan,
TransactionId  OldestXmin,
double *  liverows,
double *  deadrows,
TupleTableSlot slot 
)
inlinestatic

Definition at line 1515 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, and TableAmRoutine::scan_analyze_next_tuple.

Referenced by acquire_sample_rows().

1518 {
1519  return scan->rs_rd->rd_tableam->scan_analyze_next_tuple(scan, OldestXmin,
1520  liverows, deadrows,
1521  slot);
1522 }
bool(* scan_analyze_next_tuple)(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:533
static TransactionId OldestXmin
Definition: vacuumlazy.c:335
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34

◆ table_scan_bitmap_next_block()

static bool table_scan_bitmap_next_block ( TableScanDesc  scan,
struct TBMIterateResult tbmres 
)
inlinestatic

Definition at line 1738 of file tableam.h.

References bsysscan, CheckXidAlive, elog, ERROR, RelationData::rd_tableam, TableScanDescData::rs_rd, TableAmRoutine::scan_bitmap_next_block, TransactionIdIsValid, and unlikely.

Referenced by BitmapHeapNext().

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 }
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:660
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ table_scan_bitmap_next_tuple()

static bool table_scan_bitmap_next_tuple ( TableScanDesc  scan,
struct TBMIterateResult tbmres,
TupleTableSlot slot 
)
inlinestatic

Definition at line 1762 of file tableam.h.

References bsysscan, CheckXidAlive, elog, ERROR, RelationData::rd_tableam, TableScanDescData::rs_rd, TableAmRoutine::scan_bitmap_next_tuple, TransactionIdIsValid, and unlikely.

Referenced by BitmapHeapNext().

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 }
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:674
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ table_scan_getnextslot()

static bool table_scan_getnextslot ( TableScanDesc  sscan,
ScanDirection  direction,
TupleTableSlot slot 
)
inlinestatic

Definition at line 904 of file tableam.h.

References bsysscan, CheckXidAlive, elog, ERROR, RelationData::rd_tableam, RelationGetRelid, TableScanDescData::rs_rd, TableAmRoutine::scan_getnextslot, table_beginscan_parallel(), table_parallelscan_estimate(), table_parallelscan_initialize(), TransactionIdIsValid, TupleTableSlot::tts_tableOid, and unlikely.

Referenced by AlterDomainNotNull(), ATRewriteTable(), check_default_partition_contents(), CopyTo(), DefineQueryRewrite(), heapam_relation_copy_for_cluster(), IndexCheckExclusion(), RelationFindReplTupleSeq(), SeqNext(), systable_getnext(), validateDomainConstraint(), and validateForeignKeyConstraint().

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 }
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:224
Oid tts_tableOid
Definition: tuptable.h:131
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ table_scan_sample_next_block()

static bool table_scan_sample_next_block ( TableScanDesc  scan,
struct SampleScanState scanstate 
)
inlinestatic

Definition at line 1789 of file tableam.h.

References bsysscan, CheckXidAlive, elog, ERROR, RelationData::rd_tableam, TableScanDescData::rs_rd, TableAmRoutine::scan_sample_next_block, TransactionIdIsValid, and unlikely.

Referenced by tablesample_getnext().

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 }
bool(* scan_sample_next_block)(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:703
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ table_scan_sample_next_tuple()

static bool table_scan_sample_next_tuple ( TableScanDesc  scan,
struct SampleScanState scanstate,
TupleTableSlot slot 
)
inlinestatic

Definition at line 1811 of file tableam.h.

References bsysscan, check_default_table_access_method(), CheckXidAlive, elog, ERROR, GetHeapamTableAmRoutine(), GetTableAmRoutine(), newval, RelationData::rd_tableam, TableScanDescData::rs_rd, TableAmRoutine::scan_sample_next_tuple, simple_table_tuple_delete(), simple_table_tuple_insert(), simple_table_tuple_update(), table_block_parallelscan_estimate(), table_block_parallelscan_initialize(), table_block_parallelscan_nextpage(), table_block_parallelscan_reinitialize(), table_block_parallelscan_startblock_init(), table_block_relation_estimate_size(), table_block_relation_size(), TransactionIdIsValid, and unlikely.

Referenced by tablesample_getnext().

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 }
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
bool(* scan_sample_next_tuple)(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:719
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ table_scan_update_snapshot()

void table_scan_update_snapshot ( TableScanDesc  scan,
Snapshot  snapshot 
)

Definition at line 124 of file tableam.c.

References Assert, IsMVCCSnapshot, RegisterSnapshot(), TableScanDescData::rs_flags, TableScanDescData::rs_snapshot, and SO_TEMP_SNAPSHOT.

Referenced by ExecBitmapHeapInitializeWorker(), and table_rescan_set_params().

125 {
126  Assert(IsMVCCSnapshot(snapshot));
127 
128  RegisterSnapshot(snapshot);
129  scan->rs_snapshot = snapshot;
130  scan->rs_flags |= SO_TEMP_SNAPSHOT;
131 }
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
uint32 rs_flags
Definition: relscan.h:43
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:97
#define Assert(condition)
Definition: c.h:745
struct SnapshotData * rs_snapshot
Definition: relscan.h:35

◆ table_slot_callbacks()

const TupleTableSlotOps* table_slot_callbacks ( Relation  rel)

Definition at line 58 of file tableam.c.

References Assert, RelationData::rd_rel, RelationData::rd_tableam, TableAmRoutine::slot_callbacks, TTSOpsHeapTuple, and TTSOpsVirtual.

Referenced by ATRewriteTable(), ExecGetReturningSlot(), ExecGetTriggerNewSlot(), ExecGetTriggerOldSlot(), ExecInitBitmapHeapScan(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitModifyTable(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitTidScan(), and table_slot_create().

59 {
60  const TupleTableSlotOps *tts_cb;
61 
62  if (relation->rd_tableam)
63  tts_cb = relation->rd_tableam->slot_callbacks(relation);
64  else if (relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
65  {
66  /*
67  * Historically FDWs expect to store heap tuples in slots. Continue
68  * handing them one, to make it less painful to adapt FDWs to new
69  * versions. The cost of a heap slot over a virtual slot is pretty
70  * small.
71  */
72  tts_cb = &TTSOpsHeapTuple;
73  }
74  else
75  {
76  /*
77  * These need to be supported, as some parts of the code (like COPY)
78  * need to create slots for such relations too. It seems better to
79  * centralize the knowledge that a heap slot is the right thing in
80  * that case here.
81  */
82  Assert(relation->rd_rel->relkind == RELKIND_VIEW ||
83  relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
84  tts_cb = &TTSOpsVirtual;
85  }
86 
87  return tts_cb;
88 }
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
#define Assert(condition)
Definition: c.h:745
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84

◆ table_slot_create()

TupleTableSlot* table_slot_create ( Relation  rel,
List **  reglist 
)

Definition at line 91 of file tableam.c.

References lappend(), MakeSingleTupleTableSlot(), RelationGetDescr, and table_slot_callbacks().

Referenced by acquire_sample_rows(), AlterDomainNotNull(), apply_handle_tuple_routing(), check_default_partition_contents(), check_exclusion_or_unique_constraint(), CopyFrom(), CopyMultiInsertInfoNextFreeSlot(), CopyTo(), DefineQueryRewrite(), EvalPlanQualSlot(), ExecInitModifyTable(), ExecInitPartitionInfo(), ExecInitRoutingInfo(), FindReplTupleInLocalRel(), get_actual_variable_range(), heapam_index_build_range_scan(), heapam_relation_copy_for_cluster(), IndexCheckExclusion(), RelationFindReplTupleSeq(), systable_beginscan(), systable_beginscan_ordered(), table_index_fetch_tuple_check(), unique_key_recheck(), validateDomainConstraint(), and validateForeignKeyConstraint().

92 {
93  const TupleTableSlotOps *tts_cb;
94  TupleTableSlot *slot;
95 
96  tts_cb = table_slot_callbacks(relation);
97  slot = MakeSingleTupleTableSlot(RelationGetDescr(relation), tts_cb);
98 
99  if (reglist)
100  *reglist = lappend(*reglist, slot);
101 
102  return slot;
103 }
#define RelationGetDescr(relation)
Definition: rel.h:482
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1208
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
List * lappend(List *list, void *datum)
Definition: list.c:321

◆ table_tuple_complete_speculative()

static void table_tuple_complete_speculative ( Relation  rel,
TupleTableSlot slot,
uint32  specToken,
bool  succeeded 
)
inlinestatic

Definition at line 1211 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_complete_speculative.

Referenced by ExecInsert().

1213 {
1214  rel->rd_tableam->tuple_complete_speculative(rel, slot, specToken,
1215  succeeded);
1216 }
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:370
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_tuple_delete()

static TM_Result table_tuple_delete ( Relation  rel,
ItemPointer  tid,
CommandId  cid,
Snapshot  snapshot,
Snapshot  crosscheck,
bool  wait,
TM_FailureData tmfd,
bool  changingPart 
)
inlinestatic

Definition at line 1267 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_delete.

Referenced by ExecDelete(), and simple_table_tuple_delete().

1270 {
1271  return rel->rd_tableam->tuple_delete(rel, tid, cid,
1272  snapshot, crosscheck,
1273  wait, tmfd, changingPart);
1274 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
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

◆ table_tuple_fetch_row_version()

static bool table_tuple_fetch_row_version ( Relation  rel,
ItemPointer  tid,
Snapshot  snapshot,
TupleTableSlot slot 
)
inlinestatic

Definition at line 1071 of file tableam.h.

References bsysscan, CheckXidAlive, elog, ERROR, RelationData::rd_tableam, TransactionIdIsValid, TableAmRoutine::tuple_fetch_row_version, and unlikely.

Referenced by AfterTriggerExecute(), EvalPlanQualFetchRowMark(), ExecCheckTIDVisible(), ExecDelete(), GetTupleForTrigger(), and TidNext().

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 }
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:319
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ table_tuple_get_latest_tid()

void table_tuple_get_latest_tid ( TableScanDesc  scan,
ItemPointer  tid 
)

Definition at line 246 of file tableam.c.

References bsysscan, CheckXidAlive, elog, ereport, errcode(), errmsg(), ERROR, ItemPointerGetBlockNumberNoCheck, ItemPointerGetOffsetNumberNoCheck, RelationData::rd_tableam, RelationGetRelationName, TableScanDescData::rs_rd, TransactionIdIsValid, TableAmRoutine::tuple_get_latest_tid, TableAmRoutine::tuple_tid_valid, and unlikely.

Referenced by currtid_byrelname(), currtid_byreloid(), table_tuple_tid_valid(), and TidNext().

247 {
248  Relation rel = scan->rs_rd;
249  const TableAmRoutine *tableam = rel->rd_tableam;
250 
251  /*
252  * We don't expect direct calls to table_tuple_get_latest_tid with valid
253  * CheckXidAlive for catalog or regular tables. See detailed comments in
254  * xact.c where these variables are declared.
255  */
257  elog(ERROR, "unexpected table_tuple_get_latest_tid call during logical decoding");
258 
259  /*
260  * Since this can be called with user-supplied TID, don't trust the input
261  * too much.
262  */
263  if (!tableam->tuple_tid_valid(scan, tid))
264  ereport(ERROR,
265  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
266  errmsg("tid (%u, %u) is not valid for relation \"%s\"",
269  RelationGetRelationName(rel))));
270 
271  tableam->tuple_get_latest_tid(scan, tid);
272 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
bool bsysscan
Definition: xact.c:96
#define RelationGetRelationName(relation)
Definition: rel.h:490
TransactionId CheckXidAlive
Definition: xact.c:95
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define ereport(elevel,...)
Definition: elog.h:144
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:334
Relation rs_rd
Definition: relscan.h:34
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:327
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89
#define elog(elevel,...)
Definition: elog.h:214
#define unlikely(x)
Definition: c.h:206
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ table_tuple_insert()

static void table_tuple_insert ( Relation  rel,
TupleTableSlot slot,
CommandId  cid,
int  options,
struct BulkInsertStateData bistate 
)
inlinestatic

Definition at line 1178 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_insert.

Referenced by ATRewriteTable(), CopyFrom(), ExecInsert(), intorel_receive(), simple_table_tuple_insert(), and transientrel_receive().

1180 {
1181  rel->rd_tableam->tuple_insert(rel, slot, cid, options,
1182  bistate);
1183 }
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:357
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_tuple_insert_speculative()

static void table_tuple_insert_speculative ( Relation  rel,
TupleTableSlot slot,
CommandId  cid,
int  options,
struct BulkInsertStateData bistate,
uint32  specToken 
)
inlinestatic

Definition at line 1197 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_insert_speculative.

Referenced by ExecInsert().

1201 {
1202  rel->rd_tableam->tuple_insert_speculative(rel, slot, cid, options,
1203  bistate, specToken);
1204 }
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:362
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

◆ table_tuple_lock()

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 
)
inlinestatic

Definition at line 1356 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_lock.

Referenced by ExecDelete(), ExecLockRows(), ExecOnConflictUpdate(), ExecUpdate(), GetTupleForTrigger(), RelationFindReplTupleByIndex(), and RelationFindReplTupleSeq().

1360 {
1361  return rel->rd_tableam->tuple_lock(rel, tid, snapshot, slot,
1362  cid, mode, wait_policy,
1363  flags, tmfd);
1364 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
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

◆ table_tuple_satisfies_snapshot()

static bool table_tuple_satisfies_snapshot ( Relation  rel,
TupleTableSlot slot,
Snapshot  snapshot 
)
inlinestatic

Definition at line 1118 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_satisfies_snapshot.

Referenced by ExecCheckTupleVisible(), RI_FKey_check(), and systable_recheck_tuple().

1120 {
1121  return rel->rd_tableam->tuple_satisfies_snapshot(rel, slot, snapshot);
1122 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:341

◆ table_tuple_tid_valid()

static bool table_tuple_tid_valid ( TableScanDesc  scan,
ItemPointer  tid 
)
inlinestatic

Definition at line 1097 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, table_tuple_get_latest_tid(), and TableAmRoutine::tuple_tid_valid.

Referenced by TidListEval().

1098 {
1099  return scan->rs_rd->rd_tableam->tuple_tid_valid(scan, tid);
1100 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
Relation rs_rd
Definition: relscan.h:34
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:327

◆ table_tuple_update()

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 
)
inlinestatic

Definition at line 1311 of file tableam.h.

References RelationData::rd_tableam, and TableAmRoutine::tuple_update.

Referenced by ExecUpdate(), and simple_table_tuple_update().

1315 {
1316  return rel->rd_tableam->tuple_update(rel, otid, slot,
1317  cid, snapshot, crosscheck,
1318  wait, tmfd,
1319  lockmode, update_indexes);
1320 }
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
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171

Variable Documentation

◆ default_table_access_method

char* default_table_access_method

Definition at line 48 of file tableam.c.

Referenced by DefineRelation().

◆ synchronize_seqscans

bool synchronize_seqscans

Definition at line 49 of file tableam.c.

Referenced by initscan(), and table_block_parallelscan_initialize().