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  TM_IndexDelete
 
struct  TM_IndexStatus
 
struct  TM_IndexDeleteOp
 
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 struct TM_IndexDelete TM_IndexDelete
 
typedef struct TM_IndexStatus TM_IndexStatus
 
typedef struct TM_IndexDeleteOp TM_IndexDeleteOp
 
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_TIDRANGESCAN = 1 << 4, SO_TYPE_ANALYZE = 1 << 5, SO_ALLOW_STRAT = 1 << 6, SO_ALLOW_SYNC = 1 << 7,
  SO_ALLOW_PAGEMODE = 1 << 8, SO_TEMP_SNAPSHOT = 1 << 9
}
 
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)
 
static TableScanDesc table_beginscan_tidrange (Relation rel, Snapshot snapshot, ItemPointer mintid, ItemPointer maxtid)
 
static void table_rescan_tidrange (TableScanDesc sscan, ItemPointer mintid, ItemPointer maxtid)
 
static bool table_scan_getnextslot_tidrange (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_index_delete_tuples (Relation rel, TM_IndexDeleteOp *delstate)
 
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 235 of file tableam.h.

Referenced by CopyFrom(), and transientrel_startup().

◆ TABLE_INSERT_NO_LOGICAL

#define TABLE_INSERT_NO_LOGICAL   0x0008

Definition at line 236 of file tableam.h.

◆ TABLE_INSERT_SKIP_FSM

#define TABLE_INSERT_SKIP_FSM   0x0002

Definition at line 234 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 240 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 246 of file tableam.h.

◆ ScanOptions

typedef enum ScanOptions ScanOptions

◆ TableAmRoutine

◆ TM_FailureData

◆ TM_IndexDelete

◆ TM_IndexDeleteOp

◆ TM_IndexStatus

◆ 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_TIDRANGESCAN 
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_TIDRANGESCAN = 1 << 4,
53  SO_TYPE_ANALYZE = 1 << 5,
54 
55  /* several of SO_ALLOW_* may be specified */
56  /* allow or disallow use of access strategy */
57  SO_ALLOW_STRAT = 1 << 6,
58  /* report location to syncscan logic? */
59  SO_ALLOW_SYNC = 1 << 7,
60  /* verify visibility page-at-a-time? */
61  SO_ALLOW_PAGEMODE = 1 << 8,
62 
63  /* unregister snapshot at scan end? */
64  SO_TEMP_SNAPSHOT = 1 << 9
65 } 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 71 of file tableam.h.

72 {
73  /*
74  * Signals that the action succeeded (i.e. update/delete performed, lock
75  * was acquired)
76  */
77  TM_Ok,
78 
79  /* The affected tuple wasn't visible to the relevant snapshot */
81 
82  /* The affected tuple was already modified by the calling backend */
84 
85  /*
86  * The affected tuple was updated by another transaction. This includes
87  * the case where tuple was moved to another partition.
88  */
89  TM_Updated,
90 
91  /* The affected tuple was deleted by another transaction */
92  TM_Deleted,
93 
94  /*
95  * The affected tuple is currently being modified by another session. This
96  * will only be returned if table_(update/delete/lock_tuple) are
97  * instructed not to wait.
98  */
100 
101  /* lock couldn't be acquired, action skipped. Only used by lock_tuple */
103 } TM_Result;
TM_Result
Definition: tableam.h:71
Definition: tableam.h:77

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:422
int errcode(int sqlerrcode)
Definition: elog.c:698
#define OidIsValid(objectId)
Definition: c.h:710
#define NAMEDATALEN
Oid MyDatabaseId
Definition: globals.c:88
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:157
#define NOTICE
Definition: elog.h:37
Oid get_table_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:173
static rewind_source * source
Definition: pg_rewind.c:79
#define newval
bool IsTransactionState(void)
Definition: xact.c:372
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ GetHeapamTableAmRoutine()

const TableAmRoutine* GetHeapamTableAmRoutine ( void  )

Definition at line 2599 of file heapam_handler.c.

References heapam_methods.

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

2600 {
2601  return &heapam_methods;
2602 }
static const TableAmRoutine heapam_methods

◆ GetTableAmRoutine()

const TableAmRoutine* GetTableAmRoutine ( Oid  amhandler)

Definition at line 34 of file tableamapi.c.

References Assert, DatumGetPointer, elog, ERROR, TableAmRoutine::index_build_range_scan, TableAmRoutine::index_delete_tuples, 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->index_delete_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:325
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:747
void(* relation_vacuum)(Relation rel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:628
#define IsA(nodeptr, _type_)
Definition: nodes.h:588
Size(* parallelscan_estimate)(Relation rel)
Definition: tableam.h:367
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:518
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:398
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:404
void(* scan_end)(TableScanDesc scan)
Definition: tableam.h:312
bool(* scan_sample_next_block)(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:831
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:701
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:668
void(* index_validate_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:681
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:448
void(* relation_nontransactional_truncate)(Relation rel)
Definition: tableam.h:590
bool(* scan_analyze_next_block)(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:649
Size(* parallelscan_initialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:374
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:490
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:318
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:485
#define ERROR
Definition: elog.h:46
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:498
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:788
void(* relation_set_new_filenode)(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:576
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:504
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:602
bool(* scan_analyze_next_tuple)(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:661
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:802
void(* relation_copy_data)(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:598
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:381
uintptr_t Datum
Definition: postgres.h:411
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:711
#define OidFunctionCall0(functionId)
Definition: fmgr.h:662
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition: tableam.h:409
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:530
#define Assert(condition)
Definition: c.h:804
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:463
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:470
bool(* scan_sample_next_tuple)(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:847
#define DatumGetPointer(X)
Definition: postgres.h:593
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:456
TransactionId(* index_delete_tuples)(Relation rel, TM_IndexDeleteOp *delstate)
Definition: tableam.h:475
#define elog(elevel,...)
Definition: elog.h:232
bool(* index_fetch_tuple)(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:431
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
Definition: tableam.h:508

◆ 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:46
#define InvalidSnapshot
Definition: snapshot.h:123
TM_Result
Definition: tableam.h:71
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:1460
Definition: tableam.h:77
#define elog(elevel,...)
Definition: elog.h:232
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:762

◆ 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:1371
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:762

◆ 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:46
#define InvalidSnapshot
Definition: snapshot.h:123
TM_Result
Definition: tableam.h:71
Definition: tableam.h:77
#define elog(elevel,...)
Definition: elog.h:232
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:762
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:1504

◆ table_beginscan()

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

Definition at line 883 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(), DefineQueryRewrite(), DoCopyTo(), heapam_relation_copy_for_cluster(), pgrowlocks(), pgstat_collect_oids(), RelationFindReplTupleSeq(), SeqNext(), validateDomainConstraint(), and validateForeignKeyConstraint().

885 {
886  uint32 flags = SO_TYPE_SEQSCAN |
888 
889  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
890 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_beginscan_analyze()

static TableScanDesc table_beginscan_analyze ( Relation  rel)
inlinestatic

Definition at line 980 of file tableam.h.

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

Referenced by acquire_sample_rows().

981 {
982  uint32 flags = SO_TYPE_ANALYZE;
983 
984  return rel->rd_tableam->scan_begin(rel, NULL, 0, NULL, NULL, flags);
985 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_beginscan_bm()

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

Definition at line 928 of file tableam.h.

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

Referenced by ExecInitBitmapHeapScan().

930 {
932 
933  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
934 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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_list(), 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:825
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:386
unsigned int Oid
Definition: postgres_ext.h:31
unsigned int uint32
Definition: c.h:441
#define RelationGetRelid(relation)
Definition: rel.h:477

◆ 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_tidrange().

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:2176
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:825
unsigned int uint32
Definition: c.h:441
#define Assert(condition)
Definition: c.h:804
#define SnapshotAny
Definition: snapmgr.h:67
#define RelationGetRelid(relation)
Definition: rel.h:477

◆ 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 944 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().

948 {
949  uint32 flags = SO_TYPE_SAMPLESCAN;
950 
951  if (allow_strat)
952  flags |= SO_ALLOW_STRAT;
953  if (allow_sync)
954  flags |= SO_ALLOW_SYNC;
955  if (allow_pagemode)
956  flags |= SO_ALLOW_PAGEMODE;
957 
958  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
959 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 907 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().

910 {
912 
913  if (allow_strat)
914  flags |= SO_ALLOW_STRAT;
915  if (allow_sync)
916  flags |= SO_ALLOW_SYNC;
917 
918  return rel->rd_tableam->scan_begin(rel, snapshot, nkeys, key, NULL, flags);
919 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_beginscan_tid()

static TableScanDesc table_beginscan_tid ( Relation  rel,
Snapshot  snapshot 
)
inlinestatic

Definition at line 967 of file tableam.h.

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

Referenced by currtid_internal(), and TidListEval().

968 {
969  uint32 flags = SO_TYPE_TIDSCAN;
970 
971  return rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
972 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_beginscan_tidrange()

static TableScanDesc table_beginscan_tidrange ( Relation  rel,
Snapshot  snapshot,
ItemPointer  mintid,
ItemPointer  maxtid 
)
inlinestatic

Definition at line 1057 of file tableam.h.

References RelationData::rd_tableam, TableScanDescData::rs_rd, TableAmRoutine::scan_begin, TableAmRoutine::scan_set_tidrange, SO_ALLOW_PAGEMODE, and SO_TYPE_TIDRANGESCAN.

Referenced by TidRangeNext().

1060 {
1061  TableScanDesc sscan;
1063 
1064  sscan = rel->rd_tableam->scan_begin(rel, snapshot, 0, NULL, NULL, flags);
1065 
1066  /* Set the range of TIDs to scan */
1067  sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
1068 
1069  return sscan;
1070 }
TableScanDesc(* scan_begin)(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, ParallelTableScanDesc pscan, uint32 flags)
Definition: tableam.h:302
unsigned int uint32
Definition: c.h:441
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
void(* scan_set_tidrange)(TableScanDesc scan, ItemPointer mintid, ItemPointer maxtid)
Definition: tableam.h:346
Relation rs_rd
Definition: relscan.h:34

◆ 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:82
bool synchronize_seqscans
Definition: tableam.c:49
ParallelTableScanDescData base
Definition: relscan.h:77
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition: relscan.h:85
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:212
#define InvalidBlockNumber
Definition: block.h:33
#define RelationUsesLocalBuffers(relation)
Definition: rel.h:610
int NBuffers
Definition: globals.c:135
#define RelationGetRelid(relation)
Definition: rel.h:477

◆ 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:82
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:467
ParallelTableScanDescData base
Definition: relscan.h:77
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:82
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition: relscan.h:85
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:77
#define PARALLEL_SEQSCAN_MAX_CHUNK_SIZE
Definition: tableam.c:45
#define Min(x, y)
Definition: c.h:986
uint32 BlockNumber
Definition: block.h:31
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:918
#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:980
#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 665 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().

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

◆ 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, RelationGetSmgr(), and smgrnblocks().

Referenced by SampleHeapTupleVisible(), and table_scan_sample_next_tuple().

629 {
630  uint64 nblocks = 0;
631 
632  /* InvalidForkNumber indicates returning the size for all forks */
633  if (forkNumber == InvalidForkNumber)
634  {
635  for (int i = 0; i < MAX_FORKNUM; i++)
636  nblocks += smgrnblocks(RelationGetSmgr(rel), i);
637  }
638  else
639  nblocks = smgrnblocks(RelationGetSmgr(rel), forkNumber);
640 
641  return nblocks * BLCKSZ;
642 }
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:548
static SMgrRelation RelationGetSmgr(Relation rel)
Definition: rel.h:544
#define MAX_FORKNUM
Definition: relpath.h:55
int i

◆ table_endscan()

static void table_endscan ( TableScanDesc  scan)
inlinestatic

Definition at line 991 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(), createdb(), currtid_internal(), DefineQueryRewrite(), do_autovacuum(), DoCopyTo(), DropSetting(), DropTableSpace(), ExecEndBitmapHeapScan(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndTidRangeScan(), 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_list(), ReindexMultipleTables(), RelationFindReplTupleSeq(), remove_dbtablespaces(), RemoveSubscriptionRel(), RenameTableSpace(), systable_endscan(), ThereIsAtLeastOneRole(), vac_truncate_clog(), validateDomainConstraint(), and validateForeignKeyConstraint().

992 {
993  scan->rs_rd->rd_tableam->scan_end(scan);
994 }
void(* scan_end)(TableScanDesc scan)
Definition: tableam.h:312
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
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 1564 of file tableam.h.

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

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

1565 {
1566  /* optional callback */
1567  if (rel->rd_tableam && rel->rd_tableam->finish_bulk_insert)
1569 }
void(* finish_bulk_insert)(Relation rel, int options)
Definition: tableam.h:552
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1778 of file tableam.h.

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

Referenced by summarize_range().

1789 {
1790  return table_rel->rd_tableam->index_build_range_scan(table_rel,
1791  index_rel,
1792  index_info,
1793  allow_sync,
1794  anyvisible,
1795  progress,
1796  start_blockno,
1797  numblocks,
1798  callback,
1799  callback_state,
1800  scan);
1801 }
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:668
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
int progress
Definition: pgbench.c:272
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1745 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().

1753 {
1754  return table_rel->rd_tableam->index_build_range_scan(table_rel,
1755  index_rel,
1756  index_info,
1757  allow_sync,
1758  false,
1759  progress,
1760  0,
1762  callback,
1763  callback_state,
1764  scan);
1765 }
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:668
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
int progress
Definition: pgbench.c:272
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define InvalidBlockNumber
Definition: block.h:33

◆ table_index_delete_tuples()

static TransactionId table_index_delete_tuples ( Relation  rel,
TM_IndexDeleteOp delstate 
)
inlinestatic

Definition at line 1325 of file tableam.h.

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

Referenced by _bt_delitems_delete_check(), and index_compute_xid_horizon_for_tuples().

1326 {
1327  return rel->rd_tableam->index_delete_tuples(rel, delstate);
1328 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
TransactionId(* index_delete_tuples)(Relation rel, TM_IndexDeleteOp *delstate)
Definition: tableam.h:475

◆ table_index_fetch_begin()

static IndexFetchTableData* table_index_fetch_begin ( Relation  rel)
inlinestatic

Definition at line 1161 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().

1162 {
1163  return rel->rd_tableam->index_fetch_begin(rel);
1164 }
struct IndexFetchTableData *(* index_fetch_begin)(Relation rel)
Definition: tableam.h:398
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_index_fetch_end()

static void table_index_fetch_end ( struct IndexFetchTableData scan)
inlinestatic

Definition at line 1180 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().

1181 {
1182  scan->rel->rd_tableam->index_fetch_end(scan);
1183 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
void(* index_fetch_end)(struct IndexFetchTableData *data)
Definition: tableam.h:409

◆ table_index_fetch_reset()

static void table_index_fetch_reset ( struct IndexFetchTableData scan)
inlinestatic

Definition at line 1171 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().

1172 {
1173  scan->rel->rd_tableam->index_fetch_reset(scan);
1174 }
void(* index_fetch_reset)(struct IndexFetchTableData *data)
Definition: tableam.h:404
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1210 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().

1215 {
1216  /*
1217  * We don't expect direct calls to table_index_fetch_tuple with valid
1218  * CheckXidAlive for catalog or regular tables. See detailed comments in
1219  * xact.c where these variables are declared.
1220  */
1222  elog(ERROR, "unexpected table_index_fetch_tuple call during logical decoding");
1223 
1224  return scan->rel->rd_tableam->index_fetch_tuple(scan, tid, snapshot,
1225  slot, call_again,
1226  all_dead);
1227 }
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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:431

◆ 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:1161
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1254
static bool table_index_fetch_tuple(struct IndexFetchTableData *scan, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, bool *call_again, bool *all_dead)
Definition: tableam.h:1210
static void table_index_fetch_end(struct IndexFetchTableData *scan)
Definition: tableam.h:1180

◆ 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 1809 of file tableam.h.

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

Referenced by validate_index().

1814 {
1815  table_rel->rd_tableam->index_validate_scan(table_rel,
1816  index_rel,
1817  index_info,
1818  snapshot,
1819  state);
1820 }
void(* index_validate_scan)(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
Definition: tableam.h:681
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1426 of file tableam.h.

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

Referenced by CopyMultiInsertBufferFlush().

1428 {
1429  rel->rd_tableam->multi_insert(rel, slots, nslots,
1430  cid, options, bistate);
1431 }
void(* multi_insert)(Relation rel, TupleTableSlot **slots, int nslots, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:504
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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_tidrange().

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:367
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2093
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:96
#define Assert(condition)
Definition: c.h:804
size_t Size
Definition: c.h:540
#define SnapshotAny
Definition: snapmgr.h:67

◆ 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_tidrange().

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:374
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2117
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:96
#define Assert(condition)
Definition: c.h:804
size_t Size
Definition: c.h:540
#define SnapshotAny
Definition: snapmgr.h:67

◆ table_parallelscan_reinitialize()

static void table_parallelscan_reinitialize ( Relation  rel,
ParallelTableScanDesc  pscan 
)
inlinestatic

Definition at line 1143 of file tableam.h.

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

Referenced by ExecSeqScanReInitializeDSM().

1144 {
1145  rel->rd_tableam->parallelscan_reinitialize(rel, pscan);
1146 }
void(* parallelscan_reinitialize)(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:381
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_relation_copy_data()

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

Definition at line 1619 of file tableam.h.

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

Referenced by ATExecSetTableSpace().

1620 {
1621  rel->rd_tableam->relation_copy_data(rel, newrnode);
1622 }
void(* relation_copy_data)(Relation rel, const RelFileNode *newrnode)
Definition: tableam.h:598
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1646 of file tableam.h.

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

Referenced by copy_table_data().

1655 {
1656  OldTable->rd_tableam->relation_copy_for_cluster(OldTable, NewTable, OldIndex,
1657  use_sort, OldestXmin,
1658  xid_cutoff, multi_cutoff,
1659  num_tuples, tups_vacuumed,
1660  tups_recently_dead);
1661 }
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:602
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1907 of file tableam.h.

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

Referenced by estimate_rel_size().

1910 {
1911  rel->rd_tableam->relation_estimate_size(rel, attr_widths, pages, tuples,
1912  allvisfrac);
1913 }
void(* relation_estimate_size)(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:747
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1886 of file tableam.h.

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

Referenced by toast_fetch_datum(), and toast_fetch_datum_slice().

1889 {
1890  toastrel->rd_tableam->relation_fetch_toast_slice(toastrel, valueid,
1891  attrsize,
1892  sliceoffset, slicelength,
1893  result);
1894 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
void(* relation_fetch_toast_slice)(Relation toastrel, Oid valueid, int32 attrsize, int32 sliceoffset, int32 slicelength, struct varlena *result)
Definition: tableam.h:725

◆ table_relation_needs_toast_table()

static bool table_relation_needs_toast_table ( Relation  rel)
inlinestatic

Definition at line 1847 of file tableam.h.

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

Referenced by needs_toast_table().

1848 {
1849  return rel->rd_tableam->relation_needs_toast_table(rel);
1850 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
bool(* relation_needs_toast_table)(Relation rel)
Definition: tableam.h:711

◆ table_relation_nontransactional_truncate()

static void table_relation_nontransactional_truncate ( Relation  rel)
inlinestatic

Definition at line 1607 of file tableam.h.

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

Referenced by heap_truncate_one_rel().

1608 {
1610 }
void(* relation_nontransactional_truncate)(Relation rel)
Definition: tableam.h:590
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1590 of file tableam.h.

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

Referenced by heap_create(), and RelationSetNewRelfilenode().

1595 {
1596  rel->rd_tableam->relation_set_new_filenode(rel, newrnode, persistence,
1597  freezeXid, minmulti);
1598 }
void(* relation_set_new_filenode)(Relation rel, const RelFileNode *newrnode, char persistence, TransactionId *freezeXid, MultiXactId *minmulti)
Definition: tableam.h:576
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_relation_size()

static uint64 table_relation_size ( Relation  rel,
ForkNumber  forkNumber 
)
inlinestatic

Definition at line 1838 of file tableam.h.

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

Referenced by RelationGetNumberOfBlocksInFork().

1839 {
1840  return rel->rd_tableam->relation_size(rel, forkNumber);
1841 }
uint64(* relation_size)(Relation rel, ForkNumber forkNumber)
Definition: tableam.h:701
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_relation_toast_am()

static Oid table_relation_toast_am ( Relation  rel)
inlinestatic

Definition at line 1857 of file tableam.h.

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

Referenced by create_toast_table().

1858 {
1859  return rel->rd_tableam->relation_toast_am(rel);
1860 }
Oid(* relation_toast_am)(Relation rel)
Definition: tableam.h:718
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_relation_vacuum()

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

Definition at line 1675 of file tableam.h.

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

Referenced by vacuum_rel().

1677 {
1678  rel->rd_tableam->relation_vacuum(rel, params, bstrategy);
1679 }
void(* relation_vacuum)(Relation rel, struct VacuumParams *params, BufferAccessStrategy bstrategy)
Definition: tableam.h:628
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ table_rescan()

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

Definition at line 1000 of file tableam.h.

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

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

1002 {
1003  scan->rs_rd->rd_tableam->scan_rescan(scan, key, false, false, false, false);
1004 }
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:318
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
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 1015 of file tableam.h.

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

Referenced by tablesample_init().

1017 {
1018  scan->rs_rd->rd_tableam->scan_rescan(scan, key, true,
1019  allow_strat, allow_sync,
1020  allow_pagemode);
1021 }
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:318
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
Relation rs_rd
Definition: relscan.h:34

◆ table_rescan_tidrange()

static void table_rescan_tidrange ( TableScanDesc  sscan,
ItemPointer  mintid,
ItemPointer  maxtid 
)
inlinestatic

Definition at line 1078 of file tableam.h.

References Assert, RelationData::rd_tableam, TableScanDescData::rs_flags, TableScanDescData::rs_rd, TableAmRoutine::scan_rescan, TableAmRoutine::scan_set_tidrange, and SO_TYPE_TIDRANGESCAN.

Referenced by TidRangeNext().

1080 {
1081  /* Ensure table_beginscan_tidrange() was used. */
1082  Assert((sscan->rs_flags & SO_TYPE_TIDRANGESCAN) != 0);
1083 
1084  sscan->rs_rd->rd_tableam->scan_rescan(sscan, NULL, false, false, false, false);
1085  sscan->rs_rd->rd_tableam->scan_set_tidrange(sscan, mintid, maxtid);
1086 }
uint32 rs_flags
Definition: relscan.h:47
void(* scan_rescan)(TableScanDesc scan, struct ScanKeyData *key, bool set_params, bool allow_strat, bool allow_sync, bool allow_pagemode)
Definition: tableam.h:318
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
void(* scan_set_tidrange)(TableScanDesc scan, ItemPointer mintid, ItemPointer maxtid)
Definition: tableam.h:346
#define Assert(condition)
Definition: c.h:804
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 1690 of file tableam.h.

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

Referenced by acquire_sample_rows().

1692 {
1693  return scan->rs_rd->rd_tableam->scan_analyze_next_block(scan, blockno,
1694  bstrategy);
1695 }
bool(* scan_analyze_next_block)(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy)
Definition: tableam.h:649
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
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 1708 of file tableam.h.

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

Referenced by acquire_sample_rows().

1711 {
1712  return scan->rs_rd->rd_tableam->scan_analyze_next_tuple(scan, OldestXmin,
1713  liverows, deadrows,
1714  slot);
1715 }
bool(* scan_analyze_next_tuple)(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot)
Definition: tableam.h:661
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
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 1931 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().

1933 {
1934  /*
1935  * We don't expect direct calls to table_scan_bitmap_next_block with valid
1936  * CheckXidAlive for catalog or regular tables. See detailed comments in
1937  * xact.c where these variables are declared.
1938  */
1940  elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
1941 
1942  return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan,
1943  tbmres);
1944 }
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:788
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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 1955 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().

1958 {
1959  /*
1960  * We don't expect direct calls to table_scan_bitmap_next_tuple with valid
1961  * CheckXidAlive for catalog or regular tables. See detailed comments in
1962  * xact.c where these variables are declared.
1963  */
1965  elog(ERROR, "unexpected table_scan_bitmap_next_tuple call during logical decoding");
1966 
1967  return scan->rs_rd->rd_tableam->scan_bitmap_next_tuple(scan,
1968  tbmres,
1969  slot);
1970 }
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
bool(* scan_bitmap_next_tuple)(TableScanDesc scan, struct TBMIterateResult *tbmres, TupleTableSlot *slot)
Definition: tableam.h:802
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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 1032 of file tableam.h.

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

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

1033 {
1034  slot->tts_tableOid = RelationGetRelid(sscan->rs_rd);
1035 
1036  /*
1037  * We don't expect direct calls to table_scan_getnextslot with valid
1038  * CheckXidAlive for catalog or regular tables. See detailed comments in
1039  * xact.c where these variables are declared.
1040  */
1042  elog(ERROR, "unexpected table_scan_getnextslot call during logical decoding");
1043 
1044  return sscan->rs_rd->rd_tableam->scan_getnextslot(sscan, direction, slot);
1045 }
bool(* scan_getnextslot)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:325
Oid tts_tableOid
Definition: tuptable.h:131
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define RelationGetRelid(relation)
Definition: rel.h:477

◆ table_scan_getnextslot_tidrange()

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

Definition at line 1094 of file tableam.h.

References Assert, RelationData::rd_tableam, TableScanDescData::rs_flags, TableScanDescData::rs_rd, TableAmRoutine::scan_getnextslot_tidrange, SO_TYPE_TIDRANGESCAN, table_beginscan_parallel(), table_parallelscan_estimate(), and table_parallelscan_initialize().

Referenced by TidRangeNext().

1096 {
1097  /* Ensure table_beginscan_tidrange() was used. */
1098  Assert((sscan->rs_flags & SO_TYPE_TIDRANGESCAN) != 0);
1099 
1100  return sscan->rs_rd->rd_tableam->scan_getnextslot_tidrange(sscan,
1101  direction,
1102  slot);
1103 }
uint32 rs_flags
Definition: relscan.h:47
bool(* scan_getnextslot_tidrange)(TableScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:354
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define Assert(condition)
Definition: c.h:804
Relation rs_rd
Definition: relscan.h:34

◆ table_scan_sample_next_block()

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

Definition at line 1982 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().

1984 {
1985  /*
1986  * We don't expect direct calls to table_scan_sample_next_block with valid
1987  * CheckXidAlive for catalog or regular tables. See detailed comments in
1988  * xact.c where these variables are declared.
1989  */
1991  elog(ERROR, "unexpected table_scan_sample_next_block call during logical decoding");
1992  return scan->rs_rd->rd_tableam->scan_sample_next_block(scan, scanstate);
1993 }
bool(* scan_sample_next_block)(TableScanDesc scan, struct SampleScanState *scanstate)
Definition: tableam.h:831
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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 2004 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(), source, 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().

2007 {
2008  /*
2009  * We don't expect direct calls to table_scan_sample_next_tuple with valid
2010  * CheckXidAlive for catalog or regular tables. See detailed comments in
2011  * xact.c where these variables are declared.
2012  */
2014  elog(ERROR, "unexpected table_scan_sample_next_tuple call during logical decoding");
2015  return scan->rs_rd->rd_tableam->scan_sample_next_tuple(scan, scanstate,
2016  slot);
2017 }
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
bool(* scan_sample_next_tuple)(TableScanDesc scan, struct SampleScanState *scanstate, TupleTableSlot *slot)
Definition: tableam.h:847
Relation rs_rd
Definition: relscan.h:34
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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:825
uint32 rs_flags
Definition: relscan.h:47
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:96
#define Assert(condition)
Definition: c.h:804
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(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitTidRangeScan(), 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:804
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(), DefineQueryRewrite(), DoCopyTo(), EvalPlanQualSlot(), ExecCrossPartitionUpdate(), ExecInitInsertProjection(), ExecInitModifyTable(), ExecInitPartitionInfo(), ExecInitRoutingInfo(), ExecInitUpdateProjection(), 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:503
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1238
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
List * lappend(List *list, void *datum)
Definition: list.c:336

◆ table_tuple_complete_speculative()

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

Definition at line 1404 of file tableam.h.

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

Referenced by ExecInsert().

1406 {
1407  rel->rd_tableam->tuple_complete_speculative(rel, slot, specToken,
1408  succeeded);
1409 }
void(* tuple_complete_speculative)(Relation rel, TupleTableSlot *slot, uint32 specToken, bool succeeded)
Definition: tableam.h:498
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1460 of file tableam.h.

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

Referenced by ExecDelete(), and simple_table_tuple_delete().

1463 {
1464  return rel->rd_tableam->tuple_delete(rel, tid, cid,
1465  snapshot, crosscheck,
1466  wait, tmfd, changingPart);
1467 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
TM_Result(* tuple_delete)(Relation rel, ItemPointer tid, CommandId cid, Snapshot snapshot, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool changingPart)
Definition: tableam.h:508

◆ table_tuple_fetch_row_version()

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

Definition at line 1257 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(), ExecCrossPartitionUpdate(), ExecDelete(), ExecModifyTable(), ExecUpdate(), GetTupleForTrigger(), and TidNext().

1261 {
1262  /*
1263  * We don't expect direct calls to table_tuple_fetch_row_version with
1264  * valid CheckXidAlive for catalog or regular tables. See detailed
1265  * comments in xact.c where these variables are declared.
1266  */
1268  elog(ERROR, "unexpected table_tuple_fetch_row_version call during logical decoding");
1269 
1270  return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot);
1271 }
bool(* tuple_fetch_row_version)(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot)
Definition: tableam.h:448
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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_internal(), 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:698
#define ERROR
Definition: elog.h:46
bool bsysscan
Definition: xact.c:97
#define RelationGetRelationName(relation)
Definition: rel.h:511
TransactionId CheckXidAlive
Definition: xact.c:96
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
#define ereport(elevel,...)
Definition: elog.h:157
void(* tuple_get_latest_tid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:463
Relation rs_rd
Definition: relscan.h:34
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:456
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89
#define elog(elevel,...)
Definition: elog.h:232
#define unlikely(x)
Definition: c.h:273
#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 1371 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().

1373 {
1374  rel->rd_tableam->tuple_insert(rel, slot, cid, options,
1375  bistate);
1376 }
void(* tuple_insert)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
Definition: tableam.h:485
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1390 of file tableam.h.

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

Referenced by ExecInsert().

1394 {
1395  rel->rd_tableam->tuple_insert_speculative(rel, slot, cid, options,
1396  bistate, specToken);
1397 }
void(* tuple_insert_speculative)(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate, uint32 specToken)
Definition: tableam.h:490
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

◆ 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 1549 of file tableam.h.

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

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

1553 {
1554  return rel->rd_tableam->tuple_lock(rel, tid, snapshot, slot,
1555  cid, mode, wait_policy,
1556  flags, tmfd);
1557 }
static PgChecksumMode mode
Definition: pg_checksums.c:65
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
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:530

◆ table_tuple_satisfies_snapshot()

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

Definition at line 1304 of file tableam.h.

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

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

1306 {
1307  return rel->rd_tableam->tuple_satisfies_snapshot(rel, slot, snapshot);
1308 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
bool(* tuple_satisfies_snapshot)(Relation rel, TupleTableSlot *slot, Snapshot snapshot)
Definition: tableam.h:470

◆ table_tuple_tid_valid()

static bool table_tuple_tid_valid ( TableScanDesc  scan,
ItemPointer  tid 
)
inlinestatic

Definition at line 1283 of file tableam.h.

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

Referenced by TidListEval().

1284 {
1285  return scan->rs_rd->rd_tableam->tuple_tid_valid(scan, tid);
1286 }
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184
Relation rs_rd
Definition: relscan.h:34
bool(* tuple_tid_valid)(TableScanDesc scan, ItemPointer tid)
Definition: tableam.h:456

◆ 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 1504 of file tableam.h.

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

Referenced by ExecUpdate(), and simple_table_tuple_update().

1508 {
1509  return rel->rd_tableam->tuple_update(rel, otid, slot,
1510  cid, snapshot, crosscheck,
1511  wait, tmfd,
1512  lockmode, update_indexes);
1513 }
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:518
const struct TableAmRoutine * rd_tableam
Definition: rel.h:184

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().